RWLock.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 //----------------------------------------------------------------------
23 //----------------------------------------------------------------------
24 #include "icl_core_thread/RWLock.h"
25 
26 #include <icl_core/os_lxrt.h>
28 
29 #if defined _SYSTEM_LXRT_
31 #endif
32 
33 #if defined _SYSTEM_POSIX_
35 #elif defined _SYSTEM_WIN32_
37 #else
38 # error "No rwlock implementation defined for this platform."
39 #endif
40 
42 
43 namespace icl_core {
44 namespace thread {
45 
47  : m_impl(NULL)
48 {
49 #if defined _SYSTEM_LXRT_
50  // Only create an LXRT implementation if the LXRT runtime system is
51  // really available. Otherwise create an ACE or POSIX
52  // implementation, depending on the system configuration.
53  // Remark: This allows us to compile programs with LXRT support but
54  // run them on systems on which no LXRT is installed and to disable
55  // LXRT support at program startup on systems with installed LXRT!
57  {
58  LOGGING_TRACE_C(IclCoreThread, RWLock, "Initializing LXRT rwlock." << endl);
59  m_impl = new RWLockImplLxrt;
60  }
61  else
62  {
63  LOGGING_TRACE_C(IclCoreThread, RWLock, "Initializing POSIX rwlock." << endl);
64  m_impl = new RWLockImplPosix;
65  }
66 
67 #elif defined _SYSTEM_POSIX_
68  LOGGING_TRACE_C(IclCoreThread, RWLock, "Initializing POSIX rwlock." << endl);
69  m_impl = new RWLockImplPosix;
70 
71 #elif defined _SYSTEM_WIN32_
72  LOGGING_TRACE_C(IclCoreThread, RWLock, "Initializing WIN32 rwlock." << endl);
73  m_impl = new RWLockImplWin32;
74 
75 #endif
76 }
77 
79 {
80  LOGGING_TRACE_C(IclCoreThread, RWLock, "Destroying rwlock." << endl);
81  delete m_impl;
82  m_impl = NULL;
83 }
84 
86 {
87  LOGGING_TRACE_C(IclCoreThread, RWLock, "Read locking rwlock ..." << endl);
88  bool result = m_impl->readLock();
89  LOGGING_TRACE_C(IclCoreThread, RWLock, "RWLock read lock "
90  << (result ? "successful" : "failed") << "." << endl);
91  return result;
92 }
93 
94 bool RWLock::readLock(const ::icl_core::TimeStamp& timeout)
95 {
96  LOGGING_TRACE_C(IclCoreThread, RWLock, "Read locking rwlock with absolute timeout "
97  << timeout << " ..." << endl);
98  bool result = m_impl->readLock(timeout);
99  LOGGING_TRACE_C(IclCoreThread, RWLock, "RWLock read lock "
100  << (result ? "successful" : "failed") << "." << endl);
101  return result;
102 }
103 
104 bool RWLock::readLock(const ::icl_core::TimeSpan& timeout)
105 {
106  LOGGING_TRACE_C(IclCoreThread, RWLock, "Read locking rwlock with relative timeout "
107  << timeout << " ..." << endl);
108  bool result = m_impl->readLock(timeout);
109  LOGGING_TRACE_C(IclCoreThread, RWLock, "RWLock read lock "
110  << (result ? "successful" : "failed") << "." << endl);
111  return result;
112 }
113 
115 {
116  LOGGING_TRACE_C(IclCoreThread, RWLock, "Trying to read lock rwlock ..." << endl);
117  bool result = m_impl->tryReadLock();
118  LOGGING_TRACE_C(IclCoreThread, RWLock, "RWLock try read lock "
119  << (result ? "successful" : "failed") << "." << endl);
120  return result;
121 }
122 
124 {
125  LOGGING_TRACE_C(IclCoreThread, RWLock, "Write locking rwlock ..." << endl);
126  bool result = m_impl->writeLock();
127  LOGGING_TRACE_C(IclCoreThread, RWLock, "RWLock write lock "
128  << (result ? "successful" : "failed") << "." << endl);
129  return result;
130 }
131 
132 bool RWLock::writeLock(const ::icl_core::TimeStamp& timeout)
133 {
134  LOGGING_TRACE_C(IclCoreThread, RWLock, "Write locking rwlock with absolute timeout "
135  << timeout << " ..." << endl);
136  bool result = m_impl->writeLock(timeout);
137  LOGGING_TRACE_C(IclCoreThread, RWLock, "RWLock write lock "
138  << (result ? "successful" : "failed") << "." << endl);
139  return result;
140 }
141 
142 bool RWLock::writeLock(const ::icl_core::TimeSpan& timeout)
143 {
144  LOGGING_TRACE_C(IclCoreThread, RWLock, "Write locking rwlock with relative timeout "
145  << timeout << " ..." << endl);
146  bool result = m_impl->writeLock(timeout);
147  LOGGING_TRACE_C(IclCoreThread, RWLock, "RWLock write lock "
148  << (result ? "successful" : "failed") << "." << endl);
149  return result;
150 }
151 
153 {
154  LOGGING_TRACE_C(IclCoreThread, RWLock, "Trying to write lock rwlock ..." << endl);
155  bool result = m_impl->tryWriteLock();
156  LOGGING_TRACE_C(IclCoreThread, RWLock, "RWLock try write lock "
157  << (result ? "successful" : "failed") << "." << endl);
158  return result;
159 }
160 
162 {
163  LOGGING_TRACE_C(IclCoreThread, RWLock, "Unlocking rwlock." << endl);
164  m_impl->unlock();
165 }
166 
168 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
169 
173  bool RWLock::ReadLock()
174  {
175  return readLock();
176  }
177 
182  bool RWLock::ReadLock(const icl_core::TimeStamp& timeout)
183  {
184  return readLock(timeout);
185  }
186 
191  bool RWLock::ReadLock(const icl_core::TimeSpan& timeout)
192  {
193  return readLock(timeout);
194  }
195 
199  bool RWLock::TryReadLock()
200  {
201  return tryReadLock();
202  }
203 
207  bool RWLock::WriteLock()
208  {
209  return writeLock();
210  }
211 
216  bool RWLock::WriteLock(const icl_core::TimeStamp& timeout)
217  {
218  return writeLock(timeout);
219  }
220 
225  bool RWLock::WriteLock(const icl_core::TimeSpan& timeout)
226  {
227  return writeLock(timeout);
228  }
229 
233  bool RWLock::TryWriteLock()
234  {
235  return tryWriteLock();
236  }
237 
241  void RWLock::Unlock()
242  {
243  unlock();
244  }
245 
246 #endif
247 
249 }
250 }
Defines icl_core::thread::RWLockImplLxrt.
Represents absolute times.
Definition: TimeStamp.h:61
RWLockImpl * m_impl
Definition: RWLock.h:174
virtual bool tryReadLock()=0
Contains icl_core::thread::RWLock.
virtual bool tryWriteLock()=0
bool isLxrtAvailable()
Definition: os_lxrt.cpp:141
Contains logging definitions for the icl_core_thread library.
Contains icl_core::thread::RWLockImplPosix.
ThreadStream & endl(ThreadStream &stream)
Definition: ThreadStream.h:249
const TimeSpan timeout(1, 0)
Contains global LXRT functions.
Repesents absolute times.
Definition: TimeSpan.h:46
virtual bool writeLock()=0
Contains icl_core::thread::RWLockImplWin32.
#define LOGGING_TRACE_C(streamname, classname, arg)


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