// %flair:license{ // This file is part of the Flair framework distributed under the // CECILL-C License, Version 1.0. // %flair:license} // created: 2016/11/16 // filename: Semaphore_impl.cpp // // author: Thomas Fuhrmann // Copyright Heudiasyc UMR UTC/CNRS 7253 // // version: $Id: $ // // purpose: Class defining a semaphore implementation // // /*********************************************************************/ #include "Semaphore.h" #include "Semaphore_impl.h" #include using std::string; using namespace flair::core; Semaphore_impl::Semaphore_impl(Semaphore *self, uint32_t initialValue) { this->self = self; int status; #ifdef __XENO__ status = rt_sem_create(&semaphore, NULL, initialValue, S_FIFO); #else status = sem_init(&semaphore, 0, initialValue); #endif if (status != 0) { self->Err("error creating semaphore (%s)\n", strerror(-status)); } } Semaphore_impl::~Semaphore_impl() { int status; #ifdef __XENO__ status = rt_sem_delete(&semaphore); #else status = sem_destroy(&semaphore); #endif if (status != 0) self->Err("error destroying semaphore (%s)\n", strerror(-status)); } void Semaphore_impl::GetSemaphore(void) { int status; #ifdef __XENO__ status = rt_sem_p(&semaphore, TM_INFINITE); #else status = sem_wait(&semaphore); #endif if (status != 0) self->Err("error getting the semaphore (%s)\n", strerror(-status)); } void Semaphore_impl::ReleaseSemaphore(void) { int status; #ifdef __XENO__ status = rt_sem_v(&semaphore); #else status = sem_post(&semaphore); #endif if (status != 0) self->Err("error releasing the semaphore (%s)\n", strerror(-status)); }