CARMA C++
IoLock.h
1 #ifndef CARMA_UTIL_IOLOCK_H
2 #define CARMA_UTIL_IOLOCK_H
3 
11 #include "carma/util/PthreadMutex.h"
12 
13 namespace carma {
14 namespace util {
15 
16 
17 class IoLock {
18  public:
19  class ScopedCerrLock;
20 
21  private:
22  static carma::util::PthreadMutex cerrMutex_;
23 
24  IoLock( );
25 
26  /* virtual */ ~IoLock( );
27 }; // End class IoLock
28 
29 
30 } // End namespace util
31 } // End namespace carma
32 
33 
34 class carma::util::IoLock::ScopedCerrLock {
35  public:
36  ScopedCerrLock( );
37 
38  /* virtual */ ~ScopedCerrLock( );
39 };
40 
41 
42 inline
43 carma::util::IoLock::ScopedCerrLock::ScopedCerrLock( )
44 {
45  cerrMutex_.Lock();
46 }
47 
48 
49 inline
50 carma::util::IoLock::ScopedCerrLock::~ScopedCerrLock( )
51 try {
52  cerrMutex_.Unlock();
53 } catch ( ... ) {
54  // Just stifle any exception
55 }
56 
57 
58 #endif
A simple wrapper class that makes use of ::pthread_mutex_t easier in a C++ world. ...
Definition: PthreadMutex.h:41