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

Last change on this file since 192 was 133, checked in by Sanahuja Guillaume, 7 years ago

modif sterror

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