iox::posix::FileLock🔗
Posix file lock C++ wrapping class Following RAII, the lock is acquired on creation and released on destruction. Releasing the locks works even if the process crashes with a segfault or using SIGKILL. 'lslocks' can be used to display all system-wide locks (see man page) More...
#include <iceoryx_hoofs/posix_wrapper/file_lock.hpp>
Inherits from DesignPattern::Creation< FileLock, FileLockError >
Public Types🔗
Name | |
---|---|
using cxx::string< FILENAME_LENGTH > | FileName_t |
using cxx::string< platform::IOX_MAX_PATH_LENGTH > | PathName_t |
Public Functions🔗
Name | |
---|---|
FileLock(const FileLock & ) | |
FileLock & | operator=(const FileLock & ) |
FileLock(FileLock && rhs) | |
FileLock & | operator=(FileLock && rhs) |
~FileLock() |
Public Attributes🔗
Name | |
---|---|
constexpr int32_t | ERROR_CODE |
constexpr int32_t | INVALID_FD |
constexpr const char | LOCK_FILE_SUFFIX |
constexpr uint64_t | FILENAME_LENGTH |
Friends🔗
Name | |
---|---|
class | DesignPattern::Creation< FileLock, FileLockError > |
Additional inherited members🔗
Public Types inherited from DesignPattern::Creation< FileLock, FileLockError >
Name | |
---|---|
using Creation< DerivedClass, ErrorType > | CreationPattern_t |
using iox::cxx::expected< DerivedClass, ErrorType > | result_t |
using ErrorType | errorType_t |
Public Functions inherited from DesignPattern::Creation< FileLock, FileLockError >
Name | |
---|---|
template <typename... Targs> result_t |
create(Targs &&... args) factory method which guarantees that either a working object is produced or an error value describing the error during construction |
result_t | verify(DerivedClass && newObject) verifies if a class was created successfully |
template <typename... Targs> iox::cxx::expected< ErrorType > |
placementCreate(void *const memory, Targs &&... args) factory method which guarantees that either a working object is produced or an error value describing the error during construction |
Creation() =default | |
Creation(Creation && rhs) | |
Creation(const Creation & rhs) =default | |
bool | isInitialized() const returns true if the object was constructed successfully, otherwise false |
Protected Attributes inherited from DesignPattern::Creation< FileLock, FileLockError >
Name | |
---|---|
bool | m_isInitialized |
ErrorType | m_errorValue |
Detailed Description🔗
class iox::posix::FileLock;
Posix file lock C++ wrapping class Following RAII, the lock is acquired on creation and released on destruction. Releasing the locks works even if the process crashes with a segfault or using SIGKILL. 'lslocks' can be used to display all system-wide locks (see man page)
iox::posix::FileLock::create(nameOfmyLock)
.and_then([] { std::cout << "We aquired the lock!" << std::endl; })
.or_else([](auto& error) {
if (error == FileLockError::LOCKED_BY_OTHER_PROCESS)
{
std::cout << "Some other process is running and holds the lock!" << std::endl;
}
});
Public Types Documentation🔗
using FileName_t🔗
using iox::posix::FileLock::FileName_t = cxx::string<FILENAME_LENGTH>;
using PathName_t🔗
using iox::posix::FileLock::PathName_t = cxx::string<platform::IOX_MAX_PATH_LENGTH>;
Public Functions Documentation🔗
function FileLock🔗
FileLock(
const FileLock &
)
function operator=🔗
FileLock & operator=(
const FileLock &
)
function FileLock🔗
FileLock(
FileLock && rhs
)
function operator=🔗
FileLock & operator=(
FileLock && rhs
)
function ~FileLock🔗
~FileLock()
Public Attributes Documentation🔗
variable ERROR_CODE🔗
static constexpr int32_t ERROR_CODE = -1;
variable INVALID_FD🔗
static constexpr int32_t INVALID_FD = -1;
variable LOCK_FILE_SUFFIX🔗
static constexpr const char LOCK_FILE_SUFFIX = ".lock";
variable FILENAME_LENGTH🔗
static constexpr uint64_t FILENAME_LENGTH = platform::IOX_MAX_FILENAME_LENGTH
- sizeof(platform::IOX_LOCK_FILE_PATH_PREFIX) / sizeof(char)
- sizeof(LOCK_FILE_SUFFIX) / sizeof(char);
Friends🔗
friend DesignPattern::Creation< FileLock, FileLockError >🔗
friend class DesignPattern::Creation< FileLock, FileLockError >;
Updated on 18 December 2023 at 13:11:42 CET