YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
recursive_mutex.cpp
Go to the documentation of this file.
1
2
#include <
yaclib/fault/detail/fiber/recursive_mutex.hpp
>
3
4
namespace
yaclib::detail::fiber
{
5
6
void
RecursiveMutex::lock
() {
7
if
(
_occupied_count
!= 0 &&
_owner_id
!=
fault::Scheduler::GetId
()) {
8
_queue
.
Wait
(
NoTimeoutTag
{});
9
}
10
LockHelper
();
11
}
12
13
bool
RecursiveMutex::try_lock
()
noexcept
{
14
if
(
_occupied_count
!= 0 &&
_owner_id
!=
fault::Scheduler::GetId
()) {
15
return
false
;
16
}
17
LockHelper
();
18
return
true
;
19
}
20
21
void
RecursiveMutex::unlock
()
noexcept
{
22
YACLIB_DEBUG
(
_occupied_count
== 0,
"unlock on not locked recursive mutex"
);
23
_occupied_count
--;
24
if
(
_occupied_count
== 0) {
25
_owner_id
= 0;
26
}
27
}
28
void
RecursiveMutex::LockHelper
() {
29
_occupied_count
++;
30
_owner_id
=
fault::Scheduler::GetId
();
31
}
32
33
RecursiveMutex::native_handle_type
RecursiveMutex::native_handle
() {
34
return
nullptr
;
35
}
36
37
}
// namespace yaclib::detail::fiber
yaclib::detail::fiber::FiberQueue::Wait
WaitStatus Wait(NoTimeoutTag)
Definition
queue.cpp:5
yaclib::detail::fiber::RecursiveMutex::LockHelper
void LockHelper()
Definition
recursive_mutex.cpp:28
yaclib::detail::fiber::RecursiveMutex::_owner_id
FiberBase::Id _owner_id
Definition
recursive_mutex.hpp:27
yaclib::detail::fiber::RecursiveMutex::_occupied_count
std::uint32_t _occupied_count
Definition
recursive_mutex.hpp:28
yaclib::detail::fiber::RecursiveMutex::try_lock
bool try_lock() noexcept
Definition
recursive_mutex.cpp:13
yaclib::detail::fiber::RecursiveMutex::native_handle
native_handle_type native_handle()
Definition
recursive_mutex.cpp:33
yaclib::detail::fiber::RecursiveMutex::unlock
void unlock() noexcept
Definition
recursive_mutex.cpp:21
yaclib::detail::fiber::RecursiveMutex::lock
void lock()
Definition
recursive_mutex.cpp:6
yaclib::detail::fiber::RecursiveMutex::native_handle_type
void * native_handle_type
Definition
recursive_mutex.hpp:19
yaclib::detail::fiber::RecursiveMutex::_queue
FiberQueue _queue
Definition
recursive_mutex.hpp:26
yaclib::fault::Scheduler::GetId
static detail::fiber::FiberBase::Id GetId()
Definition
scheduler.cpp:52
recursive_mutex.hpp
YACLIB_DEBUG
#define YACLIB_DEBUG(cond, message)
Definition
log.hpp:84
yaclib::detail::fiber
Definition
atomic.hpp:7
yaclib::MakeContract
Contract< V, E > MakeContract()
Creates related future and promise.
Definition
contract.hpp:25
yaclib::detail::fiber::NoTimeoutTag
Definition
queue.hpp:12
src
fault
fiber
recursive_mutex.cpp
Generated by
1.9.8