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

ScopedLock.hpp

Go to the documentation of this file.
00001 /*==========================================================================
00002  * Copyright (c) 2005 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 // ScopedLock
00014 //
00015 // 15 November 2004 -- tds
00016 //
00017 
00018 #ifndef INDRI_SCOPEDLOCK_HPP
00019 #define INDRI_SCOPEDLOCK_HPP
00020 namespace indri
00021 {
00022   namespace thread
00023   {
00024     class ScopedLock {
00025     private:
00026       Lockable* _lockable;
00027 
00028     public:
00029       ScopedLock( Lockable& lockable ) {
00030         _lockable = &lockable;
00031         _lockable->lock();
00032       }
00033 
00034       ScopedLock( Lockable* lockable ) {
00035         _lockable = lockable;
00036 
00037         if( _lockable )
00038           _lockable->lock();
00039       }
00040 
00041       ~ScopedLock() {
00042         if( _lockable )
00043           _lockable->unlock();
00044       }
00045 
00046       void unlock() {
00047         if( _lockable )
00048           _lockable->unlock();
00049         _lockable = 0;
00050       }
00051     };
00052   }
00053 }
00054 
00055 #endif // INDRI_SCOPEDLOCK_HPP
00056 

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