Android-cuttlefish cvd tool
|
#include <data_viewer.h>
Classes | |
class | DeadlockProtector |
Public Member Functions | |
DataViewer (const std::string &backing_file) | |
template<typename R > | |
Result< R > | WithSharedLock (std::function< Result< R >(const cvd::PersistentData &)> task) const |
template<typename R > | |
Result< R > | WithExclusiveLock (std::function< Result< R >(cvd::PersistentData &)> task) |
Private Member Functions | |
Result< SharedFD > | LockBackingFile (int op) const |
Result< cvd::PersistentData > | LoadData (SharedFD fd) const |
Result< void > | StoreData (SharedFD fd, cvd::PersistentData data) |
Private Attributes | |
std::mutex | lock_map_mtx_ |
std::unordered_map< std::thread::id, bool > | lock_held_by_ |
std::string | backing_file_ |
Synchronizes loading and storing the instance database from and to a file.
Guarantees atomic access to the information stored in the backing file at the cost of high lock contention.
|
inline |
|
inline |
Provides read-write access to the data while holding an exclusive lock.
This function may block until the lock can be acquired. Others can't access the data concurrently with this one. Any changes to the data will be persisted to the file when the task functor returns successfully, no changes to the backed data occur if an error is returned.
|
inline |
Provides read-only access to the data while holding a shared lock.
This function may block until the lock can be acquired. Others can access the data in read-only mode concurrently, but write access is blocked at least until this function returns.
|
private |
|
mutableprivate |
|
mutableprivate |