]> git.mxchange.org Git - simgear.git/blob - simgear/threads/SGGuard.hxx
Add another subsystem group.
[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 SGLOCK A lockable object.
17      */
18     inline SGGuard( SGLOCK& l ) : lock(l) { lock.lock(); }
19
20     /**
21      * Destroy this object and unlock the locakable object.
22      */
23     inline ~SGGuard() { lock.unlock(); }
24
25 private:
26
27     /**
28      * A lockable object.
29      */
30     SGLOCK& lock;
31
32 private:
33     // Disable copying.
34     SGGuard(const SGLOCK&);
35     SGLOCK& operator= (const SGLOCK&);
36 };
37
38 #endif // SGGUARD_HXX_INCLUDED