Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET Apache Qpid Documentation
qpid/management/Mutex.h
Go to the documentation of this file.
00001 #ifndef _management_Mutex_h
00002 #define _management_Mutex_h
00003 
00004 /*
00005  *
00006  * Copyright (c) 2008 The Apache Software Foundation
00007  *
00008  * Licensed under the Apache License, Version 2.0 (the "License");
00009  * you may not use this file except in compliance with the License.
00010  * You may obtain a copy of the License at
00011  *
00012  *    http://www.apache.org/licenses/LICENSE-2.0
00013  *
00014  * Unless required by applicable law or agreed to in writing, software
00015  * distributed under the License is distributed on an "AS IS" BASIS,
00016  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00017  * See the License for the specific language governing permissions and
00018  * limitations under the License.
00019  *
00020  */
00021 
00022 #include "qpid/CommonImportExport.h"
00023 
00024 namespace qpid {
00025     namespace sys {
00026         class Mutex;
00027     }
00028 
00029     namespace management {
00030 
00035         template <class L> class ScopedLockTemplate {
00036         public:
00037             ScopedLockTemplate(L& l) : mutex(l) { mutex.lock(); }
00038             ~ScopedLockTemplate() { mutex.unlock(); }
00039         private:
00040             L& mutex;
00041         };
00042 
00043         template <class L> class ScopedUnlockTemplate {
00044         public:
00045             ScopedUnlockTemplate(L& l) : mutex(l) { mutex.unlock(); }
00046             ~ScopedUnlockTemplate() { mutex.lock(); }
00047         private:
00048             L& mutex;
00049         };
00050 
00051         class Mutex {
00052         public:
00053             typedef ScopedLockTemplate<Mutex> ScopedLock;
00054             typedef ScopedUnlockTemplate<Mutex> ScopedUnlock;
00055 
00056             QPID_COMMON_EXTERN Mutex();
00057             QPID_COMMON_EXTERN ~Mutex();
00058             QPID_COMMON_EXTERN void lock();
00059             QPID_COMMON_EXTERN void unlock();
00060         private:
00061             sys::Mutex* impl;
00062         };
00063     }
00064 }
00065 
00066 #endif
00067 

Qpid C++ API Reference
Generated on Mon Aug 22 2011 for Qpid C++ Client API by doxygen 1.7.4