source: flair-src/trunk/lib/FlairCore/src/ConditionVariable_impl.cpp @ 133

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

modif sterror

File size: 2.6 KB
RevLine 
[2]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[2]4// %flair:license}
5//  created:    2014/02/07
6//  filename:   ConditionVariable_impl.cpp
7//
8//  author:     Guillaume Sanahuja
9//              Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11//  version:    $Id: $
12//
13//  purpose:    Class defining a condition variable
14//
15//
16/*********************************************************************/
17
18#include "ConditionVariable_impl.h"
19#include "ConditionVariable.h"
20#include "Mutex_impl.h"
21#include <string.h>
22
23using std::string;
24using namespace flair::core;
25
[15]26ConditionVariable_impl::ConditionVariable_impl(ConditionVariable *self) {
27  this->self = self;
28  int status;
[2]29
30#ifdef __XENO__
[15]31  status = rt_cond_create(&m_ResumeCond, NULL);
[2]32#else
[15]33  status = pthread_cond_init(&m_ResumeCond, 0);
[2]34#endif
[133]35  if (status != 0) {
36                char errorMsg[256];
37    self->Err("error creating condition variable (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg)));
38        }
[2]39}
40
41ConditionVariable_impl::~ConditionVariable_impl() {
[15]42  int status;
[2]43
44#ifdef __XENO__
[15]45  status = rt_cond_delete(&m_ResumeCond);
[2]46#else
[15]47  status = pthread_cond_destroy(&m_ResumeCond);
[2]48#endif
[133]49  if (status != 0) {
50                char errorMsg[256];
51    self->Err("error destroying condition variable (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg)));
52        }
[2]53}
54
55void ConditionVariable_impl::CondWait(void) {
[15]56  int status;
[2]57#ifdef __XENO__
[15]58  status =
59      rt_cond_wait(&m_ResumeCond, &self->Mutex::pimpl_->mutex, TM_INFINITE);
[2]60#else
[15]61  status = pthread_cond_wait(&m_ResumeCond, &self->Mutex::pimpl_->mutex);
[2]62#endif
[133]63  if (status != 0) {
64                char errorMsg[256];
65    self->Err("error (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg)));
66        }
[2]67}
68
69bool ConditionVariable_impl::CondWaitUntil(Time date) {
[15]70  int status;
[2]71#ifdef __XENO__
[15]72  status = rt_cond_wait_until(&m_ResumeCond, &self->Mutex::pimpl_->mutex, date);
[2]73#else
[15]74  struct timespec restrict;
75  restrict.tv_sec = date / 1000000000;
76  restrict.tv_nsec = date % 1000000000;
77  status = pthread_cond_timedwait(&m_ResumeCond, &self->Mutex::pimpl_->mutex,
78                                  &restrict);
[2]79#endif
[15]80  if (status == 0)
81    return true;
[133]82  if (status != ETIMEDOUT) {
83                char errorMsg[256];
84    self->Err("error (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg)));
85        }
[15]86  return false;
[2]87}
88
89void ConditionVariable_impl::CondSignal(void) {
[15]90  int status;
[2]91#ifdef __XENO__
[15]92  status = rt_cond_signal(&m_ResumeCond);
[2]93#else
[15]94  status = pthread_cond_signal(&m_ResumeCond);
[2]95#endif
[133]96        if (status != 0) {
97                char errorMsg[256];
98    self->Err("error (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg)));
99        }
[2]100}
Note: See TracBrowser for help on using the repository browser.