Commit 51667d5c by FritzFlorian

Fix top-pointer help (potentially not lock free without the fix).

parent 6a123b3b
Pipeline #2633 passed with stages
in 4 minutes 37 seconds
...@@ -46,8 +46,6 @@ struct traded_cas_field { ...@@ -46,8 +46,6 @@ struct traded_cas_field {
return stamp_; return stamp_;
} }
[[nodiscard]] unsigned long get_trade_request_thread_id() const { [[nodiscard]] unsigned long get_trade_request_thread_id() const {
PLS_ASSERT(is_filled_with_trade_request() || is_filled_with_object(),
"Must only read out the tag when the traded field contains one.");
return trade_request_thread_id_ - 1; return trade_request_thread_id_ - 1;
} }
...@@ -62,6 +60,9 @@ struct traded_cas_field { ...@@ -62,6 +60,9 @@ struct traded_cas_field {
[[nodiscard]] bool is_filled_with_object() const { [[nodiscard]] bool is_filled_with_object() const {
return non_empty_flag_ && traded_task_id_; return non_empty_flag_ && traded_task_id_;
} }
[[nodiscard]] bool object_was_traded_in() const {
return traded_task_id_ != 0;
}
[[nodiscard]] bool is_empty() const { [[nodiscard]] bool is_empty() const {
return !non_empty_flag_; return !non_empty_flag_;
} }
......
...@@ -135,7 +135,8 @@ task *external_trading_deque::pop_top(task *offered_task, peek_result peek_resul ...@@ -135,7 +135,8 @@ task *external_trading_deque::pop_top(task *offered_task, peek_result peek_resul
std::memory_order_acq_rel); std::memory_order_acq_rel);
return result; return result;
} else { } else {
if (expected_sync_cas_field.is_filled_with_object() && expected_sync_cas_field.get_stamp() == expected_top.stamp_ if (expected_sync_cas_field.object_was_traded_in()
&& expected_sync_cas_field.get_stamp() == expected_top.stamp_
&& expected_sync_cas_field.get_trade_request_thread_id() == thread_id_) { && expected_sync_cas_field.get_trade_request_thread_id() == thread_id_) {
top_.compare_exchange_strong(expected_top, top_.compare_exchange_strong(expected_top,
{expected_top.stamp_ + 1, expected_top.value_ + 1}, {expected_top.stamp_ + 1, expected_top.value_ + 1},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment