Skip to content

Commit 62ab8d8

Browse files
authored
post() / post_bulk() inlining improvements (#141)
1 parent 4c722c0 commit 62ab8d8

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

include/tmc/detail/ex_cpu.ipp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,8 @@ void ex_cpu::post(work_item&& Item, size_t Priority, size_t ThreadHint) {
367367
if (!fromExecThread || ThreadHint != tmc::current_thread_index()) {
368368
notify_n(1, Priority, ThreadHint, fromExecThread, true);
369369
}
370-
} else {
371-
if (fromExecThread) {
370+
} else [[likely]] {
371+
if (fromExecThread) [[likely]] {
372372
work_queues[Priority].enqueue_ex_cpu(
373373
static_cast<work_item&&>(Item), Priority
374374
);

include/tmc/detail/qu_lockfree.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ class ConcurrentQueue {
727727
}
728728

729729
// Enqueues a single item using this ex_cpu thread's explicit producer.
730-
template <typename U> inline void enqueue_ex_cpu(U&& item, size_t priority) {
730+
template <typename U> TMC_FORCE_INLINE inline void enqueue_ex_cpu(U&& item, size_t priority) {
731731
ExplicitProducer** producers =
732732
static_cast<ExplicitProducer**>(tmc::detail::this_thread::producers);
733733
ExplicitProducer* this_thread_prod =
@@ -744,7 +744,7 @@ class ConcurrentQueue {
744744

745745
// Enqueues several items using this ex_cpu thread's explicit producer.
746746
template <typename It>
747-
void enqueue_bulk_ex_cpu(It itemFirst, size_t count, size_t priority) {
747+
TMC_FORCE_INLINE void enqueue_bulk_ex_cpu(It itemFirst, size_t count, size_t priority) {
748748
ExplicitProducer** producers =
749749
static_cast<ExplicitProducer**>(tmc::detail::this_thread::producers);
750750
ExplicitProducer* this_thread_prod =
@@ -1416,7 +1416,7 @@ class ConcurrentQueue {
14161416
}
14171417
}
14181418

1419-
template <typename U> inline void enqueue(U&& element) {
1419+
template <typename U> TMC_FORCE_INLINE inline void enqueue(U&& element) {
14201420
index_t currentTailIndex =
14211421
this->tailIndex.load(std::memory_order_relaxed);
14221422
index_t newTailIndex = 1 + currentTailIndex;
@@ -1748,7 +1748,7 @@ class ConcurrentQueue {
17481748
}
17491749

17501750
template <typename It>
1751-
void MOODYCAMEL_NO_TSAN enqueue_bulk(It itemFirst, size_t count) {
1751+
TMC_FORCE_INLINE void MOODYCAMEL_NO_TSAN enqueue_bulk(It itemFirst, size_t count) {
17521752
// static constexpr bool HasMoveConstructor = std::is_constructible_v<
17531753
// T, std::add_rvalue_reference_t<std::iter_value_t<It>>>;
17541754
static constexpr bool HasNoexceptMoveConstructor =

include/tmc/ex_cpu.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ class ex_cpu {
222222
if (!fromExecThread) {
223223
++ref_count;
224224
}
225-
if (ThreadHint < thread_count()) {
225+
if (ThreadHint < thread_count()) [[unlikely]] {
226226
size_t enqueuedCount = thread_states[ThreadHint].inbox->try_push_bulk(
227227
static_cast<It&&>(Items), Count, Priority
228228
);
@@ -233,8 +233,8 @@ class ex_cpu {
233233
}
234234
}
235235
}
236-
if (Count > 0) {
237-
if (fromExecThread) {
236+
if (Count > 0) [[likely]] {
237+
if (fromExecThread) [[likely]] {
238238
work_queues[Priority].enqueue_bulk_ex_cpu(
239239
static_cast<It&&>(Items), Count, Priority
240240
);

0 commit comments

Comments
 (0)