1/* -*-c++-*- OpenThreads library, Copyright (C) 2002 - 2007 The Open Thread Group
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
16// ScopedLock and ReverseScopedLock templates
24template <class M> class ScopedLock
28 ScopedLock(const ScopedLock&); // prevent copy
29 ScopedLock& operator=(const ScopedLock&); // prevent assign
31 explicit ScopedLock(M& m):m_lock(m) {m_lock.lock();}
32 ~ScopedLock(){m_lock.unlock();}
35template <class M> class ReverseScopedLock
39 ReverseScopedLock(const ReverseScopedLock&); // prevent copy
40 ReverseScopedLock& operator=(const ReverseScopedLock&); // prevent assign
42 explicit ReverseScopedLock(M& m):m_lock(m) {m_lock.unlock();}
43 ~ReverseScopedLock(){m_lock.lock();}
47template <class M> class ScopedPointerLock
51 ScopedPointerLock(const ScopedPointerLock&); // prevent copy
52 ScopedPointerLock& operator=(const ScopedPointerLock&); // prevent assign
54 explicit ScopedPointerLock(M* m):m_lock(m) { if (m_lock) m_lock->lock();}
55 ~ScopedPointerLock(){ if (m_lock) m_lock->unlock();}
58template <class M> class ReverseScopedPointerLock
62 ReverseScopedPointerLock(const ReverseScopedPointerLock&); // prevent copy
63 ReverseScopedPointerLock& operator=(const ReverseScopedPointerLock&); // prevent assign
65 explicit ReverseScopedPointerLock(M* m):m_lock(m) { if (m_lock) m_lock->unlock();}
66 ~ReverseScopedPointerLock(){ if (m_lock) m_lock->lock();}