2
2
// SPDX-License-Identifier: GPL-2.0-or-later
3
3
4
4
#include < condition_variable>
5
+ #include < list>
5
6
#include < mutex>
6
- #include < utility>
7
- #include < boost/intrusive/list.hpp>
8
7
#include < pthread.h>
9
8
#include " common/assert.h"
10
9
#include " common/logging/log.h"
13
12
14
13
namespace Libraries ::Kernel {
15
14
16
- using ListBaseHook =
17
- boost::intrusive::list_base_hook<boost::intrusive::link_mode<boost::intrusive::normal_link>>;
18
-
19
15
class Semaphore {
20
16
public:
21
17
Semaphore (s32 init_count, s32 max_count, std::string_view name, bool is_fifo)
@@ -37,7 +33,7 @@ class Semaphore {
37
33
38
34
// Create waiting thread object and add it into the list of waiters.
39
35
WaitingThread waiter{need_count, is_fifo};
40
- AddWaiter (waiter);
36
+ AddWaiter (& waiter);
41
37
42
38
// Perform the wait.
43
39
return waiter.Wait (lk, timeout);
@@ -52,14 +48,14 @@ class Semaphore {
52
48
53
49
// Wake up threads in order of priority.
54
50
for (auto it = wait_list.begin (); it != wait_list.end ();) {
55
- auto & waiter = *it;
56
- if (waiter. need_count > token_count) {
51
+ auto * waiter = *it;
52
+ if (waiter-> need_count > token_count) {
57
53
it++;
58
54
continue ;
59
55
}
60
56
it = wait_list.erase (it);
61
- token_count -= waiter. need_count ;
62
- waiter. cv .notify_one ();
57
+ token_count -= waiter-> need_count ;
58
+ waiter-> cv .notify_one ();
63
59
}
64
60
65
61
return true ;
@@ -70,17 +66,17 @@ class Semaphore {
70
66
if (num_waiters) {
71
67
*num_waiters = wait_list.size ();
72
68
}
73
- for (auto & waiter : wait_list) {
74
- waiter. was_cancled = true ;
75
- waiter. cv .notify_one ();
69
+ for (auto * waiter : wait_list) {
70
+ waiter-> was_cancled = true ;
71
+ waiter-> cv .notify_one ();
76
72
}
77
73
wait_list.clear ();
78
74
token_count = set_count < 0 ? init_count : set_count;
79
75
return ORBIS_OK;
80
76
}
81
77
82
78
public:
83
- struct WaitingThread : public ListBaseHook {
79
+ struct WaitingThread {
84
80
std::condition_variable cv;
85
81
u32 priority;
86
82
s32 need_count;
@@ -132,24 +128,21 @@ class Semaphore {
132
128
}
133
129
};
134
130
135
- void AddWaiter (WaitingThread& waiter) {
131
+ void AddWaiter (WaitingThread* waiter) {
136
132
// Insert at the end of the list for FIFO order.
137
133
if (is_fifo) {
138
134
wait_list.push_back (waiter);
139
135
return ;
140
136
}
141
137
// Find the first with priority less then us and insert right before it.
142
138
auto it = wait_list.begin ();
143
- while (it != wait_list.end () && it ->priority > waiter. priority ) {
139
+ while (it != wait_list.end () && (*it) ->priority > waiter-> priority ) {
144
140
it++;
145
141
}
146
142
wait_list.insert (it, waiter);
147
143
}
148
144
149
- using WaitingThreads =
150
- boost::intrusive::list<WaitingThread, boost::intrusive::base_hook<ListBaseHook>,
151
- boost::intrusive::constant_time_size<false >>;
152
- WaitingThreads wait_list;
145
+ std::list<WaitingThread*> wait_list;
153
146
std::string name;
154
147
std::atomic<s32> token_count;
155
148
std::mutex mutex;
0 commit comments