icl_core_thread/SemaphoreImplDarwin.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 "SemaphoreImplDarwin.h"
23 
24 #include <mach/mach_init.h>
25 #include <mach/task.h>
26 
27 #include "Common.h"
28 
29 namespace icl_core {
30 namespace thread {
31 
33  :m_semaphore(0)
34 {
35  semaphore_create(mach_task_self(), &m_semaphore, SYNC_POLICY_FIFO, initial_value);
36 }
37 
39 {
40  semaphore_destroy(mach_task_self(), m_semaphore);
41  m_semaphore = 0;
42 }
43 
45 {
46  semaphore_signal(m_semaphore);
47 }
48 
50 {
51  return wait(icl_core::TimeSpan(0, 0));
52 }
53 
55 {
56  kern_return_t res = semaphore_wait(m_semaphore);
57  return (res == KERN_SUCCESS);
58 }
59 
61 {
62  mach_timespec_t timeout_spec = timeout.machTimespec();
63  kern_return_t res = semaphore_timedwait(m_semaphore, timeout_spec);
64  return (res == KERN_SUCCESS);
65 }
66 
68 {
69  return wait(impl::getRelativeTimeout(timeout));
70 }
71 
72 }
73 }
Contains icl_core::thread::SemaphoreImplDarwin.
Represents absolute times.
Definition: TimeStamp.h:61
Contains icl_core::thread::tMutex.
const TimeSpan timeout(1, 0)
Repesents absolute times.
Definition: TimeSpan.h:46
TimeSpan getRelativeTimeout(const TimeStamp &timeout_absolute)
Definition: Common.h:46


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