fairness  v1.0.0
A collection of advanced syncronization mechanisms.
Loading...
Searching...
No Matches
pqlock.hpp
Go to the documentation of this file.
1
13#ifndef BOOST_FAIRNESS_PQLOCK_HPP
14#define BOOST_FAIRNESS_PQLOCK_HPP
15
16#include <exception>
22
24
25 class pqlock{
26
27 public:
28
30 pqlock() {
31 cpl_.initialize(reqs_.getRequest());
32 };
33
35 pqlock(const pqlock&) = delete;
36
38 pqlock& operator=(const pqlock&) = delete;
39
41 pqlock(pqlock&&) = delete;
42
44 pqlock& operator=(pqlock&&) = delete;
45
47 ~pqlock() = default;
48
49 void lock(Priority_t const priority = 0){
50 Request* req;
51
52 Thread* t = t_.getThread(this);
53
54 if (t == nullptr)
55 throw std::logic_error("Thread Pool returned a nullptr: Increase BOOST_FAIRNESS_MAX_THREADS");
56
57 for(;;){
58 req = reqs_.getRequest();
59 if (req != nullptr)
60 break;
61 std::this_thread::yield(); // there are no free Requests now just yield
62 }
63 t->prepare(priority, req);
64 cpl_.requestLock(t);
65 }
66
67 void unlock(){
68 Thread* t = t_.reGetThread(this);
69 cpl_.grantLock(t);
70 reqs_.returnRequest(t->watch_);
71 t_.returnThread(t);
72 }
73
74 /* The try_lock for the Craig algorithm will be implemented in a future update.
75
76 [[nodiscard]] bool try_lock(Priority_t const priority = 0){
77 #TODO
78 }
79 */
80
81 private:
82
85
86 };
87
88}
89#endif // BOOST_FAIRNESS_PQLOCK_HPP
Definition request_pool.hpp:50
void returnRequest(Request *const req)
Definition request_pool.hpp:66
Request * getRequest()
Definition request_pool.hpp:57
Definition coherent_priority_lock.hpp:33
void requestLock(Thread *const requester)
Definition coherent_priority_lock.hpp:49
void grantLock(Thread *const requester)
Definition coherent_priority_lock.hpp:63
void initialize(Request *const firstTail)
Definition coherent_priority_lock.hpp:39
Definition pqlock.hpp:25
void unlock()
Definition pqlock.hpp:67
void lock(Priority_t const priority=0)
Definition pqlock.hpp:49
This file contains the implementation of a coherent priority lock.
This file contains configurations about boost and 128bit cpu support. TODO.
Definition coherent_priority_lock.hpp:25
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...
This file contains the implementation of a static very fast and simple request pool.
Definition request_pool.hpp:25
Definition thread_pool.hpp:24
void prepare(Priority_t p, Request *req)
Definition thread_pool.hpp:28
Request * watch_
Definition thread_pool.hpp:39
This file contains the implementation of a pool of thread structs.