Sem.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 //----------------------------------------------------------------------
23 #include "icl_core_thread/Sem.h"
24 
25 
26 #if defined _SYSTEM_LXRT_
27 # include "SemaphoreImplLxrt.h"
28 #endif
29 
30 #if defined _SYSTEM_DARWIN_
31 # include "SemaphoreImplDarwin.h"
32 #elif defined _SYSTEM_POSIX_
33 # include "SemaphoreImplPosix.h"
34 #elif defined _SYSTEM_WIN32_
35 # include "SemaphoreImplWin32.h"
36 #else
37 # error "No semaphore implementation defined for this platform."
38 #endif
39 
40 namespace icl_core {
41 namespace thread {
42 
43 Semaphore::Semaphore(size_t initial_value)
44  : m_impl(0)
45 {
46 #if defined _SYSTEM_LXRT_
47  // Only create an LXRT implementation if the LXRT runtime system is
48  // really available. Otherwise create an ACE or POSIX
49  // implementation, depending on the system configuration.
50  // Remark: This allows us to compile programs with LXRT support but
51  // run them on systems on which no LXRT is installed and to disable
52  // LXRT support at program startup on systems with installed LXRT!
54  {
55  m_impl = new SemaphoreImplLxrt(initial_value);
56  }
57  else
58  {
59  m_impl = new SemaphoreImplPosix(initial_value);
60  }
61 
62 #elif defined _SYSTEM_DARWIN_
63  m_impl = new SemaphoreImplDarwin(initial_value);
64 
65 #elif defined _SYSTEM_POSIX_
66  m_impl = new SemaphoreImplPosix(initial_value);
67 
68 #elif defined _SYSTEM_WIN32_
69  m_impl = new SemaphoreImplWin32(initial_value);
70 
71 #endif
72 }
73 
75 {
76  delete m_impl;
77  m_impl = 0;
78 }
79 
81 {
82  return m_impl->post();
83 }
84 
86 {
87  return m_impl->tryWait();
88 }
89 
91 {
92  return m_impl->wait();
93 }
94 
96 {
97  return m_impl->wait(timeout);
98 }
99 
101 {
102  return m_impl->wait(timeout);
103 }
104 
106 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
107 
111 void Semaphore::Post()
112 {
113  post();
114 }
115 
119 bool Semaphore::TryWait()
120 {
121  return tryWait();
122 }
123 
127 bool Semaphore::Wait()
128 {
129  return wait();
130 }
131 
135 bool Semaphore::Wait(const icl_core::TimeSpan& timeout)
136 {
137  return wait(timeout);
138 }
139 
143 bool Semaphore::Wait(const icl_core::TimeStamp& timeout)
144 {
145  return wait(timeout);
146 }
147 
148 #endif
149 
151 }
152 }
Represents absolute times.
Definition: TimeStamp.h:61
SemaphoreImpl * m_impl
Definition: Sem.h:122
bool isLxrtAvailable()
Definition: os_lxrt.cpp:141
const TimeSpan timeout(1, 0)
Repesents absolute times.
Definition: TimeSpan.h:46
Contains icl_core::thread::Semaphore.
Semaphore(size_t initial_value)
Definition: Sem.cpp:43


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