icl_core_thread/SemaphoreImplPosix.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 //----------------------------------------------------------------------
21 //----------------------------------------------------------------------
22 #include "SemaphoreImplPosix.h"
23 
24 #include <errno.h>
25 
26 #include "Common.h"
27 
28 namespace icl_core {
29 namespace thread {
30 
32  : m_semaphore(0)
33 {
34  m_semaphore = new sem_t;
35  sem_init(m_semaphore, PTHREAD_PROCESS_PRIVATE, initial_value);
36 }
37 
39 {
40  if (m_semaphore)
41  {
42  sem_destroy(m_semaphore);
43  delete m_semaphore;
44  m_semaphore = 0;
45  }
46 }
47 
49 {
50  sem_post(m_semaphore);
51 }
52 
54 {
55  int res = sem_trywait(m_semaphore);
56  return (res == 0);
57 }
58 
60 {
61  int res = sem_wait(m_semaphore);
62  return (res == 0);
63 }
64 
66 {
67  return wait(impl::getAbsoluteTimeout(timeout));
68 }
69 
71 {
72  struct timespec timeout_spec = timeout.timespec();
73  int res = sem_timedwait(m_semaphore, &timeout_spec);
74  return (res == 0);
75 }
76 
77 }
78 }
TimeStamp getAbsoluteTimeout(const TimeSpan &timeout_relative)
Definition: Common.h:59
Represents absolute times.
Definition: TimeStamp.h:61
struct timespec timespec() const
Definition: TimeBase.cpp:113
Contains icl_core::thread::tMutex.
const TimeSpan timeout(1, 0)
Repesents absolute times.
Definition: TimeSpan.h:46
Contains icl_core::thread::SemaphoreImplPosix.


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