Libthreadar  1.4.0
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-2020 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 #include "exceptions.hpp"
32 
33  // C system headers
34 extern "C"
35 {
36 #if HAVE_PTHREAD_H
37 #include <pthread.h>
38 #endif
39 }
40  // C++ standard headers
41 #include <string>
42 
43 
44  // libthreadar headers
45 
46 
47 namespace libthreadar
48 {
50 
56  class mutex
57  {
58  public:
60  mutex();
61 
63  mutex(const mutex & ref) = delete;
64 
66  mutex(mutex && ref) = default;
67 
69  mutex & operator = (const mutex & ref) = delete;
70 
72  mutex & operator = (mutex && ref) noexcept = default;
73 
75  virtual ~mutex();
76 
78 
82  void lock();
83 
85 
88  void unlock();
89 
91 
93  bool try_lock();
94 
95  protected:
96  pthread_mutex_t mut; //< the mutex
97  };
98 
99 } // end of namespace
100 
101 #endif
defines a set of exceptions that are used by libthreadar to report error situations ...
virtual ~mutex()
destructor
mutex & operator=(const mutex &ref)=delete
no assignment operator
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
This is the only namespace used in libthreadar and all symbols provided by libthreadar are member of ...
Definition: barrier.hpp:45
Wrapper around the Posix pthread_mutex_t C objects.
Definition: mutex.hpp:56