Skip to content

Commit 25ad94b

Browse files
committed
Refactor: Minor improvements.
1 parent 4f023e4 commit 25ad94b

File tree

6 files changed

+60
-56
lines changed

6 files changed

+60
-56
lines changed

_windows/config_env_clang.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@ECHO OFF
22
IF NOT "%CLANG_DIR%" == "" GOTO CLANG_DIR_IS_SET
3-
SET CLANG_DIR=C:\Devel\Platform\Clang\21.1.4-x86_64
3+
SET CLANG_DIR=C:\Devel\Platform\Clang\21.1.7-x86_64
44
SET PATH=%CLANG_DIR%\bin;%PATH%
55
:CLANG_DIR_IS_SET
66
CALL "%~dp0config_env_ninja.cmd"

_windows/config_env_cmake.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@ECHO OFF
22
IF NOT "%CMAKE_DIR%" == "" GOTO CMAKE_DIR_IS_SET
3-
SET CMAKE_DIR=C:\Devel\Platform\CMake\4.0.4-x86_64
3+
SET CMAKE_DIR=C:\Devel\Platform\CMake\4.1.3-x86_64
44
SET PATH=%CMAKE_DIR%\bin;%PATH%
55
:CMAKE_DIR_IS_SET

_windows/config_env_ninja.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@ECHO OFF
22
IF NOT "%NINJA_DIR%" == "" GOTO NINJA_DIR_IS_SET
3-
SET NINJA_DIR=C:\Devel\Platform\Ninja\1.13.1
3+
SET NINJA_DIR=C:\Devel\Platform\Ninja\1.13.2
44
SET PATH=%NINJA_DIR%;%PATH%
55
:NINJA_DIR_IS_SET

include/xtxn/fast_mpmc_queue.hpp

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ namespace xtxn {
1919
int32_t S = queue_default_block_size,
2020
int32_t L = queue_default_capacity_limit,
2121
bool C = queue_default_completion,
22-
int32_t A = queue_default_attempts,
22+
unsigned A = queue_default_attempts,
2323
queue_growth_policy G = queue_growth_policy::round
2424
>
2525
requires ((S >= 4) && (L <= queue_max_capacity_limit) && (S <= L) && (A > 0) && (A <= queue_max_attempts))
2626
class alignas(queue_alignment) fast_mpmc_queue {
2727
struct slot;
2828
struct block;
2929
using slot_completion = queue_slot_completion<C>;
30-
// class base_accessor;
30+
// class base_accessor; // CLEANUP
3131
class producer_accessor;
3232
class consumer_accessor;
3333
using mo = std::memory_order;
@@ -52,8 +52,8 @@ namespace xtxn {
5252

5353
static constexpr size_type c_block_size [[maybe_unused]] { S };
5454
static constexpr size_type c_max_capacity [[maybe_unused]] { L };
55-
static constexpr bool c_auto_complete [[maybe_unused]] { slot_completion::c_auto_complete };
56-
static constexpr int32_t c_default_attempts [[maybe_unused]] { A };
55+
static constexpr bool c_auto_complete [[maybe_unused]] { C };
56+
static constexpr unsigned c_default_attempts [[maybe_unused]] { A };
5757
static constexpr queue_growth_policy c_growth_policy [[maybe_unused]] { G };
5858

5959
fast_mpmc_queue() noexcept(c_ntdct);
@@ -89,8 +89,8 @@ namespace xtxn {
8989
return m_consuming.load(mo::relaxed);
9090
}
9191

92-
[[nodiscard]] producer_accessor producer_slot(int32_t = c_default_attempts) noexcept(c_ntdct);
93-
[[nodiscard]] consumer_accessor consumer_slot(int32_t = c_default_attempts) noexcept;
92+
[[nodiscard]] producer_accessor producer_slot(unsigned = c_default_attempts) noexcept(c_ntdct);
93+
[[nodiscard]] consumer_accessor consumer_slot(unsigned = c_default_attempts) noexcept;
9494

9595
[[maybe_unused]]
9696
void shutdown() noexcept {
@@ -104,7 +104,7 @@ namespace xtxn {
104104
}
105105
};
106106

107-
template<std::default_initializable T, int32_t S, int32_t L, bool C, int32_t A, queue_growth_policy G>
107+
template<std::default_initializable T, int32_t S, int32_t L, bool C, unsigned A, queue_growth_policy G>
108108
requires ((S >= 4) && (L <= queue_max_capacity_limit) && (S <= L) && (A > 0) && (A <= queue_max_attempts))
109109
struct fast_mpmc_queue<T, S, L, C, A, G>::slot {
110110
slot * m_next { nullptr };
@@ -120,7 +120,7 @@ namespace xtxn {
120120
slot & operator=(slot &&) = delete;
121121
};
122122

123-
template<std::default_initializable T, int32_t S, int32_t L, bool C, int32_t A, queue_growth_policy G>
123+
template<std::default_initializable T, int32_t S, int32_t L, bool C, unsigned A, queue_growth_policy G>
124124
requires ((S >= 4) && (L <= queue_max_capacity_limit) && (S <= L) && (A > 0) && (A <= queue_max_attempts))
125125
struct fast_mpmc_queue<T, S, L, C, A, G>::block {
126126
std::array<slot, static_cast<size_t>(S)> m_slots {};
@@ -146,7 +146,7 @@ namespace xtxn {
146146
}
147147
};
148148

149-
template<std::default_initializable T, int32_t S, int32_t L, bool C, int32_t A, queue_growth_policy G>
149+
template<std::default_initializable T, int32_t S, int32_t L, bool C, unsigned A, queue_growth_policy G>
150150
requires ((S >= 4) && (L <= queue_max_capacity_limit) && (S <= L) && (A > 0) && (A <= queue_max_attempts))
151151
fast_mpmc_queue<T, S, L, C, A, G>::block::block() noexcept(c_ntdct) {
152152
auto it = m_slots.begin();
@@ -160,7 +160,7 @@ namespace xtxn {
160160
last->m_next = &m_slots[0];
161161
}
162162

163-
template<std::default_initializable T, int32_t S, int32_t L, bool C, int32_t A, queue_growth_policy G>
163+
template<std::default_initializable T, int32_t S, int32_t L, bool C, unsigned A, queue_growth_policy G>
164164
requires ((S >= 4) && (L <= queue_max_capacity_limit) && (S <= L) && (A > 0) && (A <= queue_max_attempts))
165165
fast_mpmc_queue<T, S, L, C, A, G>::block::block(block * & last_block) noexcept(c_ntdct) {
166166
assert(last_block);
@@ -178,7 +178,8 @@ namespace xtxn {
178178
last_block->m_next = this;
179179
}
180180

181-
// template<std::default_initializable T, int32_t S, int32_t L, bool C, int32_t A, queue_growth_policy G>
181+
// CLEANUP
182+
// template<std::default_initializable T, int32_t S, int32_t L, bool C, unsigned A, queue_growth_policy G>
182183
// requires ((S >= 4) && (L <= queue_max_capacity_limit) && (S <= L) && (A > 0) && (A <= queue_max_attempts))
183184
// class fast_mpmc_queue<T, S, L, C, A, G>::base_accessor {
184185
// protected:
@@ -209,12 +210,12 @@ namespace xtxn {
209210
// }
210211
// };
211212

212-
template<std::default_initializable T, int32_t S, int32_t L, bool C, int32_t A, queue_growth_policy G>
213+
template<std::default_initializable T, int32_t S, int32_t L, bool C, unsigned A, queue_growth_policy G>
213214
requires ((S >= 4) && (L <= queue_max_capacity_limit) && (S <= L) && (A > 0) && (A <= queue_max_attempts))
214215
class fast_mpmc_queue<T, S, L, C, A, G>::producer_accessor : /*public base_accessor,*/ public slot_completion {
215216
protected:
216-
// using base_accessor::m_queue;
217-
// using base_accessor::m_slot;
217+
// using base_accessor::m_queue; // CLEANUP
218+
// using base_accessor::m_slot; // CLEANUP
218219
fast_mpmc_queue & m_queue;
219220
slot * const m_slot;
220221

@@ -251,7 +252,7 @@ namespace xtxn {
251252
}
252253
};
253254

254-
template<std::default_initializable T, int32_t S, int32_t L, bool C, int32_t A, queue_growth_policy G>
255+
template<std::default_initializable T, int32_t S, int32_t L, bool C, unsigned A, queue_growth_policy G>
255256
requires ((S >= 4) && (L <= queue_max_capacity_limit) && (S <= L) && (A > 0) && (A <= queue_max_attempts))
256257
fast_mpmc_queue<T, S, L, C, A, G>::producer_accessor::~producer_accessor() noexcept {
257258
if (m_slot) {
@@ -268,12 +269,12 @@ namespace xtxn {
268269
}
269270
}
270271

271-
template<std::default_initializable T, int32_t S, int32_t L, bool C, int32_t A, queue_growth_policy G>
272+
template<std::default_initializable T, int32_t S, int32_t L, bool C, unsigned A, queue_growth_policy G>
272273
requires ((S >= 4) && (L <= queue_max_capacity_limit) && (S <= L) && (A > 0) && (A <= queue_max_attempts))
273274
class fast_mpmc_queue<T, S, L, C, A, G>::consumer_accessor : /*public base_accessor,*/ public slot_completion {
274275
protected:
275-
// using base_accessor::m_queue;
276-
// using base_accessor::m_slot;
276+
// using base_accessor::m_queue; // CLEANUP
277+
// using base_accessor::m_slot; // CLEANUP
277278
fast_mpmc_queue & m_queue;
278279
slot * const m_slot;
279280

@@ -306,7 +307,7 @@ namespace xtxn {
306307
}
307308
};
308309

309-
template<std::default_initializable T, int32_t S, int32_t L, bool C, int32_t A, queue_growth_policy G>
310+
template<std::default_initializable T, int32_t S, int32_t L, bool C, unsigned A, queue_growth_policy G>
310311
requires ((S >= 4) && (L <= queue_max_capacity_limit) && (S <= L) && (A > 0) && (A <= queue_max_attempts))
311312
fast_mpmc_queue<T, S, L, C, A, G>::consumer_accessor::~consumer_accessor() noexcept {
312313
if (m_slot) {
@@ -324,7 +325,7 @@ namespace xtxn {
324325
}
325326
}
326327

327-
template<std::default_initializable T, int32_t S, int32_t L, bool C, int32_t A, queue_growth_policy G>
328+
template<std::default_initializable T, int32_t S, int32_t L, bool C, unsigned A, queue_growth_policy G>
328329
requires ((S >= 4) && (L <= queue_max_capacity_limit) && (S <= L) && (A > 0) && (A <= queue_max_attempts))
329330
fast_mpmc_queue<T, S, L, C, A, G>::fast_mpmc_queue() noexcept(c_ntdct)
330331
: m_first_block { new block }, m_last_block { m_first_block } {
@@ -333,15 +334,15 @@ namespace xtxn {
333334
m_consumer_cursor.store(first_slot, mo::relaxed);
334335
}
335336

336-
template<std::default_initializable T, int32_t S, int32_t L, bool C, int32_t A, queue_growth_policy G>
337+
template<std::default_initializable T, int32_t S, int32_t L, bool C, unsigned A, queue_growth_policy G>
337338
requires ((S >= 4) && (L <= queue_max_capacity_limit) && (S <= L) && (A > 0) && (A <= queue_max_attempts))
338-
auto fast_mpmc_queue<T, S, L, C, A, G>::producer_slot(int32_t slot_acquire_attempts)
339+
auto fast_mpmc_queue<T, S, L, C, A, G>::producer_slot(unsigned slot_acquire_attempts)
339340
noexcept(c_ntdct) -> producer_accessor {
340341
if (!m_free.load(mo::acquire) && !grow()) {
341342
return { *this, nullptr };
342343
}
343344

344-
int_fast32_t attempts { slot_acquire_attempts - 1 };
345+
unsigned attempts { slot_acquire_attempts - 1 };
345346
slot * sentinel { m_producer_cursor.exchange(m_producer_cursor.load(mo::acquire)->m_next, mo::acq_rel) };
346347
slot * current { sentinel };
347348

@@ -372,10 +373,11 @@ namespace xtxn {
372373
return { *this, nullptr };
373374
}
374375

375-
template<std::default_initializable T, int32_t S, int32_t L, bool C, int32_t A, queue_growth_policy G>
376+
template<std::default_initializable T, int32_t S, int32_t L, bool C, unsigned A, queue_growth_policy G>
376377
requires ((S >= 4) && (L <= queue_max_capacity_limit) && (S <= L) && (A > 0) && (A <= queue_max_attempts))
377-
auto fast_mpmc_queue<T, S, L, C, A, G>::consumer_slot(int32_t slot_acquire_attempts) noexcept -> consumer_accessor {
378-
int_fast32_t attempts { slot_acquire_attempts - 1 };
378+
auto fast_mpmc_queue<T, S, L, C, A, G>::consumer_slot(unsigned slot_acquire_attempts)
379+
noexcept -> consumer_accessor {
380+
unsigned attempts { slot_acquire_attempts - 1 };
379381
slot * sentinel { m_consumer_cursor.exchange(m_consumer_cursor.load(mo::acquire)->m_next, mo::acq_rel) };
380382
slot * current { sentinel };
381383

@@ -397,7 +399,7 @@ namespace xtxn {
397399
return { *this, nullptr };
398400
}
399401

400-
template<std::default_initializable T, int32_t S, int32_t L, bool C, int32_t A, queue_growth_policy G>
402+
template<std::default_initializable T, int32_t S, int32_t L, bool C, unsigned A, queue_growth_policy G>
401403
requires ((S >= 4) && (L <= queue_max_capacity_limit) && (S <= L) && (A > 0) && (A <= queue_max_attempts))
402404
bool fast_mpmc_queue<T, S, L, C, A, G>::grow() noexcept(c_ntdct) {
403405
scoped_lock lock { m_spinlock };
@@ -422,7 +424,7 @@ namespace xtxn {
422424

423425
template<class T>
424426
concept fast_mpmc_queue_tc = requires(T t) {
425-
[] <std::default_initializable U, int32_t S, int32_t L, bool C, int32_t A, queue_growth_policy G>
427+
[] <std::default_initializable U, int32_t S, int32_t L, bool C, unsigned A, queue_growth_policy G>
426428
(fast_mpmc_queue<U, S, L, C, A, G> &) {} (t);
427429
};
428430
}

include/xtxn/fast_queue_internal.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ namespace xtxn {
1212
constexpr int32_t queue_default_capacity_limit [[maybe_unused]] { queue_default_block_size * 0x1'0000 };
1313
constexpr int32_t queue_max_capacity_limit [[maybe_unused]] { std::numeric_limits<int32_t>::max() };
1414
constexpr bool queue_default_completion [[maybe_unused]] { true };
15-
constexpr int32_t queue_default_attempts [[maybe_unused]] { 5 };
16-
constexpr int32_t queue_max_attempts [[maybe_unused]] { std::numeric_limits<int32_t>::max() };
15+
constexpr unsigned queue_default_attempts [[maybe_unused]] { 5 };
16+
constexpr unsigned queue_max_attempts [[maybe_unused]] { std::numeric_limits<unsigned>::max() };
1717

1818
enum class queue_slot_state { free, prod_locked, ready, cons_locked };
1919

include/xtxn/fastest_mpmc_queue.hpp

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ namespace xtxn {
1515
std::default_initializable T,
1616
int32_t S,
1717
bool C = queue_default_completion,
18-
int32_t A = queue_default_attempts
18+
unsigned A = queue_default_attempts
1919
>
2020
requires ((S >= 4) && (S <= queue_max_capacity_limit) && (A > 0) && (A <= queue_max_attempts))
2121
class alignas(queue_alignment) fastest_mpmc_queue {
2222
struct slot;
2323
using slot_completion = queue_slot_completion<C>;
24-
// class base_accessor;
24+
// class base_accessor; // CLEANUP
2525
class producer_accessor;
2626
class consumer_accessor;
2727
using mo = std::memory_order;
@@ -40,8 +40,9 @@ namespace xtxn {
4040
using size_type = decltype(S);
4141
using offset_type = decltype(m_producer_cursor)::value_type;
4242

43-
static constexpr bool c_auto_complete [[maybe_unused]] { slot_completion::c_auto_complete };
44-
static constexpr auto c_default_attempts [[maybe_unused]] = A;
43+
static constexpr size_type c_size [[maybe_unused]] { S };
44+
static constexpr bool c_auto_complete [[maybe_unused]] { C };
45+
static constexpr unsigned c_default_attempts [[maybe_unused]] { A };
4546

4647
fastest_mpmc_queue() noexcept(c_ntdct) = default;
4748
fastest_mpmc_queue(const fastest_mpmc_queue &) = delete;
@@ -76,8 +77,8 @@ namespace xtxn {
7677
return m_consuming.load(mo::relaxed);
7778
}
7879

79-
[[nodiscard]] producer_accessor producer_slot(int32_t = c_default_attempts) noexcept(c_ntdct);
80-
[[nodiscard]] consumer_accessor consumer_slot(int32_t = c_default_attempts) noexcept;
80+
[[nodiscard]] producer_accessor producer_slot(unsigned = c_default_attempts) noexcept(c_ntdct);
81+
[[nodiscard]] consumer_accessor consumer_slot(unsigned = c_default_attempts) noexcept;
8182

8283
[[maybe_unused]]
8384
void shutdown() noexcept {
@@ -113,7 +114,7 @@ namespace xtxn {
113114
}
114115
};
115116

116-
template<std::default_initializable T, int32_t S, bool C, int32_t A>
117+
template<std::default_initializable T, int32_t S, bool C, unsigned A>
117118
requires ((S >= 4) && (S <= queue_max_capacity_limit) && (A > 0) && (A <= queue_max_attempts))
118119
struct fastest_mpmc_queue<T, S, C, A>::slot {
119120
std::atomic<state> m_state { state::free };
@@ -128,7 +129,8 @@ namespace xtxn {
128129
slot & operator=(slot &&) = delete;
129130
};
130131

131-
// template<std::default_initializable T, int32_t S, bool C, int32_t A>
132+
// CLEANUP
133+
// template<std::default_initializable T, int32_t S, bool C, unsigned A>
132134
// requires ((S >= 4) && (S <= queue_max_capacity_limit) && (A > 0) && (A <= queue_max_attempts))
133135
// class fastest_mpmc_queue<T, S, C, A>::base_accessor {
134136
// protected:
@@ -159,12 +161,12 @@ namespace xtxn {
159161
// }
160162
// };
161163

162-
template<std::default_initializable T, int32_t S, bool C, int32_t A>
164+
template<std::default_initializable T, int32_t S, bool C, unsigned A>
163165
requires ((S >= 4) && (S <= queue_max_capacity_limit) && (A > 0) && (A <= queue_max_attempts))
164166
class fastest_mpmc_queue<T, S, C, A>::producer_accessor : /*public base_accessor,*/ public slot_completion {
165167
protected:
166-
// using base_accessor::m_queue;
167-
// using base_accessor::m_slot;
168+
// using base_accessor::m_queue; // CLEANUP
169+
// using base_accessor::m_slot; // CLEANUP
168170
fastest_mpmc_queue & m_queue;
169171
slot * const m_slot;
170172

@@ -201,7 +203,7 @@ namespace xtxn {
201203
}
202204
};
203205

204-
template<std::default_initializable T, int32_t S, bool C, int32_t A>
206+
template<std::default_initializable T, int32_t S, bool C, unsigned A>
205207
requires ((S >= 4) && (S <= queue_max_capacity_limit) && (A > 0) && (A <= queue_max_attempts))
206208
fastest_mpmc_queue<T, S, C, A>::producer_accessor::~producer_accessor() noexcept {
207209
if (m_slot) {
@@ -218,12 +220,12 @@ namespace xtxn {
218220
}
219221
}
220222

221-
template<std::default_initializable T, int32_t S, bool C, int32_t A>
223+
template<std::default_initializable T, int32_t S, bool C, unsigned A>
222224
requires ((S >= 4) && (S <= queue_max_capacity_limit) && (A > 0) && (A <= queue_max_attempts))
223225
class fastest_mpmc_queue<T, S, C, A>::consumer_accessor : /*public base_accessor,*/ public slot_completion {
224226
protected:
225-
// using base_accessor::m_queue;
226-
// using base_accessor::m_slot;
227+
// using base_accessor::m_queue; // CLEANUP
228+
// using base_accessor::m_slot; // CLEANUP
227229
fastest_mpmc_queue & m_queue;
228230
slot * const m_slot;
229231

@@ -256,7 +258,7 @@ namespace xtxn {
256258
}
257259
};
258260

259-
template<std::default_initializable T, int32_t S, bool C, int32_t A>
261+
template<std::default_initializable T, int32_t S, bool C, unsigned A>
260262
requires ((S >= 4) && (S <= queue_max_capacity_limit) && (A > 0) && (A <= queue_max_attempts))
261263
fastest_mpmc_queue<T, S, C, A>::consumer_accessor::~consumer_accessor() noexcept {
262264
if (m_slot) {
@@ -274,15 +276,15 @@ namespace xtxn {
274276
}
275277
}
276278

277-
template<std::default_initializable T, int32_t S, bool C, int32_t A>
279+
template<std::default_initializable T, int32_t S, bool C, unsigned A>
278280
requires ((S >= 4) && (S <= queue_max_capacity_limit) && (A > 0) && (A <= queue_max_attempts))
279-
auto fastest_mpmc_queue<T, S, C, A>::producer_slot(int32_t slot_acquire_attempts)
281+
auto fastest_mpmc_queue<T, S, C, A>::producer_slot(unsigned slot_acquire_attempts)
280282
noexcept(c_ntdct) -> producer_accessor {
281283
if (!m_free.load(mo::acquire)) {
282284
return { *this, nullptr };
283285
}
284286

285-
int_fast32_t attempts { slot_acquire_attempts - 1 };
287+
unsigned attempts { slot_acquire_attempts - 1 };
286288
offset_type current { iterate_cursor(m_producer_cursor) };
287289
offset_type sentinel { current };
288290

@@ -307,10 +309,10 @@ namespace xtxn {
307309
return { *this, nullptr };
308310
}
309311

310-
template<std::default_initializable T, int32_t S, bool C, int32_t A>
312+
template<std::default_initializable T, int32_t S, bool C, unsigned A>
311313
requires ((S >= 4) && (S <= queue_max_capacity_limit) && (A > 0) && (A <= queue_max_attempts))
312-
auto fastest_mpmc_queue<T, S, C, A>::consumer_slot(int32_t slot_acquire_attempts) noexcept -> consumer_accessor {
313-
int_fast32_t attempts { slot_acquire_attempts - 1 };
314+
auto fastest_mpmc_queue<T, S, C, A>::consumer_slot(unsigned slot_acquire_attempts) noexcept -> consumer_accessor {
315+
unsigned attempts { slot_acquire_attempts - 1 };
314316
offset_type current { iterate_cursor(m_consumer_cursor) };
315317
offset_type sentinel { current };
316318

@@ -338,6 +340,6 @@ namespace xtxn {
338340

339341
template<class T>
340342
concept fastest_mpmc_queue_tc = requires(T t) {
341-
[] <std::default_initializable U, int32_t S, bool C, int32_t A> (fastest_mpmc_queue<U, S, C, A> &) {} (t);
343+
[] <std::default_initializable U, int32_t S, bool C, unsigned A> (fastest_mpmc_queue<U, S, C, A> &) {} (t);
342344
};
343345
}

0 commit comments

Comments
 (0)