Mutex.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/Mutex.h"
25 
26 
27 #include <icl_core/os_lxrt.h>
28 
29 #undef ICL_CORE_LOCAL_LOGGING
30 //#define ICL_CORE_LOCAL_LOGGING
32 
33 #define LOCAL_PRINTF(args)
34 //#define LOCAL_PRINTF PRINTF
35 
36 #if defined _SYSTEM_LXRT_
38 #endif
39 
40 #if defined _SYSTEM_POSIX_
42 #elif defined _SYSTEM_WIN32_
44 #else
45 # error "No mutex implementation defined for this platform."
46 #endif
47 
49 
50 namespace icl_core {
51 namespace thread {
52 
54  : m_impl(NULL)
55 {
56 #if defined _SYSTEM_LXRT_
57  // Only create an LXRT implementation if the LXRT runtime system is
58  // really available. Otherwise create an ACE or POSIX
59  // implementation, depending on the system configuration.
60  // Remark: This allows us to compile programs with LXRT support but
61  // run them on systems on which no LXRT is installed and to disable
62  // LXRT support at program startup on systems with installed LXRT!
64  {
65  LOCAL_PRINTF("Initializing LXRT mutex.\n");
66  m_impl = new MutexImplLxrt;
67  }
68  else
69  {
70  LOCAL_PRINTF("Initializing POSIX mutex.\n");
71  m_impl = new MutexImplPosix;
72  }
73 
74 #elif defined _SYSTEM_POSIX_
75  LOCAL_PRINTF("Initializing POSIX mutex.\n");
76  m_impl = new MutexImplPosix;
77 
78 #elif defined _SYSTEM_WIN32_
79  LOCAL_PRINTF("Initializing WIN32 mutex.\n");
80  m_impl = new MutexImplWin32;
81 
82 #endif
83 }
84 
86 {
87  LOCAL_PRINTF("Destroying mutex.\n");
88  delete m_impl;
89  m_impl = NULL;
90 }
91 
93 {
94  LLOGGING_TRACE_C(Thread, Mutex, "Locking mutex ..." << endl);
95  bool result = m_impl->lock();
96  LLOGGING_TRACE_C(Thread, Mutex, "Mutex lock " << (result ? "successful" : "failed") << "." << endl);
97  return result;
98 }
99 
100 bool Mutex::lock(const ::icl_core::TimeStamp& timeout)
101 {
102  LLOGGING_TRACE_C(Thread, Mutex, "Locking mutex with absolute timeout " << timeout << " ..." << endl);
103  bool result = m_impl->lock(timeout);
104  LLOGGING_TRACE_C(Thread, Mutex, "Mutex lock " << (result ? "successful" : "failed") << "." << endl);
105  return result;
106 }
107 
108 bool Mutex::lock(const ::icl_core::TimeSpan& timeout)
109 {
110  LLOGGING_TRACE_C(Thread, Mutex, "Locking mutex with relative timeout " << timeout << " ..." << endl);
111  bool result = m_impl->lock(timeout);
112  LLOGGING_TRACE_C(Thread, Mutex, "Mutex lock " << (result ? "successful" : "failed") << "." << endl);
113  return result;
114 }
115 
117 {
118  LLOGGING_TRACE_C(Thread, Mutex, "Trying to lock mutex ..." << endl);
119  bool result = m_impl->tryLock();
120  LLOGGING_TRACE_C(Thread, Mutex, "Mutex try-lock " << (result ? "successful" : "failed") << "." << endl);
121  return result;
122 }
123 
125 {
126  LLOGGING_TRACE_C(Thread, Mutex, "Unlocking mutex." << endl);
127  m_impl->unlock();
128 }
129 
131 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
132 
137 bool Mutex::Lock()
138 {
139  return lock();
140 }
141 
146 bool Mutex::Lock(const icl_core::TimeStamp& timeout)
147 {
148  return lock(timeout);
149 }
150 
155 bool Mutex::Lock(const icl_core::TimeSpan& timeout)
156 {
157  return lock(timeout);
158 }
159 
166 bool Mutex::TryLock()
167 {
168  return tryLock();
169 }
170 
173 void Mutex::Unlock()
174 {
175  unlock();
176 }
177 
178 #endif
179 
181 }
182 }
Represents absolute times.
Definition: TimeStamp.h:61
Contains icl_core::thread::MutexImplWin32.
#define LOCAL_PRINTF(args)
Definition: Mutex.cpp:33
bool isLxrtAvailable()
Definition: os_lxrt.cpp:141
virtual bool tryLock()=0
Contains logging definitions for the icl_core_thread library.
ThreadStream & endl(ThreadStream &stream)
Definition: ThreadStream.h:249
const TimeSpan timeout(1, 0)
Contains global LXRT functions.
Contains icl_core::thread::Mutex.
Repesents absolute times.
Definition: TimeSpan.h:46
Defines icl_core::thread::MutexImplLxrt.
MutexImpl * m_impl
Definition: Mutex.h:127
#define LLOGGING_TRACE_C(streamname, classname, arg)
Contains icl_core::thread::MutexImplPosix.


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