CARMA C++
ScopedSharedLock.h
1 #ifndef CARMA_UTIL_SCOPED_SHARED_LOCK_H
2 #define CARMA_UTIL_SCOPED_SHARED_LOCK_H
3 
4 
5 namespace carma {
6 namespace util {
7 
8 
48 
49 template< typename L >
51  public:
52 
58 
59  explicit ScopedSharedLock( L & l );
60 
61 
64 
65  /* virtual */ ~ScopedSharedLock( );
66 
67  private:
68  // no copying
70  ScopedSharedLock & operator=( const ScopedSharedLock & );
71 
72  L & l_;
73 };
74 
75 
76 } // namespace carma::util
77 } // namespace carma
78 
79 
80 // ******* Below here is simply implementation *******
81 
82 template< typename L >
83 inline
85 l_( l )
86 {
87  sharedLock( l );
88 }
89 
90 
91 template< typename L >
92 inline
94 try {
95  sharedUnlock( l_ );
96 } catch ( ... ) {
97  // just stifle any exceptions
98 
99  return;
100 }
101 
102 
103 #endif
A templated scope class (i.e.
~ScopedSharedLock()
Releases the shared lock on the lock (that was given to the constructor) held by the caller&#39;s thread...
ScopedSharedLock(L &l)
Obtains an shared lock on the given lock for the caller&#39;s thread (possibly waiting an indeterminate a...