HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_Lockable.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: UT_Lockable.h (UT Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __UT_LOCKABLE_H_INCLUDED__
13 #define __UT_LOCKABLE_H_INCLUDED__
14 
15 #include "UT_API.h"
16 #include "UT_LockUtil.h"
17 #include "UT_NonCopyable.h"
18 #include <SYS/SYS_Types.h>
19 
20 /// UT_Lock interface adapter for C++11 mutexes
21 template <typename MUTEX>
23 {
24 public:
27 
29 
30  using Scope = UT_UniqueLock< UT_Lockable<MUTEX> >;
31 
32  bool tryLock() { return myMutex.try_lock(); }
33  void lock() { myMutex.lock(); }
34  void unlock() { myMutex.unlock(); }
35  bool safeLock() { lock(); return true; }
36 
37  bool isLocked()
38  {
39  if (tryLock())
40  {
41  unlock();
42  return false;
43  }
44  return true;
45  }
46 
47  exint getMemoryUsage(bool inclusive) const
48  {
49  return (inclusive ? sizeof(*this) : 0);
50  }
51 
52 protected:
53  MUTEX& mutex() { return myMutex; }
54 
55 private:
56  MUTEX myMutex;
57 };
58 
59 #endif // __UT_LOCKABLE_H_INCLUDED__
void lock()
Definition: UT_Lockable.h:33
exint getMemoryUsage(bool inclusive) const
Definition: UT_Lockable.h:47
bool tryLock()
Definition: UT_Lockable.h:32
UT_Lock interface adapter for C++11 mutexes.
Definition: UT_Lockable.h:22
int64 exint
Definition: SYS_Types.h:125
MUTEX & mutex()
Definition: UT_Lockable.h:53
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
bool safeLock()
Definition: UT_Lockable.h:35
void unlock()
Definition: UT_Lockable.h:34
bool isLocked()
Definition: UT_Lockable.h:37