Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

ScopedMonitor.hpp

Go to the documentation of this file.
00001 /*==========================================================================
00002  * Copyright (c) 2004 University of Massachusetts.  All Rights Reserved.
00003  *
00004  * Use of the Lemur Toolkit for Language Modeling and Information Retrieval
00005  * is subject to the terms of the software license set forth in the LICENSE
00006  * file included with this software, and also available at
00007  * http://www.lemurproject.org/license.html
00008  *
00009  *==========================================================================
00010  */
00011 
00012 //
00013 // ScopedMonitor
00014 //
00015 // 15 November 2004 -- tds
00016 //
00017 
00018 #ifndef INDRI_SCOPEDMONITOR_HPP
00019 #define INDRI_SCOPEDMONITOR_HPP
00020 
00021 #include "indri/Mutex.hpp"
00022 #include "indri/ConditionVariable.hpp"
00023 namespace indri
00024 {
00025   namespace thread
00026   {
00027     
00028     class ScopedMonitor {
00029     private:
00030       Mutex& _mutex;
00031       ConditionVariable& _condition;
00032 
00033     public:
00034       ScopedMonitor( Mutex& mutex, ConditionVariable& condition ) :
00035         _mutex(mutex),
00036         _condition(condition)
00037       {
00038         _mutex.lock();
00039       }
00040 
00041       ~ScopedMonitor() {
00042         _mutex.unlock();
00043       }
00044 
00045       void wait() {
00046         _condition.wait( _mutex );
00047       }
00048 
00049       void notifyOne() {
00050         _condition.notifyOne();
00051       }
00052 
00053       void notifyAll() {
00054         _condition.notifyAll();
00055       }
00056     };
00057   }
00058 }
00059 
00060 #endif // INDRI_SCOPEDMONITOR_HPP
00061 

Generated on Tue Jun 15 11:02:55 2010 for Lemur by doxygen 1.3.4