00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*- 00002 //---------------------------------------------------------------------- 00008 //---------------------------------------------------------------------- 00009 #include "SemaphoreImplLxrt33.h" 00010 00011 #include <errno.h> 00012 00013 #include "Common.h" 00014 00015 #include <iostream> 00016 00017 namespace icl_core { 00018 namespace thread { 00019 00020 SemaphoreImplLxrt33::SemaphoreImplLxrt33(size_t initial_value) 00021 : m_semaphore(NULL) 00022 { 00023 m_semaphore = new sem_t; 00024 sem_init_rt(m_semaphore, PTHREAD_PROCESS_PRIVATE, initial_value); 00025 } 00026 00027 SemaphoreImplLxrt33::~SemaphoreImplLxrt33() 00028 { 00029 if (m_semaphore != NULL) 00030 { 00031 sem_destroy_rt(m_semaphore); 00032 delete m_semaphore; 00033 m_semaphore = 0; 00034 } 00035 } 00036 00037 void SemaphoreImplLxrt33::post() 00038 { 00039 sem_post_rt(m_semaphore); 00040 } 00041 00042 bool SemaphoreImplLxrt33::tryWait() 00043 { 00044 int res = sem_trywait_rt(m_semaphore); 00045 return (res == 0); 00046 } 00047 00048 bool SemaphoreImplLxrt33::wait() 00049 { 00050 int res = sem_wait_rt(m_semaphore); 00051 return (res == 0); 00052 } 00053 00054 bool SemaphoreImplLxrt33::wait(const icl_core::TimeSpan& timeout) 00055 { 00056 return wait(impl::getAbsoluteTimeout(timeout)); 00057 } 00058 00059 bool SemaphoreImplLxrt33::wait(const icl_core::TimeStamp& timeout) 00060 { 00061 struct timespec timeout_spec = timeout.systemTimespec(); 00062 int res = sem_timedwait_rt(m_semaphore, &timeout_spec); 00063 return (res == 0); 00064 } 00065 00066 } 00067 }