OmniSciDB  ca0c39ec8f
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
lockmgr::MutexTracker Class Reference

#include <LockMgrImpl.h>

+ Inheritance diagram for lockmgr::MutexTracker:
+ Collaboration diagram for lockmgr::MutexTracker:

Public Member Functions

 MutexTracker (std::unique_ptr< heavyai::DistributedSharedMutex > dmutex)
 
virtual void lock ()
 
virtual bool try_lock ()
 
virtual void unlock ()
 
virtual void lock_shared ()
 
virtual bool try_lock_shared ()
 
virtual void unlock_shared ()
 
virtual bool isAcquired () const
 
- Public Member Functions inherited from heavyai::SharedMutexInterface
virtual ~SharedMutexInterface ()
 
- Public Member Functions inherited from heavyai::MutexInterface
virtual ~MutexInterface ()
 

Private Attributes

std::atomic< size_t > ref_count_
 
MutexTypeBase mutex_
 
std::unique_ptr
< heavyai::DistributedSharedMutex
dmutex_
 

Detailed Description

Definition at line 40 of file LockMgrImpl.h.

Constructor & Destructor Documentation

lockmgr::MutexTracker::MutexTracker ( std::unique_ptr< heavyai::DistributedSharedMutex dmutex)
inline

Definition at line 42 of file LockMgrImpl.h.

43  : ref_count_(0u), dmutex_(std::move(dmutex)) {}
std::unique_ptr< heavyai::DistributedSharedMutex > dmutex_
Definition: LockMgrImpl.h:108
std::atomic< size_t > ref_count_
Definition: LockMgrImpl.h:106

Member Function Documentation

virtual bool lockmgr::MutexTracker::isAcquired ( ) const
inlinevirtual

Definition at line 103 of file LockMgrImpl.h.

References ref_count_.

103 { return ref_count_.load() > 0; }
std::atomic< size_t > ref_count_
Definition: LockMgrImpl.h:106
virtual void lockmgr::MutexTracker::lock ( )
inlinevirtual

Implements heavyai::MutexInterface.

Definition at line 45 of file LockMgrImpl.h.

References dmutex_, g_multi_instance, mutex_, and ref_count_.

45  {
46  ref_count_.fetch_add(1u);
47  if (!g_multi_instance) {
48  mutex_.lock();
49  } else {
50  dmutex_->lock();
51  }
52  }
MutexTypeBase mutex_
Definition: LockMgrImpl.h:107
bool g_multi_instance
Definition: heavyai_locks.h:21
std::unique_ptr< heavyai::DistributedSharedMutex > dmutex_
Definition: LockMgrImpl.h:108
std::atomic< size_t > ref_count_
Definition: LockMgrImpl.h:106
virtual void lockmgr::MutexTracker::lock_shared ( )
inlinevirtual

Implements heavyai::SharedMutexInterface.

Definition at line 74 of file LockMgrImpl.h.

References dmutex_, g_multi_instance, mutex_, and ref_count_.

74  {
75  ref_count_.fetch_add(1u);
76  if (!g_multi_instance) {
77  mutex_.lock_shared();
78  } else {
79  dmutex_->lock_shared();
80  }
81  }
MutexTypeBase mutex_
Definition: LockMgrImpl.h:107
bool g_multi_instance
Definition: heavyai_locks.h:21
std::unique_ptr< heavyai::DistributedSharedMutex > dmutex_
Definition: LockMgrImpl.h:108
std::atomic< size_t > ref_count_
Definition: LockMgrImpl.h:106
virtual bool lockmgr::MutexTracker::try_lock ( )
inlinevirtual

Implements heavyai::MutexInterface.

Definition at line 53 of file LockMgrImpl.h.

References dmutex_, g_multi_instance, mutex_, and ref_count_.

53  {
54  bool gotlock{false};
55  if (!g_multi_instance) {
56  gotlock = mutex_.try_lock();
57  } else {
58  gotlock = dmutex_->try_lock();
59  }
60  if (gotlock) {
61  ref_count_.fetch_add(1u);
62  }
63  return gotlock;
64  }
MutexTypeBase mutex_
Definition: LockMgrImpl.h:107
bool g_multi_instance
Definition: heavyai_locks.h:21
std::unique_ptr< heavyai::DistributedSharedMutex > dmutex_
Definition: LockMgrImpl.h:108
std::atomic< size_t > ref_count_
Definition: LockMgrImpl.h:106
virtual bool lockmgr::MutexTracker::try_lock_shared ( )
inlinevirtual

Implements heavyai::SharedMutexInterface.

Definition at line 82 of file LockMgrImpl.h.

References dmutex_, g_multi_instance, mutex_, and ref_count_.

82  {
83  bool gotlock{false};
84  if (!g_multi_instance) {
85  gotlock = mutex_.try_lock_shared();
86  } else {
87  gotlock = dmutex_->try_lock_shared();
88  }
89  if (gotlock) {
90  ref_count_.fetch_add(1u);
91  }
92  return gotlock;
93  }
MutexTypeBase mutex_
Definition: LockMgrImpl.h:107
bool g_multi_instance
Definition: heavyai_locks.h:21
std::unique_ptr< heavyai::DistributedSharedMutex > dmutex_
Definition: LockMgrImpl.h:108
std::atomic< size_t > ref_count_
Definition: LockMgrImpl.h:106
virtual void lockmgr::MutexTracker::unlock ( )
inlinevirtual

Implements heavyai::MutexInterface.

Definition at line 65 of file LockMgrImpl.h.

References dmutex_, g_multi_instance, mutex_, and ref_count_.

65  {
66  if (!g_multi_instance) {
67  mutex_.unlock();
68  } else {
69  dmutex_->unlock();
70  }
71  ref_count_.fetch_sub(1u);
72  }
MutexTypeBase mutex_
Definition: LockMgrImpl.h:107
bool g_multi_instance
Definition: heavyai_locks.h:21
std::unique_ptr< heavyai::DistributedSharedMutex > dmutex_
Definition: LockMgrImpl.h:108
std::atomic< size_t > ref_count_
Definition: LockMgrImpl.h:106
virtual void lockmgr::MutexTracker::unlock_shared ( )
inlinevirtual

Implements heavyai::SharedMutexInterface.

Definition at line 94 of file LockMgrImpl.h.

References dmutex_, g_multi_instance, mutex_, and ref_count_.

94  {
95  if (!g_multi_instance) {
96  mutex_.unlock_shared();
97  } else {
98  dmutex_->unlock_shared();
99  }
100  ref_count_.fetch_sub(1u);
101  }
MutexTypeBase mutex_
Definition: LockMgrImpl.h:107
bool g_multi_instance
Definition: heavyai_locks.h:21
std::unique_ptr< heavyai::DistributedSharedMutex > dmutex_
Definition: LockMgrImpl.h:108
std::atomic< size_t > ref_count_
Definition: LockMgrImpl.h:106

Member Data Documentation

std::unique_ptr<heavyai::DistributedSharedMutex> lockmgr::MutexTracker::dmutex_
private

Definition at line 108 of file LockMgrImpl.h.

Referenced by lock(), lock_shared(), try_lock(), try_lock_shared(), unlock(), and unlock_shared().

MutexTypeBase lockmgr::MutexTracker::mutex_
private

Definition at line 107 of file LockMgrImpl.h.

Referenced by lock(), lock_shared(), try_lock(), try_lock_shared(), unlock(), and unlock_shared().

std::atomic<size_t> lockmgr::MutexTracker::ref_count_
private

The documentation for this class was generated from the following file: