SemaphoreImplLxrt38.cpp
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of FZIs ic_workspace.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00021 //----------------------------------------------------------------------
00022 #include "SemaphoreImplLxrt38.h"
00023 
00024 #include <rtai_posix.h>
00025 
00026 #include "Common.h"
00027 
00028 namespace icl_core {
00029 namespace thread {
00030 
00031 SemaphoreImplLxrt38::SemaphoreImplLxrt38(size_t initial_value, int type)
00032   : m_semaphore(NULL)
00033 {
00034   m_semaphore = rt_typed_sem_init(size_t(this), initial_value, type | PRIO_Q);
00035 }
00036 
00037 SemaphoreImplLxrt38::~SemaphoreImplLxrt38()
00038 {
00039   if (m_semaphore != NULL)
00040   {
00041     rt_sem_delete(m_semaphore);
00042     m_semaphore = NULL;
00043   }
00044 }
00045 
00046 void SemaphoreImplLxrt38::post()
00047 {
00048   rt_sem_signal(m_semaphore);
00049 }
00050 
00051 bool SemaphoreImplLxrt38::tryWait()
00052 {
00053   int res = rt_sem_wait_if(m_semaphore);
00054   return (res > 0 && res < SEM_TIMOUT);
00055 }
00056 
00057 bool SemaphoreImplLxrt38::wait()
00058 {
00059   int res = rt_sem_wait(m_semaphore);
00060   return (res < SEM_TIMOUT);
00061 }
00062 
00063 bool SemaphoreImplLxrt38::wait(const icl_core::TimeSpan& timeout)
00064 {
00065   return wait(impl::getAbsoluteTimeout(timeout));
00066 }
00067 
00068 bool SemaphoreImplLxrt38::wait(const icl_core::TimeStamp& timeout)
00069 {
00070   struct timespec timeout_spec = timeout.systemTimespec();
00071   int res = rt_sem_wait_until(m_semaphore, timespec2count(&timeout_spec));
00072   return (res < SEM_TIMOUT);
00073 }
00074 
00075 }
00076 }


fzi_icl_core
Author(s):
autogenerated on Tue Aug 8 2017 02:28:03