13#ifndef BOOST_FAIRNESS_SPINLOCK_PRIORITY_MUTEX_TATAS_HPP
14#define BOOST_FAIRNESS_SPINLOCK_PRIORITY_MUTEX_TATAS_HPP
27 template<
size_t N = 1>
29 class spinlock_priority_mutex{
31 using Thread_cnt_t = uint32_t;
36 spinlock_priority_mutex() =
default;
39 spinlock_priority_mutex(
const spinlock_priority_mutex&) =
delete;
42 spinlock_priority_mutex& operator=(
const spinlock_priority_mutex&) =
delete;
45 spinlock_priority_mutex(spinlock_priority_mutex&&) =
delete;
48 spinlock_priority_mutex& operator=(spinlock_priority_mutex&&) =
delete;
51 ~spinlock_priority_mutex() =
default;
70 bool localLockOwned = lockOwned_.test(std::memory_order_relaxed);
72 Priority_t localCurrentPriority = currentPriority_.load(std::memory_order_relaxed);
74 waiters_[priority].fetch_add(1, std::memory_order_relaxed);
78 if (!localLockOwned & (localCurrentPriority >= priority)){
79 if (!lockOwned_.test_and_set(std::memory_order_acquire))
83 localLockOwned = lockOwned_.test(std::memory_order_relaxed);
84 localCurrentPriority = currentPriority_.load(std::memory_order_relaxed);
88 waiters_[priority].fetch_sub(1, std::memory_order_relaxed);
106 currentPriority_.store(find_first_priority_(), std::memory_order_relaxed);
107 lockOwned_.clear(std::memory_order_release);
127 return (currentPriority_.load(std::memory_order_relaxed) >= priority && !lockOwned_.test_and_set(std::memory_order_acquire));
void lock(Priority_t const priority=0)
Try to acquire the unique ownership of the spinlock_priority_mutex, blocking the thread if the spinlo...
Definition spinlock_priority_mutex_tatas.hpp:68
bool try_lock(Priority_t const priority=0)
Try to acquire the unique ownership of the spinlock_priority_mutex, if successful will return true,...
Definition spinlock_priority_mutex_tatas.hpp:126
void unlock()
Release the spinlock_priority_mutex from unique ownership.
Definition spinlock_priority_mutex_tatas.hpp:105
#define BOOST_FAIRNESS_HARDWARE_DESTRUCTIVE_SIZE
Size to be aligned to avoid false sharing
Definition config.hpp:85
void spin_wait() noexcept
Definition wait_ops.hpp:56
Definition acquisition_modes.hpp:16
uint8_t Priority_t
Definition priority_t.hpp:17
Alias the type Priority_t. Priority_t is the type of priorities that are used by the priority_mutexes...
#define BOOST_FAIRNESS_MAXIMUM_PRIORITY
Priorities are indexes in an array, that means that if I define a priority_mutex<BOOST_FAIRNESS_MAXIM...
Definition priority_t.hpp:24
This file contains the implementation of the wait operations used by the mutexes.