fairness  v1.0.0
A collection of advanced syncronization mechanisms.
Loading...
Searching...
No Matches
thread_pool.hpp
Go to the documentation of this file.
1
14#ifndef BOOST_FAIRNESS_THREAD_POOL_HPP
15#define BOOST_FAIRNESS_THREAD_POOL_HPP
16
17#include <array>
19
21
22 class pqspinlock;
23
24 struct Thread{
25
26 Thread() = default;
27
28 void prepare(Priority_t p, Request* req){
29
30 request_ = req;
31
32 req->thread_ = this;
33
34 priority_ = p;
35
36 watch_ = nullptr;
37 }
38
39 Request* watch_{nullptr};
40 Request* request_{nullptr};
41 void* owner_{nullptr};
43 bool inUse_{};
44 };
45
46 template<size_t N>
48 public:
49
50 ThreadPool() = default;
51
52 Thread* getThread(void* const owner){
53 for (uint32_t i = 0; i < N; ++i){
54 if (!threads_[i].inUse_){
55 threads_[i].owner_ = owner;
56 return &threads_[i];
57 }
58 }
59 return nullptr;
60 }
61
62 Thread* reGetThread(void* const owner){
63 for (uint32_t i = 0; i < N; ++i){
64 if (threads_[i].owner_ == owner){
65 return &threads_[i];
66 }
67 }
68 return nullptr;
69 }
70
71 void returnThread(Thread* const t){
72 // setting owner_ to nullptr should be unnecessary
73 t->inUse_ = false;
74 }
75
76 private:
77
78 std::array<Thread, N> threads_;
79
80 };
81
82 static thread_local ThreadPool<BOOST_FAIRNESS_MAX_THREADS> t_;
83
84}
85#endif // BOOST_FAIRNESS_THREAD_POOL_HPP
Definition thread_pool.hpp:47
Thread * getThread(void *const owner)
Definition thread_pool.hpp:52
Thread * reGetThread(void *const owner)
Definition thread_pool.hpp:62
void returnThread(Thread *const t)
Definition thread_pool.hpp:71
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
boost::fairness::detail::pqspinlock pqspinlock
Definition priority_mutex_benchmark.hpp:20
#define BOOST_FAIRNESS_INVALID_PRIORITY
A number indicating an invalid priority which is not usable by the mutexes.
Definition priority_t.hpp:29
Definition request_pool.hpp:25
Thread * thread_
Definition request_pool.hpp:27
Definition thread_pool.hpp:24
Request * request_
Definition thread_pool.hpp:40
void prepare(Priority_t p, Request *req)
Definition thread_pool.hpp:28
void * owner_
Definition thread_pool.hpp:41
Request * watch_
Definition thread_pool.hpp:39
bool inUse_
Definition thread_pool.hpp:43
Priority_t priority_
Definition thread_pool.hpp:42