CARMA C++
ScopedExclusiveLock.h
1 #ifndef CARMA_UTIL_SCOPED_EXCLUSIVE_LOCK_H
2 #define CARMA_UTIL_SCOPED_EXCLUSIVE_LOCK_H
3 
4 
5 namespace carma {
6 namespace util {
7 
8 
43 
44 template< typename L >
46  public:
47 
53 
54  explicit ScopedExclusiveLock( L & l );
55 
56 
59 
60  /* virtual */ ~ScopedExclusiveLock( );
61 
62  private:
63  // no copying
65  ScopedExclusiveLock & operator=( const ScopedExclusiveLock & rhs );
66 
67  L & l_;
68 };
69 
70 
71 } // namespace carma::util
72 } // namespace carma
73 
74 
75 // ******* Below here is simply implementation *******
76 
77 template< typename L >
78 inline
80 l_( l ) {
81  exclusiveLock( l );
82 }
83 
84 
85 template< typename L >
86 inline
88 try {
89  exclusiveUnlock( l_ );
90 } catch ( ... ) {
91  // just stifle any exceptions
92 
93  return;
94 }
95 
96 
97 #endif
ScopedExclusiveLock(L &l)
Obtains an exclusive lock on the given lock for the caller&#39;s thread (possibly waiting an indeterminat...
A templated scope class (i.e.
~ScopedExclusiveLock()
Releases the exclusive lock on the lock (that was given to the constructor) held by the caller&#39;s thre...