aboutsummaryrefslogtreecommitdiff
path: root/src/cancel.cpp
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2024-04-08 18:26:47 +0200
committerBenoit Germain <benoit.germain@ubisoft.com>2024-04-08 18:26:47 +0200
commit6efef88d0c7c155690dc2ac478d52e75da97d147 (patch)
tree9706bac4d419f0f242f69d283412f912e0b2b6fb /src/cancel.cpp
parent96daea993eeea17f0c64325491943e48795ff751 (diff)
downloadlanes-6efef88d0c7c155690dc2ac478d52e75da97d147.tar.gz
lanes-6efef88d0c7c155690dc2ac478d52e75da97d147.tar.bz2
lanes-6efef88d0c7c155690dc2ac478d52e75da97d147.zip
C++ migration: lanes.now_secs uses std::chrono::sytem_clock. plus more enum class cleanup.
Diffstat (limited to 'src/cancel.cpp')
-rw-r--r--src/cancel.cpp17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/cancel.cpp b/src/cancel.cpp
index 6a94343..437a6f0 100644
--- a/src/cancel.cpp
+++ b/src/cancel.cpp
@@ -33,13 +33,14 @@ THE SOFTWARE.
33]]-- 33]]--
34*/ 34*/
35 35
36#include <assert.h> 36#include "cancel.h"
37#include <string.h> 37
38// #include <assert.h>
39//#include <string.h>
38 40
41#include "lanes_private.h"
39#include "threading.h" 42#include "threading.h"
40#include "cancel.h"
41#include "tools.h" 43#include "tools.h"
42#include "lanes_private.h"
43 44
44// ################################################################################################ 45// ################################################################################################
45// ################################################################################################ 46// ################################################################################################
@@ -103,7 +104,7 @@ static void cancel_hook(lua_State* L, [[maybe_unused]] lua_Debug* ar)
103// 'wake_lindas_bool': if true, signal any linda the thread is waiting on 104// 'wake_lindas_bool': if true, signal any linda the thread is waiting on
104// instead of waiting for its timeout (if any) 105// instead of waiting for its timeout (if any)
105// 106//
106// Returns: true if the lane was already finished (DONE/ERROR_ST/CANCELLED) or if we 107// Returns: true if the lane was already finished (Done/Error/Cancelled) or if we
107// managed to cancel it. 108// managed to cancel it.
108// false if the cancellation timed out, or a kill was needed. 109// false if the cancellation timed out, or a kill was needed.
109// 110//
@@ -117,7 +118,7 @@ static CancelResult thread_cancel_soft(Lane* lane_, lua_Duration duration_, bool
117 if (wake_lane_) // wake the thread so that execution returns from any pending linda operation if desired 118 if (wake_lane_) // wake the thread so that execution returns from any pending linda operation if desired
118 { 119 {
119 std::condition_variable* const waiting_on{ lane_->m_waiting_on }; 120 std::condition_variable* const waiting_on{ lane_->m_waiting_on };
120 if (lane_->status == WAITING && waiting_on != nullptr) 121 if (lane_->m_status == Lane::Waiting && waiting_on != nullptr)
121 { 122 {
122 waiting_on->notify_all(); 123 waiting_on->notify_all();
123 } 124 }
@@ -135,7 +136,7 @@ static CancelResult thread_cancel_hard(Lane* lane_, lua_Duration duration_, bool
135 if (wake_lane_) // wake the thread so that execution returns from any pending linda operation if desired 136 if (wake_lane_) // wake the thread so that execution returns from any pending linda operation if desired
136 { 137 {
137 std::condition_variable* waiting_on = lane_->m_waiting_on; 138 std::condition_variable* waiting_on = lane_->m_waiting_on;
138 if (lane_->status == WAITING && waiting_on != nullptr) 139 if (lane_->m_status == Lane::Waiting && waiting_on != nullptr)
139 { 140 {
140 waiting_on->notify_all(); 141 waiting_on->notify_all();
141 } 142 }
@@ -151,7 +152,7 @@ CancelResult thread_cancel(Lane* lane_, CancelOp op_, int hook_count_, lua_Durat
151{ 152{
152 // remember that lanes are not transferable: only one thread can cancel a lane, so no multithreading issue here 153 // remember that lanes are not transferable: only one thread can cancel a lane, so no multithreading issue here
153 // We can read 'lane_->status' without locks, but not wait for it (if Posix no PTHREAD_TIMEDJOIN) 154 // We can read 'lane_->status' without locks, but not wait for it (if Posix no PTHREAD_TIMEDJOIN)
154 if (lane_->status >= DONE) 155 if (lane_->m_status >= Lane::Done)
155 { 156 {
156 // say "ok" by default, including when lane is already done 157 // say "ok" by default, including when lane is already done
157 return CancelResult::Cancelled; 158 return CancelResult::Cancelled;