HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PRM_Lock.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: PRM_Lock.h (PRM Library, C++)
7  *
8  * COMMENTS: This header allows us to enable/disable locking when cooking.
9  */
10 
11 #ifndef __PRM_LOCK_H_INCLUDED__
12 #define __PRM_LOCK_H_INCLUDED__
13 
14 #include "PRM_API.h"
15 
16 #include <tbb/spin_rw_mutex.h>
17 
18 // Modify this to enable/disable node cook locking
19 #define PRM_LOCKS 1
20 
21 #if PRM_LOCKS
22  typedef tbb::spin_rw_mutex PRM_SpinLock;
23  typedef tbb::spin_rw_mutex::scoped_lock PRM_SpinLockScope;
24 
26  {
27  public:
30  {
31  }
32 
34  : PRM_SpinLockScope(lock, /*write*/false)
35  {
36  }
37 
38  // Acquire lock on given mutex
39  void acquire(PRM_SpinLock &lock)
40  {
41  PRM_SpinLockScope::acquire(lock, /*write*/false);
42  }
43 
44  // Change reader lock to a writer lock. Returns false if the lock was
45  // released in favour of another upgrade request and then reacquired;
46  // true otherwise.
48  {
49  return PRM_SpinLockScope::upgrade_to_writer();
50  }
51  };
53  {
54  public:
57  {
58  }
59 
61  : PRM_SpinLockScope(lock, /*write*/true)
62  {
63  }
64 
65  // Acquire lock on given mutex
66  void acquire(PRM_SpinLock &lock)
67  {
68  PRM_SpinLockScope::acquire(lock, /*write*/true);
69  }
70  };
71 
72 #else
73  typedef UT_NullLock PRM_SpinLock;
75 #endif
76 
77 #endif // __PRM_LOCK_H_INCLUDED__
bool upgradeToWriter()
Definition: PRM_Lock.h:47
void acquire(PRM_SpinLock &lock)
Definition: PRM_Lock.h:39
tbb::spin_rw_mutex PRM_SpinLock
Definition: PRM_Lock.h:22
tbb::spin_rw_mutex::scoped_lock PRM_SpinLockScope
Definition: PRM_Lock.h:23
PRM_SpinLockWriteScope(PRM_SpinLock &lock)
Definition: PRM_Lock.h:60
#define PRM_API
Definition: PRM_API.h:10
void acquire(PRM_SpinLock &lock)
Definition: PRM_Lock.h:66
PRM_SpinLockReadScope(PRM_SpinLock &lock)
Definition: PRM_Lock.h:33