General IRI utilities
mutex.h
1 // Copyright (C) 2009-2010 Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
2 // Author Sergi Hernandez (shernand@iri.upc.edu)
3 // All rights reserved.
4 //
5 // This file is part of iriutils
6 // iriutils is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU Lesser General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 #ifndef _MUTEX_H
20 #define _MUTEX_H
21 
22 #include <pthread.h>
23 
46 class CMutex
47 {
48  private:
57  pthread_mutex_t access;
58 
59  public:
72  void enter(void);
73 
93  bool try_enter(void);
94 
111  void exit(void);
112 
124  CMutex();
125 
136  virtual ~CMutex();
137 };
138 
139 #endif
Implementation of a mutual exclusion mechanism.
Definition: mutex.h:46
CMutex()
default constructor
Definition: mutex.cpp:24
virtual ~CMutex()
default destructor
Definition: mutex.cpp:75
bool try_enter(void)
function to request access to the critical section and return if denied.
Definition: mutex.cpp:46
void exit(void)
function to release the critical section
Definition: mutex.cpp:64
void enter(void)
function to request access to the critical section
Definition: mutex.cpp:35