fairness  v1.0.0
A collection of advanced syncronization mechanisms.
Loading...
Searching...
No Matches
shared_priority_mutex_benchmark.hpp
Go to the documentation of this file.
1
14#include <boost/fairness.hpp>
15#include "../utils/thread_utils.hpp"
16
19
20 void lock_unlock_benchmark(benchmark::State& state) {
21 for (auto _ : state){
22 m.lock();
23 m.unlock();
24 }
25 }
26
27 void shared_lock_unlock_benchmark(benchmark::State& state) {
28 for (auto _ : state){
29 m.lock_shared();
30 m.unlock_shared();
31 }
32 }
33
34 void pipeline_benchmark_long(benchmark::State& state) {// order of 1/10th of a second (PM faster)
35 std::array<int, 8> prios {0, 1, 2, 1, 3, 2, 2, 0};
36 std::array<int, 8> preCT {20, 15, 20, 30, 10, 5, 5, 20};
37 int CT = 10;
38 std::array<int, 8> postCT {50, 30, 20, 25, 10, 15, 15, 45};
39
40 for (auto _ : state) {
41 utils::thread::thread_function<utils::thread::LockLevel::Unique, utils::waiting::WaitingLevel::Milli>(m, preCT[state.thread_index()], CT, postCT[state.thread_index()], prios[state.thread_index()]);
42 }
43 }
44
45 void shared_pipeline_benchmark_long(benchmark::State& state) {// order of 1/10th of a second (PM faster)
46 std::array<int, 8> prios {0, 1, 2, 1, 3, 2, 2, 0};
47 std::array<int, 8> preCT {20, 15, 20, 30, 10, 5, 5, 20};
48 int CT = 10;
49 std::array<int, 8> postCT {50, 30, 20, 25, 10, 15, 15, 45};
50
51 for (auto _ : state) {
52 utils::thread::thread_function<utils::thread::LockLevel::Shared, utils::waiting::WaitingLevel::Milli>(m, preCT[state.thread_index()], CT, postCT[state.thread_index()], prios[state.thread_index()]);
53 }
54 }
55
56 void pipeline_benchmark_gaming(benchmark::State& state) {// order of 10 to 15 milliseconds (PM faster)
57 std::array<int, 8> prios {0, 1, 2, 1, 3, 2, 2, 0};
58 std::array<int, 8> preCT {2000, 1500, 2000, 3000, 1000, 500, 500, 2000};
59 int CT = 1000;
60 std::array<int, 8> postCT {5000, 3000, 2000, 2500, 1000, 1500, 1500, 4500};
61
62 for (auto _ : state) {
63 utils::thread::thread_function<utils::thread::LockLevel::Unique, utils::waiting::WaitingLevel::Micro>(m, preCT[state.thread_index()], CT, postCT[state.thread_index()], prios[state.thread_index()]);
64 }
65 }
66
67 void shared_pipeline_benchmark_gaming(benchmark::State& state) {// order of 10 to 15 milliseconds (PM faster)
68 std::array<int, 8> prios {0, 1, 2, 1, 3, 2, 2, 0};
69 std::array<int, 8> preCT {2000, 1500, 2000, 3000, 1000, 500, 500, 2000};
70 int CT = 1000;
71 std::array<int, 8> postCT {5000, 3000, 2000, 2500, 1000, 1500, 1500, 4500};
72
73 for (auto _ : state) {
74 utils::thread::thread_function<utils::thread::LockLevel::Shared, utils::waiting::WaitingLevel::Micro>(m, preCT[state.thread_index()], CT, postCT[state.thread_index()], prios[state.thread_index()]);
75 }
76 }
77
78 void pipeline_benchmark_audio(benchmark::State& state) {// order of 1 to 1.5 millisec (PM faster)
79 std::array<int, 8> prios {0, 1, 2, 1, 3, 2, 2, 0};
80 std::array<int, 8> preCT {200, 150, 200, 300, 100, 50, 50, 200};
81 int CT = 100;
82 std::array<int, 8> postCT {500, 300, 200, 250, 100, 150, 150, 450};
83
84 for (auto _ : state) {
85 utils::thread::thread_function<utils::thread::LockLevel::Unique, utils::waiting::WaitingLevel::Micro>(m, preCT[state.thread_index()], CT, postCT[state.thread_index()], prios[state.thread_index()]);
86 }
87 }
88
89 void shared_pipeline_benchmark_audio(benchmark::State& state) {// order of 1 to 1.5 millisec (PM faster)
90 std::array<int, 8> prios {0, 1, 2, 1, 3, 2, 2, 0};
91 std::array<int, 8> preCT {200, 150, 200, 300, 100, 50, 50, 200};
92 int CT = 100;
93 std::array<int, 8> postCT {500, 300, 200, 250, 100, 150, 150, 450};
94
95 for (auto _ : state) {
96 utils::thread::thread_function<utils::thread::LockLevel::Shared, utils::waiting::WaitingLevel::Micro>(m, preCT[state.thread_index()], CT, postCT[state.thread_index()], prios[state.thread_index()]);
97 }
98 }
99
100 void pipeline_benchmark_fast(benchmark::State& state) {
101 std::array<int, 8> prios {0, 1, 2, 1, 3, 2, 2, 0};
102 std::array<int, 8> preCT {2000, 1500, 2000, 3000, 1000, 500, 500, 2000};
103 int CT = 1000;
104 std::array<int, 8> postCT {5000, 3000, 2000, 2500, 1000, 1500, 1500, 4500};
105
106 for (auto _ : state) {
107 utils::thread::thread_function<utils::thread::LockLevel::Unique, utils::waiting::WaitingLevel::Nano>(m, preCT[state.thread_index()], CT, postCT[state.thread_index()], prios[state.thread_index()]);
108 }
109 }
110
111 void shared_pipeline_benchmark_fast(benchmark::State& state) {
112 std::array<int, 8> prios {0, 1, 2, 1, 3, 2, 2, 0};
113 std::array<int, 8> preCT {2000, 1500, 2000, 3000, 1000, 500, 500, 2000};
114 int CT = 1000;
115 std::array<int, 8> postCT {5000, 3000, 2000, 2500, 1000, 1500, 1500, 4500};
116
117 for (auto _ : state) {
118 utils::thread::thread_function<utils::thread::LockLevel::Shared, utils::waiting::WaitingLevel::Nano>(m, preCT[state.thread_index()], CT, postCT[state.thread_index()], prios[state.thread_index()]);
119 }
120 }
121}
The shared_priority_mutex is an advanced synchronization mechanism that enhances the traditional shar...
Definition shared_priority_mutex.hpp:49
void lock(Priority_t const priority=0)
Try to acquire the unique ownership of the shared_priority_mutex, blocking the thread if the shared_p...
Definition shared_priority_mutex.hpp:109
This file contains the all the includes required by the library.
Definition shared_priority_mutex_benchmark.hpp:17
void shared_pipeline_benchmark_fast(benchmark::State &state)
Definition shared_priority_mutex_benchmark.hpp:111
void pipeline_benchmark_gaming(benchmark::State &state)
Definition shared_priority_mutex_benchmark.hpp:56
void lock_unlock_benchmark(benchmark::State &state)
Definition shared_priority_mutex_benchmark.hpp:20
void pipeline_benchmark_audio(benchmark::State &state)
Definition shared_priority_mutex_benchmark.hpp:78
void pipeline_benchmark_long(benchmark::State &state)
Definition shared_priority_mutex_benchmark.hpp:34
void shared_pipeline_benchmark_long(benchmark::State &state)
Definition shared_priority_mutex_benchmark.hpp:45
void shared_pipeline_benchmark_gaming(benchmark::State &state)
Definition shared_priority_mutex_benchmark.hpp:67
void pipeline_benchmark_fast(benchmark::State &state)
Definition shared_priority_mutex_benchmark.hpp:100
void shared_lock_unlock_benchmark(benchmark::State &state)
Definition shared_priority_mutex_benchmark.hpp:27
void shared_pipeline_benchmark_audio(benchmark::State &state)
Definition shared_priority_mutex_benchmark.hpp:89
boost::fairness::shared_priority_mutex< 4 > m
Definition shared_priority_mutex_benchmark.hpp:18
void thread_function(Lockable &lockable, int preCriticalTime, int criticalTime, int postCriticalTime, int p=0)
Definition thread_utils.hpp:26