HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NET_RWLock.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: NET_RWLock.h
7  *
8  * COMMENTS:
9  *
10  *
11  */
12 
13 #ifndef __NET_RWLOCK_H__
14 #define __NET_RWLOCK_H__
15 
16 #include "NET_API.h"
17 
18 #include <UT/UT_Assert.h>
19 
20 #if 0
21 #include <tbb/spin_rw_mutex.h>
22 
23 using NET_RWLock = tbb::spin_rw_mutex;
24 
25 class NET_AutoReadLock : public NET_RWLock::scoped_lock
26 {
27 public:
29  : NET_RWLock::scoped_lock()
30  {
31  acquire(lock, false /*write*/);
32  }
33 
34  NET_AutoReadLock(const NET_AutoReadLock&) = delete;
36 private:
37 };
38 
39 class NET_AutoWriteLock : public NET_RWLock::scoped_lock
40 {
41 public:
43  : NET_RWLock::scoped_lock()
44  {
45  acquire(lock, true /*write*/);
46  }
47 
48  NET_AutoWriteLock(const NET_AutoWriteLock&) = delete;
50 private:
51 };
52 
54 {
55 public:
57  myLock(lock)
58  {
59  myLock.upgrade_to_writer();
60  }
61 
63  {
64  myLock.downgrade_to_reader();
65  }
66 
69 
70 private:
71  NET_AutoReadLock& myLock;
72 };
73 #else
74 #include <hboost/thread.hpp>
75 
76 using NET_AutoReadLock = hboost::shared_lock<hboost::shared_mutex>;
77 using NET_AutoWriteLock = hboost::unique_lock<hboost::shared_mutex>;
78 
79 using NET_RWLock = hboost::shared_mutex;
80 
82 {
83 public:
84  explicit NET_AutoReadUnlock(NET_RWLock& lock) :
85  myLock(lock)
86  {
87  myLock.unlock_shared();
88  }
89 
91  {
92  myLock.lock_shared();
93  }
94 
95  NET_AutoReadUnlock(const NET_AutoReadUnlock&) = delete;
97 
98 private:
99  NET_RWLock& myLock;
100 };
101 
103 {
104 public:
106  myLock(lock)
107  {
108  NET_RWLock* l = myLock.mutex();
109  UT_ASSERT_P(l != nullptr);
110  if (l != nullptr)
111  {
112  l->unlock_shared();
113  l->lock();
114  }
115  }
116 
118  {
119  NET_RWLock* l = myLock.mutex();
120  UT_ASSERT_P(l != nullptr);
121  if (l != nullptr)
122  {
123  l->unlock();
124  l->lock_shared();
125  }
126  }
127 
130 
131 private:
132  NET_AutoReadLock& myLock;
133 };
134 #endif
135 
136 #endif // __NET_RWLOCK_H__
137 
NET_AutoReadToWriteLock(NET_AutoReadLock &lock)
Definition: NET_RWLock.h:105
#define NET_API
Definition: NET_API.h:9
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:155
hboost::shared_mutex NET_RWLock
Definition: NET_RWLock.h:79
hboost::unique_lock< hboost::shared_mutex > NET_AutoWriteLock
Definition: NET_RWLock.h:77
NET_AutoReadUnlock(NET_RWLock &lock)
Definition: NET_RWLock.h:84
hboost::shared_lock< hboost::shared_mutex > NET_AutoReadLock
Definition: NET_RWLock.h:76
LeafData & operator=(const LeafData &)=delete