Android-cuttlefish cvd tool
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
cuttlefish::DataViewer Class Reference

#include <data_viewer.h>

Collaboration diagram for cuttlefish::DataViewer:
Collaboration graph
[legend]

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< SharedFDLockBackingFile (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_
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ DataViewer()

cuttlefish::DataViewer::DataViewer ( const std::string &  backing_file)
inline

Member Function Documentation

◆ LoadData()

Result< cvd::PersistentData > cuttlefish::DataViewer::LoadData ( SharedFD  fd) const
private

◆ LockBackingFile()

Result< SharedFD > cuttlefish::DataViewer::LockBackingFile ( int  op) const
private

◆ StoreData()

Result< void > cuttlefish::DataViewer::StoreData ( SharedFD  fd,
cvd::PersistentData  data 
)
private

◆ WithExclusiveLock()

template<typename R >
Result< R > cuttlefish::DataViewer::WithExclusiveLock ( std::function< Result< R >(cvd::PersistentData &)>  task)
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.

◆ WithSharedLock()

template<typename R >
Result< R > cuttlefish::DataViewer::WithSharedLock ( std::function< Result< R >(const cvd::PersistentData &)>  task) const
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.

Member Data Documentation

◆ backing_file_

std::string cuttlefish::DataViewer::backing_file_
private

◆ lock_held_by_

std::unordered_map<std::thread::id, bool> cuttlefish::DataViewer::lock_held_by_
mutableprivate

◆ lock_map_mtx_

std::mutex cuttlefish::DataViewer::lock_map_mtx_
mutableprivate

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