Newer
Older
#ifndef __VEREIGN_KVSTORE_LOCK_HH
#define __VEREIGN_KVSTORE_LOCK_HH
#include <vereign/kvstore/storage.hh>
#include <chrono>
namespace vereign::kvstore {
/**
* Lock guard used for lock/unlock Storage within a scope.
*
* When the Lock is constructed it locks the Storage, and when it is destroyed it unlock it.
*/
/**
* Creates a Lock and locks the Storage.
*
* @param storage The storage to lock.
* @throws LockError when the lock is held by another process.
*/
/**
* Creates a Lock and locks the Storage.
*
* If the lock is not possible it retries `retry_count` and sleeps between retries `sleep_interval`.
*
* @param storage The storage to lock.
* @param retry_count How many times to retry if the lock is held by another process.
* @param sleep_interval How many time to sleep between retries.
*
* @throws LockError If the lock could not be held after `retry_count` retries.
*/
Lock(Storage& storage, int retry_count, std::chrono::milliseconds sleep_interval);