source: flair-src/trunk/lib/FlairCore/src/Mutex_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
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: 2012/03/14
6// filename: Mutex.cpp
7//
8// author: Guillaume Sanahuja
9// Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11// version: $Id: $
12//
13// purpose: Class defining a mutex
14//
15//
16/*********************************************************************/
17
18#include "Mutex_impl.h"
19#include "Mutex.h"
20#include <string.h>
21
22using std::string;
23using namespace flair::core;
24
25Mutex_impl::Mutex_impl(Mutex *self) {
26 this->self = self;
27#ifdef __XENO__
28 int status = rt_mutex_create(&mutex, NULL);
29 if (status != 0)
30 self->Err("rt_mutex_create error (%s)\n", strerror(-status));
31#else
32 // flag_locked=false;//revoir l'implementation nrt du is_locked
33 pthread_mutexattr_t attr;
34 if (pthread_mutexattr_init(&attr) != 0) {
35 self->Err("pthread_mutexattr_init error\n");
36 }
37 if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0) {
38 self->Err("pthread_mutexattr_settype error\n");
39 }
40 if (pthread_mutex_init(&mutex, &attr) != 0) {
41 self->Err("pthread_mutex_init error\n");
42 }
43 if (pthread_mutexattr_destroy(&attr) != 0) {
44 self->Err("pthread_mutexattr_destroy error\n");
45 }
46#endif
47}
48
49Mutex_impl::~Mutex_impl() {
50 int status;
51#ifdef __XENO__
52 status = rt_mutex_delete(&mutex);
53#else
54 status = pthread_mutex_destroy(&mutex);
55#endif
56 if (status != 0)
57 self->Err("error destroying mutex (%s)\n", strerror(-status));
58}
59
60void Mutex_impl::GetMutex(void) {
61 int status;
62#ifdef __XENO__
63 status = rt_mutex_acquire(&mutex, TM_INFINITE);
64#else
65 // flag_locked=true;
66 status = pthread_mutex_lock(&mutex);
67#endif
68 if (status != 0)
69 self->Err("error (%s)\n", strerror(-status));
70}
71
72void Mutex_impl::ReleaseMutex(void) {
73 int status;
74#ifdef __XENO__
75 status = rt_mutex_release(&mutex);
76#else
77 status = pthread_mutex_unlock(&mutex);
78// flag_locked=false;
79#endif
80 if (status != 0)
81 self->Err("error (%s)\n", strerror(-status));
82}
83
84/*
85bool Mutex_impl::IsLocked(void)
86{
87#ifdef __XENO__
88 RT_MUTEX_INFO info;
89 int status=rt_mutex_inquire(&mutex_rt,&info);
90 if(status!=0) mutex->Err("erreur rt_mutex_inquire
91(%s)\n",strerror(-status));
92 if(info.locked>0) return true;
93 return false;
94#else
95 return flag_locked;
96#endif
97}
98*/
Note: See TracBrowser for help on using the repository browser.