icl_core_thread/SemaphoreImplLxrt33.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 "SemaphoreImplLxrt33.h"
23 
24 #include <errno.h>
25 
26 #include "Common.h"
27 
28 #include <iostream>
29 
30 namespace icl_core {
31 namespace thread {
32 
34  : m_semaphore(NULL)
35 {
36  m_semaphore = new sem_t;
37  sem_init_rt(m_semaphore, PTHREAD_PROCESS_PRIVATE, initial_value);
38 }
39 
41 {
42  if (m_semaphore != NULL)
43  {
44  sem_destroy_rt(m_semaphore);
45  delete m_semaphore;
46  m_semaphore = 0;
47  }
48 }
49 
51 {
52  sem_post_rt(m_semaphore);
53 }
54 
56 {
57  int res = sem_trywait_rt(m_semaphore);
58  return (res == 0);
59 }
60 
62 {
63  int res = sem_wait_rt(m_semaphore);
64  return (res == 0);
65 }
66 
68 {
69  return wait(impl::getAbsoluteTimeout(timeout));
70 }
71 
73 {
74  struct timespec timeout_spec = timeout.systemTimespec();
75  int res = sem_timedwait_rt(m_semaphore, &timeout_spec);
76  return (res == 0);
77 }
78 
79 }
80 }
TimeStamp getAbsoluteTimeout(const TimeSpan &timeout_relative)
Definition: Common.h:59
Represents absolute times.
Definition: TimeStamp.h:61
Contains icl_core::thread::SemaphoreImplLxrt33.
Contains icl_core::thread::tMutex.
const TimeSpan timeout(1, 0)
Repesents absolute times.
Definition: TimeSpan.h:46
struct timespec systemTimespec() const
Definition: TimeBase.cpp:121


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