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, 6 years ago

modif sterror

File size: 2.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: 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
26ConditionVariable_impl::ConditionVariable_impl(ConditionVariable *self) {
27 this->self = self;
28 int status;
29
30#ifdef __XENO__
31 status = rt_cond_create(&m_ResumeCond, NULL);
32#else
33 status = pthread_cond_init(&m_ResumeCond, 0);
34#endif
35 if (status != 0) {
36 char errorMsg[256];
37 self->Err("error creating condition variable (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg)));
38 }
39}
40
41ConditionVariable_impl::~ConditionVariable_impl() {
42 int status;
43
44#ifdef __XENO__
45 status = rt_cond_delete(&m_ResumeCond);
46#else
47 status = pthread_cond_destroy(&m_ResumeCond);
48#endif
49 if (status != 0) {
50 char errorMsg[256];
51 self->Err("error destroying condition variable (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg)));
52 }
53}
54
55void ConditionVariable_impl::CondWait(void) {
56 int status;
57#ifdef __XENO__
58 status =
59 rt_cond_wait(&m_ResumeCond, &self->Mutex::pimpl_->mutex, TM_INFINITE);
60#else
61 status = pthread_cond_wait(&m_ResumeCond, &self->Mutex::pimpl_->mutex);
62#endif
63 if (status != 0) {
64 char errorMsg[256];
65 self->Err("error (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg)));
66 }
67}
68
69bool ConditionVariable_impl::CondWaitUntil(Time date) {
70 int status;
71#ifdef __XENO__
72 status = rt_cond_wait_until(&m_ResumeCond, &self->Mutex::pimpl_->mutex, date);
73#else
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);
79#endif
80 if (status == 0)
81 return true;
82 if (status != ETIMEDOUT) {
83 char errorMsg[256];
84 self->Err("error (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg)));
85 }
86 return false;
87}
88
89void ConditionVariable_impl::CondSignal(void) {
90 int status;
91#ifdef __XENO__
92 status = rt_cond_signal(&m_ResumeCond);
93#else
94 status = pthread_cond_signal(&m_ResumeCond);
95#endif
96 if (status != 0) {
97 char errorMsg[256];
98 self->Err("error (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg)));
99 }
100}
Note: See TracBrowser for help on using the repository browser.