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

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

sources reformatted with flair-format-dir script

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