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

Last change on this file since 67 was 15, checked in by Bayard Gildas, 6 years ago

sources reformatted with flair-format-dir script

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