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

Last change on this file since 213 was 213, checked in by Sanahuja Guillaume, 4 years ago

thread stack size rework
add Matrix class

File size: 2.5 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 char errorMsg[256];
31 self->Err("rt_mutex_create error (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg)));
32 }
33#else
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 }
48#endif
49}
50
51Mutex_impl::~Mutex_impl() {
52 int status;
53
54#ifdef __XENO__
55 status = rt_mutex_delete(&mutex);
56#else
57 status = pthread_mutex_destroy(&mutex);
58#endif
59 if (status != 0) {
60 char errorMsg[256];
61 self->Err("error destroying mutex (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg)));
62 }
63}
64
65void Mutex_impl::GetMutex(void) {
66 int status;
67
68#ifdef __XENO__
69 status = rt_mutex_acquire(&mutex, TM_INFINITE);
70#else
71 // flag_locked=true;
72 status = pthread_mutex_lock(&mutex);
73#endif
74 if (status != 0) {
75 char errorMsg[256];
76 self->Err("error (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg)));
77 }
78}
79
80void Mutex_impl::ReleaseMutex(void) {
81 int status;
82
83#ifdef __XENO__
84 status = rt_mutex_release(&mutex);
85#else
86 status = pthread_mutex_unlock(&mutex);
87// flag_locked=false;
88#endif
89 if (status != 0) {
90 char errorMsg[256];
91 self->Err("error (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg)));
92 }
93}
94
95/*
96bool Mutex_impl::IsLocked(void)
97{
98#ifdef __XENO__
99 RT_MUTEX_INFO info;
100 int status=rt_mutex_inquire(&mutex_rt,&info);
101 if(status!=0) mutex->Err("erreur rt_mutex_inquire (%s)\n",strerror_r(-status, errorMsg, sizeof(errorMsg)));
102 if(info.locked>0) return true;
103 return false;
104#else
105 return flag_locked;
106#endif
107}
108*/
Note: See TracBrowser for help on using the repository browser.