pmem::obj::mutex Class Reference

Persistent memory resident mutex implementation. More...

`#include <libpmemobj++/mutex.hpp>`

## Public Types

typedef PMEMmutex * | native_handle_type
| Implementation defined handle to the native type. More...

## Public Member Functions

| mutex ()
| Default constructor. More...
| ~mutex ()=default
| Defaulted destructor.
void | lock ()
| Locks the mutex, blocks if already locked. More...
bool | try_lock ()
| Tries to lock the mutex, returns regardless if the lock succeeds. More...
void | unlock ()
| Unlocks a previously locked mutex. More...
native_handle_type | native_handle () noexcept
| Access a native handle to this condition variable. More...
enum pobj_tx_param | lock_type () const noexcept
| The type of lock needed for the transaction API. More...
mutex & | operator= (const mutex &)=delete
| Deleted assignment operator.
| mutex (const mutex &)=delete
| Deleted copy constructor.

## Private Attributes

PMEMmutex | plock
| A POSIX style PMEM-resident mutex. More...

## Detailed Description

Persistent memory resident mutex implementation.

This class is an implementation of a PMEM-resident mutex which mimics in behavior the C++11 std::mutex. This class satisfies all requirements of the Mutex and StandardLayoutType concepts. The typical usage example would be:

#include <libpmemobj++/mutex.hpp>
#include <libpmemobj++/persistent_ptr.hpp>
#include <libpmemobj++/pool.hpp>
#include <mutex>
namespace nvobj = pmem::obj;
void
unique_guard_example()
{
// pool root structure
struct root {
nvobj::mutex pmutex;
};
// create a pmemobj pool
auto pop = nvobj::pool<root>::create("poolfile", "layout",
PMEMOBJ_MIN_POOL);
auto proot = pop.get_root();
// typical usage schemes
std::lock_guard<nvobj::mutex> guard(proot->pmutex);
std::unique_lock<nvobj::mutex> other_guard(proot->pmutex);
}

## Member Typedef Documentation

## native_handle_type

typedef PMEMmutex* pmem::obj::mutex::native_handle_type

Implementation defined handle to the native type.

## Constructor & Destructor Documentation

## mutex()

pmem::obj::mutex::mutex | ( |  | ) |

inline

Default constructor.

Exceptions

  lock_error | when the mutex is not from persistent memory.

## Member Function Documentation

## lock()

void pmem::obj::mutex::lock | ( |  | ) |

inline

Locks the mutex, blocks if already locked.

If a different thread already locked this mutex, the calling thread will block. If the same thread tries to lock a mutex it already owns, the behavior is undefined.

Exceptions

  lock_error | when an error occurs, this includes all system related errors with the underlying implementation of the mutex.

## lock_type()

enum pobj_tx_param pmem::obj::mutex::lock_type | ( |  | ) | const

inline noexcept

The type of lock needed for the transaction API.

Returns
  TX_PARAM_MUTEX

## native_handle()

native_handle_type pmem::obj::mutex::native_handle | ( |  | ) |

inline noexcept

Access a native handle to this condition variable.

Returns
  a pointer to PMEMmutex.

## try_lock()

bool pmem::obj::mutex::try_lock | ( |  | ) |

inline

Tries to lock the mutex, returns regardless if the lock succeeds.

If the same thread tries to lock a mutex it already owns, the behavior is undefined.

Returns
  `true` on successful lock acquisition, `false` otherwise.

Exceptions

  lock_error | when an error occurs, this includes all system related errors with the underlying implementation of the mutex.

## unlock()

void pmem::obj::mutex::unlock | ( |  | ) |

inline

Unlocks a previously locked mutex.

Unlocking a mutex that has not been locked by the current thread results in undefined behavior. Unlocking a mutex that has not been lock also results in undefined behavior.

## Member Data Documentation

## plock

PMEMmutex pmem::obj::mutex::plock

private

A POSIX style PMEM-resident mutex.

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

- pmdk-1.4.1/src/include/libpmemobj++/mutex.hpp