libDwm-0.6.0
DwmMutex.hh
Go to the documentation of this file.
1 //===========================================================================
2 // @(#) $DwmPath: dwm/libDwm/tags/libDwm-0.6.0/include/DwmMutex.hh 8401 $
3 // @(#) $Id: DwmMutex.hh 8401 2016-04-17 06:44:31Z dwm $
4 //===========================================================================
5 // Copyright (c) Daniel W. McRobb 2000-2007, 2016
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
10 // are met:
11 //
12 // 1. Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // 2. Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // 3. The names of the authors and copyright holders may not be used to
18 // endorse or promote products derived from this software without
19 // specific prior written permission.
20 //
21 // IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
22 // DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
23 // INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
24 // EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
25 // DAMAGE.
26 //
27 // THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
28 // DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
29 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
30 // REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
31 // IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32 // WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
33 // PURPOSE, OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
34 // TRADEMARK OR OTHER RIGHTS.
35 //===========================================================================
36 
37 //---------------------------------------------------------------------------
40 //---------------------------------------------------------------------------
41 
42 #ifndef _DWMMUTEX_HH_
43 #define _DWMMUTEX_HH_
44 
45 #include "DwmPortability.hh"
46 
47 extern "C" {
48 #include <pthread.h>
49 }
50 
51 #ifdef HAVE_TR1
52 #include <tr1/memory>
53 #define STD_SHARED_PTR std::tr1::shared_ptr
54 #else
55 #include <memory>
56 #define STD_SHARED_PTR std::shared_ptr
57 #endif
58 
59 namespace Dwm {
60 
61  namespace Pthread {
62 
63  //------------------------------------------------------------------------
66  //------------------------------------------------------------------------
67  class Mutex
68  {
69  public:
70  //----------------------------------------------------------------------
72  //----------------------------------------------------------------------
73  Mutex();
74 
75  //----------------------------------------------------------------------
77  //----------------------------------------------------------------------
78  ~Mutex();
79 
80  //----------------------------------------------------------------------
82  //----------------------------------------------------------------------
83  Mutex(const Mutex & mutex);
84 
85  //----------------------------------------------------------------------
87  //----------------------------------------------------------------------
88  Mutex & operator = (const Mutex & mutex);
89 
90  //----------------------------------------------------------------------
93  //----------------------------------------------------------------------
94  bool Lock();
95 
96  //----------------------------------------------------------------------
99  //----------------------------------------------------------------------
100  bool TryLock();
101 
102  //----------------------------------------------------------------------
104  //----------------------------------------------------------------------
105  bool Unlock();
106 
107  friend class ConditionVariable;
108 
109  protected:
110  class Wrapper
111  {
112  public:
113  Wrapper();
114  ~Wrapper();
115  bool Lock();
116  bool TryLock();
117  bool Unlock();
118  pthread_mutex_t & Mutex();
119 
120  private:
121  pthread_mutex_t _mutex;
122  };
123 
124  STD_SHARED_PTR<Wrapper> _mutex;
125  };
126 
127  } // namespace Pthread
128 
129 } // namespace Dwm
130 
131 #endif // _DWMMUTEX_HH_
132 
133 //---------------------------- emacs settings -----------------------------
134 // Local Variables:
135 // mode: C++/la
136 // tab-width: 2
137 // indent-tabs-mode: nil
138 // c-basic-offset: 2
139 // End:
140 //-------------------------------------------------------------------------
bool Unlock()
Unlock the mutex. Returns true on success.
This class just encapsulates a condition variable (from the pthread library), with default attributes...
Definition: DwmConditionVariable.hh:59
bool TryLock()
Try to lock the mutex, without blocking.
Mutex & operator=(const Mutex &mutex)
operator =
Definition: DwmBZ2IO.hh:67
bool Lock()
Lock the mutex.
~Mutex()
Constructor. Destroys the mutex.
Mutex()
Constructor. Initializes the mutex.
This class just encapsulates a pthread_mutex_t (from the pthread library).
Definition: DwmMutex.hh:67
A configure target for dealing with OS differences.