51 std::recursive_timed_mutex m_mtx_lock;
53 std::thread::id m_owner_id;
57 : m_lock_count(0), m_owner_id() { }
62 bool isOwner(std::thread::id
id)
const noexcept {
return id == m_owner_id; }
63 bool isOwner() const noexcept {
return std::this_thread::get_id() == m_owner_id; }
80 if( 1 == ++m_lock_count ) {
81 m_owner_id = std::this_thread::get_id();
93 bool overflow =
false;
95 std::chrono::duration<int64_t, std::nano> d = timeout.to_duration(std::chrono::nanoseconds::zero(), &overflow);
99 auto timeout_time = std::chrono::steady_clock::now() + d;
101 if( m_mtx_lock.try_lock_until(timeout_time) ) {
102 if( 1 == ++m_lock_count ) {
103 m_owner_id = std::this_thread::get_id();
112 std::thread::id
id = std::this_thread::get_id();
129 if( 0 < --m_lock_count ) {
133 if(
nullptr != taskBeforeUnlock ) {
136 m_owner_id = std::thread::id();
141 return "RL[count " + std::to_string(m_lock_count.load()) +
", owner " +
threadName(m_owner_id) +
"]";
void lock()
Acquire this lock indefinitely (no timeout)
void operator=(const RecursiveLock &)=delete
RecursiveLock(const RecursiveLock &)=delete
bool tryLock(const fraction_i64 &timeout)
Try to acquire this lock within given timeout in seconds.
std::string toString() const
nsize_t holdCount() noexcept
Return the number of locks issued to this lock by the same thread.
bool isOwner() const noexcept
void unlock(callback_func taskBeforeUnlock=nullptr)
Unlock ...
void validateLocked() const
bool isOwner(std::thread::id id) const noexcept
void(* callback_func)() noexcept
ordered_atomic< jau::nsize_t, std::memory_order_relaxed > relaxed_atomic_nsize_t
Relaxed non-SC atomic integral scalar jau::nsize_t.
fraction< int64_t > fraction_i64
fraction using int64_t as integral type
uint_fast32_t nsize_t
Natural 'size_t' alternative using uint_fast32_t as its natural sized type.
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
std::string threadName(const std::thread::id id) noexcept