Template Struct lock_policy
Defined in File lock_policy.h
Struct Documentation
-
template<typename mutexT, typename lockT>
struct lock_policy Do you want to write code that may or may not require concurrent access and need lock based synchronization? Lock policies are for you.
Are you not sure if your code should own/hold a lock, or you need a shared lock? The shared_lock_policy can be combined with other lock policies to meet your needs.
A lock policy is a simple struct that defines a mutex_type and a lock_type. The only requirement on the mutex_type is that it defines a lock() and an unlock() function. The only requirement on the lock_type is that it takes a mutex_type reference in the constructor and calls its lock() function, and in the destructor calls it’s unlock() function.
This follows the basic pattern of scoped locks as you might know them from boost and modern C++. No other patterns are supported to keep things simple, such as timed locks or temporarily unlocking, etc.
The null_lock_policy defines types that do nothing. Use this when you want to specialize your code to not perform synchronization.
The lock_policy type also defines a mutex_type and a lock_type, but in doing so resolves whether mutexT is a raw or smart pointer.
If mutexT is a mutex type, lock_type becomes lockT.
If mutexT is a raw or smart pointer to a mutex type, lock_type becomes a proxy that dereferences its argument before passing it on to an internal lockT instance.
Resolves whether mutexT is a raw or smart pointer, and uses a proxy if so. Otherwise uses a the regular lockT.