fairness  v1.0.0
A collection of advanced syncronization mechanisms.
Loading...
Searching...
No Matches
control_block_t.hpp
Go to the documentation of this file.
1
13#ifndef BOOST_FAIRNESS_CONTROL_BLOCK_T_HPP
14#define BOOST_FAIRNESS_CONTROL_BLOCK_T_HPP
17#include <atomic>
18
19namespace boost::fairness{
20
21
23
24 #define LOCK_OWNED 1
25 #define LOCK_NOT_OWNED 0
26
29
31 control_block_64b_simple_t new_ctrl = *this;
32 new_ctrl.owned_ = LOCK_OWNED;
33 return new_ctrl;
34 }
35
37 control_block_64b_simple_t new_ctrl = *this;
38 new_ctrl.priority_ = priority;
39 return new_ctrl;
40 }
41
43 return priority_;
44 }
45
46 bool isOwned() const{
47 return owned_ == LOCK_OWNED;
48 }
49
50 #undef LOCK_OWNED
51 #undef LOCK_NOT_OWNED
52 };
53
54 static_assert(std::atomic<control_block_64b_simple_t>::is_always_lock_free, "control_block_64b_simple_t is not lock free");
55
56
61 struct control_block_64b_t{
66 int8_t owned_ = 7;
71 uint8_t priority_[7];
77 control_block_64b_t setOwned() const {
78 control_block_64b_t new_ctrl = *this;
79 new_ctrl.owned_ |= 0b10000000;
80 return new_ctrl;
81 }
88 control_block_64b_t increasePriority(Priority_t const priority) const {
89 control_block_64b_t new_ctrl = *this;
90 ++new_ctrl.priority_[priority];
91 return new_ctrl;
92 }
99 control_block_64b_t decreasePriority(Priority_t const priority) const {
100 control_block_64b_t new_ctrl = *this;
101 --new_ctrl.priority_[priority];
102 return new_ctrl;
103 }
110 control_block_64b_t setPriority(Priority_t const priority) const {
111 control_block_64b_t new_ctrl = *this;
112 new_ctrl.owned_ = priority;
113 return new_ctrl;
114 }
120 Priority_t getPriority() const {
121 return owned_ & 0b01111111;
122 }
129 bool isOwned_() const{
130 return owned_ < 0;
131 }
132 };
133
134 #define BOOST_FAIRNESS_SPM64B_SUPPORTED_PRIORITIES sizeof(control_block_64b_t::priority_)
135
136 static_assert(std::atomic<control_block_64b_t>::is_always_lock_free, "control_block64b_t is not lock free");
137
138 #ifdef BOOST_FAIRNESS_HAS_DWCAS
139
140 struct control_block_128b_t{
145 int8_t owned_ = 15;// first bit owned remaining 7 bit is the current priority
150 uint8_t priority_[15];
155 control_block_128b_t setOwned() const {
156 control_block_128b_t new_ctrl = *this;
157 new_ctrl.owned_ |= 0b10000000;
158 return new_ctrl;
159 }
164 control_block_128b_t increasePriority(Priority_t const priority) const {
165 control_block_128b_t new_ctrl = *this;
166 ++new_ctrl.priority_[priority];
167 return new_ctrl;
168 }
173 control_block_128b_t decreasePriority(Priority_t const priority) const {
174 control_block_128b_t new_ctrl = *this;
175 --new_ctrl.priority_[priority];
176 return new_ctrl;
177 }
182 control_block_128b_t setPriority(Priority_t const priority) const {
183 control_block_128b_t new_ctrl = *this;
184 new_ctrl.owned_ = priority;
185 return new_ctrl;
186 }
191 Priority_t getPriority() const {
192 return owned_ & 0b01111111;
193 }
198 bool isOwned_() const{
199 return owned_ < 0;
200 }
201 };
202 #define BOOST_FAIRNESS_SPM128B_SUPPORTED_PRIORITIES sizeof(control_block_128b_t::priority_)
203
204 static_assert(boost::atomic<control_block_128b_t>::is_always_lock_free, "control_block128b_t is not lock free");
205
206 #endif // BOOST_FAIRNESS_HAS_DWCAS
207
208} // namespace boost::fairness
209
210#endif // BOOST_FAIRNESS_CONTROL_BLOCK_T_HPP
This file contains configurations about boost and 128bit cpu support. TODO.
#define LOCK_NOT_OWNED
Definition control_block_t.hpp:25
#define LOCK_OWNED
Definition control_block_t.hpp:24
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
Definition control_block_t.hpp:22
control_block_64b_simple_t setPriority(Priority_t const priority) const
Definition control_block_t.hpp:36
uint32_t owned_
Definition control_block_t.hpp:27
Priority_t getPriority() const
Definition control_block_t.hpp:42
bool isOwned() const
Definition control_block_t.hpp:46
control_block_64b_simple_t setOwned() const
Definition control_block_t.hpp:30
uint32_t priority_
Definition control_block_t.hpp:28