aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2025-04-23 14:27:00 +0200
committerBenoit Germain <benoit.germain@ubisoft.com>2025-04-23 14:27:00 +0200
commitefb81b501adbbddf25615bbcc216bbbf3a3c8e0a (patch)
tree5f354dfeee836ef78c0935cc2d0ec66e6276151c
parent7eb03175d19fca48ac915fc03c352e0d429bc37e (diff)
downloadlanes-efb81b501adbbddf25615bbcc216bbbf3a3c8e0a.tar.gz
lanes-efb81b501adbbddf25615bbcc216bbbf3a3c8e0a.tar.bz2
lanes-efb81b501adbbddf25615bbcc216bbbf3a3c8e0a.zip
cancel_test() returns "soft"/"hard" instead of true
-rw-r--r--CHANGES1
-rw-r--r--docs/index.html23
-rw-r--r--src/cancel.cpp6
-rw-r--r--unit_tests/scripts/lane/cooperative_shutdown.lua1
4 files changed, 23 insertions, 8 deletions
diff --git a/CHANGES b/CHANGES
index ccfa923..4dc9d2d 100644
--- a/CHANGES
+++ b/CHANGES
@@ -38,6 +38,7 @@ CHANGE 2: BGe 27-Nov-24
38 - Returns nil, error in case of problem. 38 - Returns nil, error in case of problem.
39 - Forces lane function body must return a non-nil first value on success because of the above. 39 - Forces lane function body must return a non-nil first value on success because of the above.
40 - lane:get_debug_threadname() renamed get_threadname(). 40 - lane:get_debug_threadname() renamed get_threadname().
41 - cancel_test() returns "soft"/"hard" instead of true when a cancellation request is active
41 - Lindas: 42 - Lindas:
42 - lanes.linda() 43 - lanes.linda()
43 - Arguments can be provided in any order. 44 - Arguments can be provided in any order.
diff --git a/docs/index.html b/docs/index.html
index e3e8c7a..e3fbd0b 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -71,7 +71,7 @@
71 </p> 71 </p>
72 72
73 <p> 73 <p>
74 This document was revised on 21-Apr-25, and applies to version <tt>4.0.0</tt>. 74 This document was revised on 23-Apr-25, and applies to version <tt>4.0.0</tt>.
75 </p> 75 </p>
76 </font> 76 </font>
77 </center> 77 </center>
@@ -215,6 +215,7 @@
215 <li> 215 <li>
216 Inside the lane 216 Inside the lane
217 <ul> 217 <ul>
218 <li><tt>cancel_test()</tt>: check for cancellation requests</li>
218 <li><tt>lane_threadname()</tt>: read or change the name of the thread</li> 219 <li><tt>lane_threadname()</tt>: read or change the name of the thread</li>
219 <li><tt>set_finalizer()</tt>: install a function called when the lane exits</li> 220 <li><tt>set_finalizer()</tt>: install a function called when the lane exits</li>
220 </ul> 221 </ul>
@@ -1222,26 +1223,36 @@
1222 First argument is a <tt>mode</tt>. It can be one of: 1223 First argument is a <tt>mode</tt>. It can be one of:
1223 <ul> 1224 <ul>
1224 <li> 1225 <li>
1225 <tt>"soft"</tt>: Cancellation will only cause <tt>cancel_test()</tt> to return <tt>true</tt>, so that the lane can cleanup manually. 1226 <tt>"soft"</tt>: Cancellation will only cause <tt>cancel_test()</tt> to return <tt>"soft"</tt>, so that the lane can cleanup manually.
1226 <br /> 1227 <br />
1227 Lindas will also check for cancellation inside blocking calls to early out based on their <tt>wake_period</tt>. 1228 Lindas will also check for cancellation inside blocking calls to early out based on their <tt>wake_period</tt>.
1228 </li> 1229 </li>
1229 <li> 1230 <li>
1230 <tt>"hard"</tt>: waits for the request to be processed, or a timeout to occur. <a href="#lindas">linda</a> operations detecting the cancellation request will raise a special cancellation error (meaning they won't return in that case).<br /> 1231 <tt>"hard"</tt>: waits for the request to be processed, or a timeout to occur. <a href="#lindas">linda</a> operations detecting the cancellation request will raise a special cancellation error (meaning they won't return in that case).
1232 <br />
1233 If the lane isn't actually waiting on a Linda when the request is issued, a lane calling <tt>cancel_test()</tt> will see it return <tt>"hard"</tt>.
1234 <br />
1231 <tt>wake_lane</tt> defaults to <tt>true</tt>, and <tt>timeout</tt> defaults to 0 if not specified. 1235 <tt>wake_lane</tt> defaults to <tt>true</tt>, and <tt>timeout</tt> defaults to 0 if not specified.
1232 </li> 1236 </li>
1233 <li> 1237 <li>
1234 <tt>"call"</tt>, <tt>"ret"</tt>, <tt>"line"</tt>, <tt>"count"</tt>: Asynchronously install the corresponding hook, then behave as <tt>"hard"</tt>. 1238 <tt>"call"</tt>, <tt>"ret"</tt>, <tt>"line"</tt>, <tt>"count"</tt>: Asynchronously install the corresponding hook, then behave as <tt>"hard"</tt>.
1239 <br />
1240 If the lane has the opportunity to call <tt>cancel_test()</tt> before the hook is invoked, calling <tt>cancel_test()</tt> will see it return <tt>"hard"</tt>.
1235 </li> 1241 </li>
1236 <li> 1242 <li>
1237 <tt>"all"</tt>: Installs all hooks in one shot, just to be sure. 1243 <tt>"all"</tt>: Installs all hooks in one shot, just to be sure.
1238 </li> 1244 </li>
1239 </ul> 1245 </ul>
1240 If <tt>mode</tt> is not specified, it defaults to <tt>"hard"</tt>. 1246 <p>
1247 If <tt>mode</tt> is not specified, it defaults to <tt>"hard"</tt>.
1248 </p>
1249</p>
1250<p>
1241 If <tt>wake_lane</tt> is <tt>true</tt>, the lane is also signalled so that execution returns from any pending <a href="#lindas">linda</a> operation. <a href="#lindas">linda</a> operations detecting the cancellation request return <tt>lanes.cancel_error</tt>. 1251 If <tt>wake_lane</tt> is <tt>true</tt>, the lane is also signalled so that execution returns from any pending <a href="#lindas">linda</a> operation. <a href="#lindas">linda</a> operations detecting the cancellation request return <tt>lanes.cancel_error</tt>.
1242</p> 1252</p>
1243<tt>timeout</tt> is an optional number &gt= 0. Defaults to infinite if left unspecified or <tt>nil</tt>. 1253<p>
1244<br /> 1254 <tt>timeout</tt> is an optional number &gt= 0. Defaults to infinite if left unspecified or <tt>nil</tt>.
1255</p>
1245<p> 1256<p>
1246 If the lane is still running after the timeout expired, there is a chance lanes will freeze forever at shutdown when failing to terminate all free-running lanes within the specified timeout. 1257 If the lane is still running after the timeout expired, there is a chance lanes will freeze forever at shutdown when failing to terminate all free-running lanes within the specified timeout.
1247</p> 1258</p>
diff --git a/src/cancel.cpp b/src/cancel.cpp
index 5bba9fc..ec9b6e4 100644
--- a/src/cancel.cpp
+++ b/src/cancel.cpp
@@ -133,7 +133,11 @@ static CancelOp WhichCancelOp(lua_State* const L_, StackIndex const idx_)
133LUAG_FUNC(cancel_test) 133LUAG_FUNC(cancel_test)
134{ 134{
135 CancelRequest const _test{ CheckCancelRequest(L_) }; 135 CancelRequest const _test{ CheckCancelRequest(L_) };
136 lua_pushboolean(L_, _test != CancelRequest::None); 136 if (_test == CancelRequest::None) {
137 lua_pushboolean(L_, 0);
138 } else {
139 luaG_pushstring(L_, (_test == CancelRequest::Soft) ? "soft" : "hard");
140 }
137 return 1; 141 return 1;
138} 142}
139 143
diff --git a/unit_tests/scripts/lane/cooperative_shutdown.lua b/unit_tests/scripts/lane/cooperative_shutdown.lua
index 756e33c..0e30f91 100644
--- a/unit_tests/scripts/lane/cooperative_shutdown.lua
+++ b/unit_tests/scripts/lane/cooperative_shutdown.lua
@@ -23,7 +23,6 @@ end
23local lane3 = function() 23local lane3 = function()
24 lane_threadname("lane3") 24 lane_threadname("lane3")
25 -- this one cooperates too, because of the hook cancellation modes that Lanes will be using 25 -- this one cooperates too, because of the hook cancellation modes that Lanes will be using
26 -- but not with LuaJIT, because the function is compiled, and we don't call anyone, so no hook triggers
27 local fixture = require "fixture" 26 local fixture = require "fixture"
28 repeat until fixture.give_me_back(false) 27 repeat until fixture.give_me_back(false)
29end 28end