OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ReadWriteMutex.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenThreads - Copyright (C) 1998-2007 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12 */
13 
14 #ifndef _OPENTHREADS_READWRITEMUTEX_
15 #define _OPENTHREADS_READWRITEMUTEX_
16 
17 #include <OpenThreads/Thread>
18 #include <OpenThreads/ReentrantMutex>
19 
20 namespace OpenThreads {
21 
23 {
24  public:
25 
27  _readCount(0) {}
28 
29  virtual ~ReadWriteMutex() {}
30 
31  virtual int readLock()
32  {
34  int result = 0;
35  if (_readCount==0)
36  {
37  result = _readWriteMutex.lock();
38  }
39  ++_readCount;
40  return result;
41  }
42 
43 
44  virtual int readUnlock()
45  {
47  int result = 0;
48  if (_readCount>0)
49  {
50  --_readCount;
51  if (_readCount==0)
52  {
53  result = _readWriteMutex.unlock();
54  }
55  }
56  return result;
57  }
58 
59  virtual int writeLock()
60  {
61  return _readWriteMutex.lock();
62  }
63 
64  virtual int writeUnlock()
65  {
66  return _readWriteMutex.unlock();
67  }
68 
69  protected:
70 
72  ReadWriteMutex& operator = (const ReadWriteMutex&) { return *(this); }
73 
74 #if 0
77 #else
80 #endif
81  unsigned int _readCount;
82 
83 };
84 
86 {
87  public:
88 
91 
92  protected:
94 
95  ScopedReadLock& operator = (const ScopedReadLock&) { return *this; }
96 };
97 
98 
100 {
101  public:
102 
105 
106  protected:
108 
109  ScopedWriteLock& operator = (const ScopedWriteLock&) { return *this; }
110 };
111 
112 }
113 
114 #endif
ScopedReadLock & operator=(const ScopedReadLock &)
This class provides an object-oriented thread mutex interface.
Definition: Mutex.h:31
virtual int unlock()
ScopedWriteLock & operator=(const ScopedWriteLock &)
OpenThreads::Mutex _readCountMutex
ScopedWriteLock(ReadWriteMutex &mutex)
ReadWriteMutex(const ReadWriteMutex &)
ScopedReadLock(ReadWriteMutex &mutex)
virtual int lock()
ReadWriteMutex & operator=(const ReadWriteMutex &)
OpenThreads::Mutex _readWriteMutex