CatapultServer  v0.5.0.1 (Elephant)
FileLock.h
Go to the documentation of this file.
1 
21 #pragma once
24 #include <string>
25 
26 namespace catapult { namespace io {
27 
29  class FileLock : public utils::NonCopyable {
30  public:
33 #ifdef _MSC_VER
34  using FdType = void*;
35 #else
36  using FdType = int;
37 #endif
38 
39  public:
41  explicit FileLock(const std::string& lockFilePath);
42 
44  ~FileLock();
45 
46  public:
48  void lock();
49 
51  bool try_lock();
52 
54  void unlock() noexcept;
55 
56  private:
57  std::string m_lockFilePath;
58  utils::SpinLock m_spinLock;
60  };
61 }}
catapult::io::FileLock::lock
void lock()
Blocks until a lock can be obtained for the current execution agent.
Definition: FileLock.cpp:100
CATAPULT_LOG
#define CATAPULT_LOG(SEV)
Writes a log entry to the default logger with SEV severity.
Definition: Logging.h:340
SpinLock.h
colorPrint.warning
def warning(*args)
Definition: colorPrint.py:10
catapult::io::FileLock::m_spinLock
utils::SpinLock m_spinLock
Definition: FileLock.h:58
catapult::io::FileLock::m_lockFilePath
std::string m_lockFilePath
Definition: FileLock.h:57
FileLock.h
catapult::io::FileLock
Lock based on an underlying lock file.
Definition: FileLock.h:29
catapult::io::FdType
FileLock::FdType FdType
Definition: FileLock.cpp:35
catapult::utils::SpinLock::try_lock
bool try_lock()
Attempts to acquire the lock for the current execution agent without blocking.
Definition: SpinLock.h:46
catapult::io::FileLock::~FileLock
~FileLock()
Releases the lock file.
Definition: FileLock.cpp:96
catapult::utils::SpinLock::unlock
void unlock() noexcept
Releases the lock held by the execution agent. Throws no exceptions.
Definition: SpinLock.h:51
catapult::io::FileLock::FdType
int FdType
Definition: FileLock.h:36
catapult::io::FileLock::m_fd
FdType m_fd
Definition: FileLock.h:59
catapult::io::FileLock::try_lock
bool try_lock()
Attempts to acquire the lock for the current execution agent without blocking.
Definition: FileLock.cpp:105
catapult
Definition: AddressExtractionExtension.cpp:28
Logging.h
catapult::utils::NonCopyable
A class that can neither be copied nor moved.
Definition: NonCopyable.h:26
catapult::io::FileLock::unlock
void unlock() noexcept
Releases the lock held by the execution agent. Throws no exceptions.
Definition: FileLock.cpp:114
catapult::utils::SpinLockGuard
std::lock_guard< SpinLock > SpinLockGuard
A spin lock guard.
Definition: SpinLock.h:60
catapult::io::FileLock::FileLock
FileLock(const std::string &lockFilePath)
Creates a lock file with path lockFilePath.
Definition: FileLock.cpp:91
NonCopyable.h