fw4spl
ObjectReadLock.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2016.
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/ObjectReadLock.hpp"
8 
9 #include <boost/thread/locks.hpp>
10 
11 namespace fwData
12 {
13 namespace mt
14 {
15 
16 //-----------------------------------------------------------------------------
17 
18 ObjectReadLock::ObjectReadLock(::fwData::Object::csptr obj, bool lock)
19 {
20  if (lock)
21  {
22  m_lock = ::fwCore::mt::ReadLock(obj->getMutex());
23  }
24  else
25  {
26  m_lock = ::fwCore::mt::ReadLock(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 void lock()
Adds read lock on object mutex.
FWDATA_API ObjectReadLock(::fwData::Object::csptr obj, bool lock=true)
Constructor : owns an read lock on object mutex. If adopt_lock==false : the mutex is not locked (call...
::boost::shared_lock< ReadWriteMutex > ReadLock
Defines a lock of read type for read/write mutex.
FWDATA_API ~ObjectReadLock()
Destructor. Does nothing.
FWDATA_API void unlock()
Releases lock on object mutex.
Contains the representation of the data objects used in the framework.