fairness  v1.0.0
A collection of advanced syncronization mechanisms.
Loading...
Searching...
No Matches
pqspinlock.hpp
Go to the documentation of this file.
1
13#ifndef BOOST_FAIRNESS_PQSPINLOCK_HPP
14#define BOOST_FAIRNESS_PQSPINLOCK_HPP
15
16#include <exception>
22
24
26
27 public:
28
30 pqspinlock() {
31 cpl_.initialize(reqs_.getRequest());
32 };
33
35 pqspinlock(const pqspinlock&) = delete;
36
38 pqspinlock& operator=(const pqspinlock&) = delete;
39
41 pqspinlock(pqspinlock&&) = delete;
42
44 pqspinlock& operator=(pqspinlock&&) = delete;
45
47 ~pqspinlock() = 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 private:
75
78
79 };
80
81}
82#endif // BOOST_FAIRNESS_PQSPINLOCK_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 pqspinlock.hpp:25
void lock(Priority_t const priority=0)
Definition pqspinlock.hpp:49
void unlock()
Definition pqspinlock.hpp:67
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.