fw4spl
ObjectWriteLock.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "fwData/mt/ObjectWriteLock.hpp"
8 
9 #include <boost/thread/locks.hpp>
10 
11 namespace fwData
12 {
13 namespace mt
14 {
15 
16 //-----------------------------------------------------------------------------
17 
18 ObjectWriteLock::ObjectWriteLock(::fwData::Object::sptr obj, bool adopt_lock)
19 {
20  if (adopt_lock)
21  {
22  m_lock = ::fwCore::mt::WriteLock(obj->getMutex());
23  }
24  else
25  {
26  m_lock = ::fwCore::mt::WriteLock(obj->getMutex(), ::boost::defer_lock_t());
27  }
28 }
29 
30 //-----------------------------------------------------------------------------
31 
33 {
34 }
35 
36 //-----------------------------------------------------------------------------
37 
39 {
40  m_lock.lock();
41 }
42 
43 //-----------------------------------------------------------------------------
44 
46 {
47  m_lock.unlock();
48 }
49 
50 //-----------------------------------------------------------------------------
51 
52 } // mt
53 } // fwData
FWDATA_API ~ObjectWriteLock()
Destructor. Does nothing.
FWDATA_API ObjectWriteLock(::fwData::Object::sptr obj, bool adopt_lock=true)
Constructor : owns an exclusive lock on object mutex. If adopt_lock==false : the mutex is not locked ...
::boost::unique_lock< ReadWriteMutex > WriteLock
Defines a lock of write type for read/write mutex.
FWDATA_API void lock()
Adds exclusive lock on object mutex.
Contains the representation of the data objects used in the framework.
FWDATA_API void unlock()
Releases lock on object mutex.