diff options
| author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-11-13 10:06:37 +0100 |
|---|---|---|
| committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-11-13 10:06:37 +0100 |
| commit | f45a3f5de2a11065764c87208d3f0b58e6ebe771 (patch) | |
| tree | 8b1d5e586e7fee575ed2d09a9cb4e7fe4f2101f2 /src | |
| parent | 43915511f5e0c74a5aa6e0d02fe62505eb133191 (diff) | |
| download | lanes-f45a3f5de2a11065764c87208d3f0b58e6ebe771.tar.gz lanes-f45a3f5de2a11065764c87208d3f0b58e6ebe771.tar.bz2 lanes-f45a3f5de2a11065764c87208d3f0b58e6ebe771.zip | |
Cleaning up guano
Converted volatile Lane::cancelRequest to std::atomic
Diffstat (limited to 'src')
| -rw-r--r-- | src/cancel.cpp | 2 | ||||
| -rw-r--r-- | src/lane.cpp | 2 | ||||
| -rw-r--r-- | src/lane.hpp | 3 | ||||
| -rw-r--r-- | src/linda.cpp | 4 | ||||
| -rw-r--r-- | src/universe.cpp | 2 |
5 files changed, 7 insertions, 6 deletions
diff --git a/src/cancel.cpp b/src/cancel.cpp index 8991684..9248b25 100644 --- a/src/cancel.cpp +++ b/src/cancel.cpp | |||
| @@ -54,7 +54,7 @@ THE SOFTWARE. | |||
| 54 | { | 54 | { |
| 55 | auto const* const _lane{ kLanePointerRegKey.readLightUserDataValue<Lane>(L_) }; | 55 | auto const* const _lane{ kLanePointerRegKey.readLightUserDataValue<Lane>(L_) }; |
| 56 | // 'lane' is nullptr for the original main state (and no-one can cancel that) | 56 | // 'lane' is nullptr for the original main state (and no-one can cancel that) |
| 57 | return _lane ? _lane->cancelRequest : CancelRequest::None; | 57 | return _lane ? _lane->cancelRequest.load(std::memory_order_relaxed) : CancelRequest::None; |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | // ################################################################################################# | 60 | // ################################################################################################# |
diff --git a/src/lane.cpp b/src/lane.cpp index ac3fffa..4caebcb 100644 --- a/src/lane.cpp +++ b/src/lane.cpp | |||
| @@ -939,7 +939,7 @@ CancelResult Lane::cancel(CancelOp const op_, std::chrono::time_point<std::chron | |||
| 939 | 939 | ||
| 940 | [[nodiscard]] CancelResult Lane::internalCancel(CancelRequest const rq_, std::chrono::time_point<std::chrono::steady_clock> const until_, WakeLane const wakeLane_) | 940 | [[nodiscard]] CancelResult Lane::internalCancel(CancelRequest const rq_, std::chrono::time_point<std::chrono::steady_clock> const until_, WakeLane const wakeLane_) |
| 941 | { | 941 | { |
| 942 | cancelRequest = rq_; // it's now signaled to stop | 942 | cancelRequest.store(rq_, std::memory_order_relaxed); // it's now signaled to stop |
| 943 | if (rq_ == CancelRequest::Hard) { | 943 | if (rq_ == CancelRequest::Hard) { |
| 944 | // lane_->thread.get_stop_source().request_stop(); | 944 | // lane_->thread.get_stop_source().request_stop(); |
| 945 | } | 945 | } |
diff --git a/src/lane.hpp b/src/lane.hpp index 4fd0f6d..1926824 100644 --- a/src/lane.hpp +++ b/src/lane.hpp | |||
| @@ -122,7 +122,8 @@ class Lane | |||
| 122 | // | 122 | // |
| 123 | // When status is Waiting, points on the linda's signal the thread waits on, else nullptr | 123 | // When status is Waiting, points on the linda's signal the thread waits on, else nullptr |
| 124 | 124 | ||
| 125 | CancelRequest volatile cancelRequest{ CancelRequest::None }; | 125 | std::atomic<CancelRequest> cancelRequest{ CancelRequest::None }; |
| 126 | static_assert(std::atomic<CancelRequest>::is_always_lock_free); | ||
| 126 | // | 127 | // |
| 127 | // M: sets to false, flags true for cancel request | 128 | // M: sets to false, flags true for cancel request |
| 128 | // S: reads to see if cancel is requested | 129 | // S: reads to see if cancel is requested |
diff --git a/src/linda.cpp b/src/linda.cpp index 80f62d3..1536da5 100644 --- a/src/linda.cpp +++ b/src/linda.cpp | |||
| @@ -640,7 +640,7 @@ LUAG_FUNC(linda_receive) | |||
| 640 | STACK_CHECK_START_REL(_K, 0); | 640 | STACK_CHECK_START_REL(_K, 0); |
| 641 | for (bool _try_again{ true };;) { | 641 | for (bool _try_again{ true };;) { |
| 642 | if (_lane != nullptr) { | 642 | if (_lane != nullptr) { |
| 643 | _cancel = _lane->cancelRequest; | 643 | _cancel = _lane->cancelRequest.load(std::memory_order_relaxed); |
| 644 | } | 644 | } |
| 645 | _cancel = (_cancel != CancelRequest::None) | 645 | _cancel = (_cancel != CancelRequest::None) |
| 646 | ? _cancel | 646 | ? _cancel |
| @@ -779,7 +779,7 @@ LUAG_FUNC(linda_send) | |||
| 779 | STACK_CHECK_START_REL(_K, 0); | 779 | STACK_CHECK_START_REL(_K, 0); |
| 780 | for (bool _try_again{ true };;) { | 780 | for (bool _try_again{ true };;) { |
| 781 | if (_lane != nullptr) { | 781 | if (_lane != nullptr) { |
| 782 | _cancel = _lane->cancelRequest; | 782 | _cancel = _lane->cancelRequest.load(std::memory_order_relaxed); |
| 783 | } | 783 | } |
| 784 | _cancel = (_cancel != CancelRequest::None) | 784 | _cancel = (_cancel != CancelRequest::None) |
| 785 | ? _cancel | 785 | ? _cancel |
diff --git a/src/universe.cpp b/src/universe.cpp index 1aafbff..357aa08 100644 --- a/src/universe.cpp +++ b/src/universe.cpp | |||
| @@ -381,7 +381,7 @@ bool Universe::terminateFreeRunningLanes(lua_Duration const shutdownTimeout_, Ca | |||
| 381 | std::lock_guard<std::mutex> _guard{ selfdestructMutex }; | 381 | std::lock_guard<std::mutex> _guard{ selfdestructMutex }; |
| 382 | Lane* _lane{ selfdestructFirst }; | 382 | Lane* _lane{ selfdestructFirst }; |
| 383 | while (_lane != SELFDESTRUCT_END) { | 383 | while (_lane != SELFDESTRUCT_END) { |
| 384 | if (_lane->cancelRequest != CancelRequest::None) | 384 | if (_lane->cancelRequest.load(std::memory_order_relaxed) != CancelRequest::None) |
| 385 | ++_n; | 385 | ++_n; |
| 386 | _lane = _lane->selfdestruct_next; | 386 | _lane = _lane->selfdestruct_next; |
| 387 | } | 387 | } |
