Libthreadar  1.0.1
 All Classes Namespaces Files Functions Macros
mutex.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // libthreadar - is a library providing several C++ classes to work with threads
3 // Copyright (C) 2014-2015 Denis Corbin
4 //
5 // This file is part of libthreadar
6 //
7 // libthreadar is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // libhtreadar is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Lesser General Public License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with libthreadar. If not, see <http://www.gnu.org/licenses/>
19 //
20 //----
21 // to contact the author: dar.linux@free.fr
22 /*********************************************************************/
23 
24 #ifndef LIBTHREADAR_MUTEX_HPP
25 #define LIBTHREADAR_MUTEX_HPP
26 
29 
30 #include "config.h"
31 
32  // C system headers
33 extern "C"
34 {
35 #if HAVE_PTHREAD_H
36 #include <pthread.h>
37 #endif
38 }
39  // C++ standard headers
40 #include <string>
41 
42 
43  // libthreadar headers
44 
45 
46 
47 namespace libthreadar
48 {
50 
56  class mutex
57  {
58  public:
60  mutex();
61 
62  // no copy constructor (made private)
63 
64  // no assignment operator (made private)
65 
67  ~mutex();
68 
70 
74  void lock();
75 
77 
80  void unlock();
81 
83 
85  bool try_lock();
86 
87  private:
88  mutex(const mutex & ref) { throw std::string("BUG"); };
89  const mutex & operator = (const mutex & ref) { throw std::string("BUG"); };
90 
91  pthread_mutex_t mut; //< the mutex
92  };
93 
94 } // end of namespace
95 
96 #endif
mutex()
constructor
bool try_lock()
Tells whether calling lock() would currently suspend the caller or not.
void unlock()
unlock the mutex
void lock()
lock the mutex
~mutex()
destructor
This is the only namespace used in libthreadar and all symbols provided by libthreadar are member of ...
Definition: barrier.hpp:46
Wrapper around the Posix pthread_mutex_t C objects.
Definition: mutex.hpp:56