3 #ifndef __CDS_LOCK_SCOPED_LOCK_H
4 #define __CDS_LOCK_SCOPED_LOCK_H
6 #include <cds/details/defs.h>
7 #include <cds/details/noncopyable.h>
9 namespace cds { namespace lock {
14 An object of type \p scoped_lock controls the ownership of a lockable object within a scope.
15 A \p scoped_lock object maintains ownership of a lockable object throughout the \p scoped_lock object
\92s lifetime.
16 The behavior of a program is undefined if the lockable object does not exist for the entire lifetime
17 of the \p scoped_lock object.
18 The supplied \p Lock type shall have two methods: \p lock and \p unlock.
20 The constructor locks the wrapped lock object, the destructor unlocks it.
22 Scoped lock is not copy-constructible and not default-constructible.
24 This class is similar to \p std::lock_quard
27 class scoped_lock: public cds::details::noncopyable
30 typedef Lock lock_type ; ///< Lock type
33 lock_type& m_Lock ; ///< Owned lock object
37 // Only for internal use!!!
42 /// Get ownership of lock object \p l and calls <tt>l.lock()</tt>
43 scoped_lock( lock_type& l )
49 /// Get ownership of lock object \p l and conditionally locks it
51 The constructor calls <tt>l.lock()</tt> only if \p bAlreadyLocked is \p false.
52 If \p bAlreadyLocked is \p true, no locking is performed.
54 In any case, the destructor of \p scoped_lock object invokes <tt>l.unlock()</tt>.
56 scoped_lock( lock_type& l, bool bAlreadyLocked )
59 if ( !bAlreadyLocked )
63 /// Unlock underlying lock object and release ownership
69 }} // namespace cds::lock
72 #endif // #ifndef __CDS_LOCK_SCOPED_LOCK_H