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

Last change on this file since 2 was 2, checked in by Sanahuja Guillaume, 6 years ago

flaircore

File size: 2.2 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) self->Err("error creating condition variable (%s)\n",strerror(-status));
36}
37
38ConditionVariable_impl::~ConditionVariable_impl() {
39 int status;
40
41#ifdef __XENO__
42 status=rt_cond_delete(&m_ResumeCond);
43#else
44 status=pthread_cond_destroy(&m_ResumeCond);
45#endif
46 if(status!=0) self->Err("error destroying condition variable (%s)\n",strerror(-status));
47}
48
49void ConditionVariable_impl::CondWait(void) {
50 int status;
51#ifdef __XENO__
52 status=rt_cond_wait(&m_ResumeCond, &self->Mutex::pimpl_->mutex,TM_INFINITE);
53#else
54 status=pthread_cond_wait(&m_ResumeCond, &self->Mutex::pimpl_->mutex);
55#endif
56 if(status!=0) self->Err("error (%s)\n",strerror(-status));
57}
58
59bool ConditionVariable_impl::CondWaitUntil(Time date) {
60 int status;
61#ifdef __XENO__
62 status=rt_cond_wait_until(&m_ResumeCond, &self->Mutex::pimpl_->mutex,date);
63#else
64 struct timespec restrict;
65 restrict.tv_sec=date/1000000000;
66 restrict.tv_nsec=date%1000000000;
67 status=pthread_cond_timedwait(&m_ResumeCond, &self->Mutex::pimpl_->mutex,&restrict);
68#endif
69 if (status==0) return true;
70 if(status!=ETIMEDOUT) self->Err("error (%s)\n",strerror(-status));
71 return false;
72}
73
74void ConditionVariable_impl::CondSignal(void) {
75 int status;
76#ifdef __XENO__
77 status=rt_cond_signal(&m_ResumeCond);
78#else
79 status=pthread_cond_signal(&m_ResumeCond);
80#endif
81 if(status!=0) self->Err("error (%s)\n",strerror(-status));
82}
Note: See TracBrowser for help on using the repository browser.