]> git.mxchange.org Git - simgear.git/blob - simgear/threads/SGGuard.hxx
Lots of (mostly) doxygen fixes/cleanup.
[simgear.git] / simgear / threads / SGGuard.hxx
1 #ifndef SGGUARD_HXX_INCLUDED
2 #define SGGUARD_HXX_INCLUDED 1
3
4 /**
5  * A scoped locking utility.
6  * An SGGuard object locks its synchronization object during creation and
7  * automatically unlocks it when it goes out of scope.
8  */
9 template<class SGLOCK>
10 class SGGuard
11 {
12 public:
13
14     /**
15      * Create an SGGuard object and lock the passed lockable object.
16      * @param l A lockable object.
17      */
18     inline SGGuard( SGLOCK& l ) : lock(l) { lock.lock(); }
19
20     /**
21      * Destroy this object and unlock the lockable object.
22      */
23     inline ~SGGuard() { lock.unlock(); }
24
25 private:
26
27     SGLOCK& lock; //!< A lockable object
28
29 private:
30     // Disable copying.
31     SGGuard(const SGLOCK&);
32     SGLOCK& operator= (const SGLOCK&);
33 };
34
35 #endif // SGGUARD_HXX_INCLUDED