source: flair-src/trunk/lib/FlairCore/src/Semaphore_impl.cpp @ 124

Last change on this file since 124 was 118, checked in by Sanahuja Guillaume, 5 years ago

aded semaphore
resolved bug for rt_printf before thread is started

File size: 1.6 KB
Line 
1// %flair:license{
2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
4// %flair:license}
5//  created:    2016/11/16
6//  filename:   Semaphore_impl.cpp
7//
8//  author:     Thomas Fuhrmann
9//              Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11//  version:    $Id: $
12//
13//  purpose:    Class defining a semaphore implementation
14//
15//
16/*********************************************************************/
17
18#include "Semaphore.h"
19#include "Semaphore_impl.h"
20
21#include <string.h>
22
23using std::string;
24using namespace flair::core;
25
26Semaphore_impl::Semaphore_impl(Semaphore *self, uint32_t initialValue) {
27  this->self = self;
28  int status;
29#ifdef __XENO__
30  status = rt_sem_create(&semaphore, NULL, initialValue, S_FIFO);
31#else
32  status = sem_init(&semaphore, 0, initialValue);
33#endif
34  if (status != 0) {
35    self->Err("error creating semaphore (%s)\n", strerror(-status));
36  }
37}
38
39Semaphore_impl::~Semaphore_impl() {
40  int status;
41#ifdef __XENO__
42  status = rt_sem_delete(&semaphore);
43#else
44  status = sem_destroy(&semaphore);
45#endif
46  if (status != 0)
47    self->Err("error destroying semaphore (%s)\n", strerror(-status));
48}
49
50void Semaphore_impl::GetSemaphore(void) {
51  int status;
52#ifdef __XENO__
53  status = rt_sem_p(&semaphore, TM_INFINITE);
54#else
55  status = sem_wait(&semaphore);
56#endif
57  if (status != 0)
58    self->Err("error getting the semaphore (%s)\n", strerror(-status));
59}
60
61void Semaphore_impl::ReleaseSemaphore(void) {
62  int status;
63#ifdef __XENO__
64  status = rt_sem_v(&semaphore);
65#else
66  status = sem_post(&semaphore);
67#endif
68  if (status != 0)
69    self->Err("error releasing the semaphore (%s)\n", strerror(-status));
70}
Note: See TracBrowser for help on using the repository browser.