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

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

flaircore

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{
27 this->self=self;
28#ifdef __XENO__
29 int status=rt_mutex_create(&mutex,NULL);
30 if(status!=0) 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 {
36 self->Err("pthread_mutexattr_init error\n");
37 }
38 if(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0)
39 {
40 self->Err("pthread_mutexattr_settype error\n");
41 }
42 if(pthread_mutex_init(&mutex, &attr)!=0)
43 {
44 self->Err("pthread_mutex_init error\n");
45 }
46 if(pthread_mutexattr_destroy(&attr)!=0)
47 {
48 self->Err("pthread_mutexattr_destroy error\n");
49 }
50#endif
51}
52
53Mutex_impl::~Mutex_impl()
54{
55 int status;
56#ifdef __XENO__
57 status=rt_mutex_delete(&mutex);
58#else
59 status=pthread_mutex_destroy(&mutex);
60#endif
61 if(status!=0) self->Err("error destroying mutex (%s)\n",strerror(-status));
62}
63
64void Mutex_impl::GetMutex(void)
65{
66 int status;
67#ifdef __XENO__
68 status=rt_mutex_acquire(&mutex,TM_INFINITE);
69#else
70 //flag_locked=true;
71 status=pthread_mutex_lock(&mutex);
72#endif
73 if(status!=0) self->Err("error (%s)\n",strerror(-status));
74}
75
76void Mutex_impl::ReleaseMutex(void)
77{
78 int status;
79#ifdef __XENO__
80 status=rt_mutex_release(&mutex);
81#else
82 status=pthread_mutex_unlock(&mutex);
83 //flag_locked=false;
84#endif
85 if(status!=0) self->Err("error (%s)\n",strerror(-status));
86}
87
88/*
89bool Mutex_impl::IsLocked(void)
90{
91#ifdef __XENO__
92 RT_MUTEX_INFO info;
93 int status=rt_mutex_inquire(&mutex_rt,&info);
94 if(status!=0) mutex->Err("erreur rt_mutex_inquire (%s)\n",strerror(-status));
95 if(info.locked>0) return true;
96 return false;
97#else
98 return flag_locked;
99#endif
100}
101*/
Note: See TracBrowser for help on using the repository browser.