holoscan::FileFIFOMutex

Beta
View as Markdown

A class that implements a file-based FIFO mutex.

This class implements a file-based mutex that can be used to synchronize multiple processes. It uses a lock file to synchronize the processes and a queue file to store the process IDs of the processes that are waiting to acquire the lock.

#include <holoscan/file_fifo_mutex.hpp>

Constructors

FileFIFOMutex

holoscan::FileFIFOMutex::FileFIFOMutex(holoscan::FileFIFOMutex::FileFIFOMutex(
std::string file_path
)

Constructs a new file-backed mutex at the given path and a queue file at file_path.queue, if not already present.

It also opens both the files.

Parameters

file_path
std::string

The path to the mutex file.

Destructor

~FileFIFOMutex

holoscan::FileFIFOMutex::~FileFIFOMutex()holoscan::FileFIFOMutex::~FileFIFOMutex()

Unlocks the mutex if it was locked.

Closes the queue and lock files.


Assignment operators

operator=

FileFIFOMutex & holoscan::FileFIFOMutex::operator=(FileFIFOMutex & holoscan::FileFIFOMutex::operator=(
const FileFIFOMutex &
) = delete

Methods

set_wait_time_ms

void holoscan::FileFIFOMutex::set_wait_time_ms(
int wait_time_ms
)

Sets the wait time for the lock.

The wait time is applied when the queue file is being locked. If the queue file is not available for lock within the wait time, then the lock is not acquired. If the wait time is less than or equal to 0, then it blocks until the lock is acquired.

Parameters

wait_time_ms
int

The wait time in milliseconds.

lock

void holoscan::FileFIFOMutex::lock()

Locks the mutex after writing the current process’ PID to the queue.

Waits for the queue file to be unlocked to write its own PID to the queue, depending on the wait time.

unlock

void holoscan::FileFIFOMutex::unlock()

Unlocks the mutex by removing itself from the queue and unlocking the mutex.

locked

bool holoscan::FileFIFOMutex::locked() const

Returns true if the mutex is locked.

Returns: false When the mutex is not locked.


Member variables

NameTypeDescription
main_lock_std::unique_ptr< ScopedFlock >
fd_int
queue_fd_int
pid_pid_t
locked_bool
wait_time_ms_int