ScopedRWLock.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
22 //----------------------------------------------------------------------
24 
25 #include "icl_core_thread/RWLock.h"
26 
27 namespace icl_core {
28 namespace thread {
29 
30 ScopedRWLock::ScopedRWLock(RWLock& lock, LockMode lock_mode, bool force)
31  : m_lock(lock), m_is_locked(false)
32 {
33  if (lock_mode == eLM_READ_LOCK)
34  {
35  do { m_is_locked = m_lock.readLock(); } while (force && !m_is_locked);
36  }
37  else
38  {
39  do { m_is_locked = m_lock.writeLock(); } while (force && !m_is_locked);
40  }
41 }
42 
44 {
45  if (isLocked())
46  {
47  m_lock.unlock();
48  }
49 }
50 
52 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
53 
57 bool ScopedRWLock::IsLocked() const
58 {
59  return isLocked();
60 }
61 
62 #endif
63 
65 }
66 }
Contains icl_core::thread::ScopedRWLock.
LockMode
The type of lock to obtain on the read-write lock.
Definition: ScopedRWLock.h:54
Contains icl_core::thread::RWLock.
ScopedRWLock(RWLock &lock, LockMode lock_mode, bool force=true)


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58