aboutsummaryrefslogtreecommitdiff
path: root/src/cancel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/cancel.cpp')
-rw-r--r--src/cancel.cpp70
1 files changed, 35 insertions, 35 deletions
diff --git a/src/cancel.cpp b/src/cancel.cpp
index 8356169..b297c85 100644
--- a/src/cancel.cpp
+++ b/src/cancel.cpp
@@ -51,9 +51,9 @@ THE SOFTWARE.
51 */ 51 */
52[[nodiscard]] static inline CancelRequest cancel_test(lua_State* L_) 52[[nodiscard]] static inline CancelRequest cancel_test(lua_State* L_)
53{ 53{
54 Lane* const lane{ kLanePointerRegKey.readLightUserDataValue<Lane>(L_) }; 54 Lane* const _lane{ kLanePointerRegKey.readLightUserDataValue<Lane>(L_) };
55 // 'lane' is nullptr for the original main state (and no-one can cancel that) 55 // 'lane' is nullptr for the original main state (and no-one can cancel that)
56 return lane ? lane->cancelRequest : CancelRequest::None; 56 return _lane ? _lane->cancelRequest : CancelRequest::None;
57} 57}
58 58
59// ################################################################################################# 59// #################################################################################################
@@ -66,8 +66,8 @@ THE SOFTWARE.
66// 66//
67LUAG_FUNC(cancel_test) 67LUAG_FUNC(cancel_test)
68{ 68{
69 CancelRequest test{ cancel_test(L_) }; 69 CancelRequest _test{ cancel_test(L_) };
70 lua_pushboolean(L_, test != CancelRequest::None); 70 lua_pushboolean(L_, _test != CancelRequest::None);
71 return 1; 71 return 1;
72} 72}
73 73
@@ -110,9 +110,9 @@ LUAG_FUNC(cancel_test)
110 lane_->cancelRequest = CancelRequest::Soft; // it's now signaled to stop 110 lane_->cancelRequest = CancelRequest::Soft; // it's now signaled to stop
111 // negative timeout: we don't want to truly abort the lane, we just want it to react to cancel_test() on its own 111 // negative timeout: we don't want to truly abort the lane, we just want it to react to cancel_test() on its own
112 if (wakeLane_) { // wake the thread so that execution returns from any pending linda operation if desired 112 if (wakeLane_) { // wake the thread so that execution returns from any pending linda operation if desired
113 std::condition_variable* const waiting_on{ lane_->waiting_on }; 113 std::condition_variable* const _waiting_on{ lane_->waiting_on };
114 if (lane_->status == Lane::Waiting && waiting_on != nullptr) { 114 if (lane_->status == Lane::Waiting && _waiting_on != nullptr) {
115 waiting_on->notify_all(); 115 _waiting_on->notify_all();
116 } 116 }
117 } 117 }
118 118
@@ -126,9 +126,9 @@ LUAG_FUNC(cancel_test)
126 lane_->cancelRequest = CancelRequest::Hard; // it's now signaled to stop 126 lane_->cancelRequest = CancelRequest::Hard; // it's now signaled to stop
127 // lane_->thread.get_stop_source().request_stop(); 127 // lane_->thread.get_stop_source().request_stop();
128 if (wakeLane_) { // wake the thread so that execution returns from any pending linda operation if desired 128 if (wakeLane_) { // wake the thread so that execution returns from any pending linda operation if desired
129 std::condition_variable* waiting_on = lane_->waiting_on; 129 std::condition_variable* const _waiting_on{ lane_->waiting_on };
130 if (lane_->status == Lane::Waiting && waiting_on != nullptr) { 130 if (lane_->status == Lane::Waiting && _waiting_on != nullptr) {
131 waiting_on->notify_all(); 131 _waiting_on->notify_all();
132 } 132 }
133 } 133 }
134 134
@@ -163,21 +163,21 @@ CancelResult thread_cancel(Lane* lane_, CancelOp op_, int hookCount_, std::chron
163 163
164CancelOp which_cancel_op(char const* opString_) 164CancelOp which_cancel_op(char const* opString_)
165{ 165{
166 CancelOp op{ CancelOp::Invalid }; 166 CancelOp _op{ CancelOp::Invalid };
167 if (strcmp(opString_, "hard") == 0) { 167 if (strcmp(opString_, "hard") == 0) {
168 op = CancelOp::Hard; 168 _op = CancelOp::Hard;
169 } else if (strcmp(opString_, "soft") == 0) { 169 } else if (strcmp(opString_, "soft") == 0) {
170 op = CancelOp::Soft; 170 _op = CancelOp::Soft;
171 } else if (strcmp(opString_, "call") == 0) { 171 } else if (strcmp(opString_, "call") == 0) {
172 op = CancelOp::MaskCall; 172 _op = CancelOp::MaskCall;
173 } else if (strcmp(opString_, "ret") == 0) { 173 } else if (strcmp(opString_, "ret") == 0) {
174 op = CancelOp::MaskRet; 174 _op = CancelOp::MaskRet;
175 } else if (strcmp(opString_, "line") == 0) { 175 } else if (strcmp(opString_, "line") == 0) {
176 op = CancelOp::MaskLine; 176 _op = CancelOp::MaskLine;
177 } else if (strcmp(opString_, "count") == 0) { 177 } else if (strcmp(opString_, "count") == 0) {
178 op = CancelOp::MaskCount; 178 _op = CancelOp::MaskCount;
179 } 179 }
180 return op; 180 return _op;
181} 181}
182 182
183// ################################################################################################# 183// #################################################################################################
@@ -185,13 +185,13 @@ CancelOp which_cancel_op(char const* opString_)
185[[nodiscard]] static CancelOp which_cancel_op(lua_State* L_, int idx_) 185[[nodiscard]] static CancelOp which_cancel_op(lua_State* L_, int idx_)
186{ 186{
187 if (lua_type(L_, idx_) == LUA_TSTRING) { 187 if (lua_type(L_, idx_) == LUA_TSTRING) {
188 char const* const str{ lua_tostring(L_, idx_) }; 188 char const* const _str{ lua_tostring(L_, idx_) };
189 CancelOp op{ which_cancel_op(str) }; 189 CancelOp _op{ which_cancel_op(_str) };
190 lua_remove(L_, idx_); // argument is processed, remove it 190 lua_remove(L_, idx_); // argument is processed, remove it
191 if (op == CancelOp::Invalid) { 191 if (_op == CancelOp::Invalid) {
192 raise_luaL_error(L_, "invalid hook option %s", str); 192 raise_luaL_error(L_, "invalid hook option %s", _str);
193 } 193 }
194 return op; 194 return _op;
195 } 195 }
196 return CancelOp::Hard; 196 return CancelOp::Hard;
197} 197}
@@ -201,23 +201,23 @@ CancelOp which_cancel_op(char const* opString_)
201// bool[,reason] = lane_h:cancel( [mode, hookcount] [, timeout] [, wake_lane]) 201// bool[,reason] = lane_h:cancel( [mode, hookcount] [, timeout] [, wake_lane])
202LUAG_FUNC(thread_cancel) 202LUAG_FUNC(thread_cancel)
203{ 203{
204 Lane* const lane{ ToLane(L_, 1) }; 204 Lane* const _lane{ ToLane(L_, 1) };
205 CancelOp const op{ which_cancel_op(L_, 2) }; // this removes the op string from the stack 205 CancelOp const _op{ which_cancel_op(L_, 2) }; // this removes the op string from the stack
206 206
207 int hook_count{ 0 }; 207 int _hook_count{ 0 };
208 if (static_cast<int>(op) > static_cast<int>(CancelOp::Soft)) { // hook is requested 208 if (static_cast<int>(_op) > static_cast<int>(CancelOp::Soft)) { // hook is requested
209 hook_count = static_cast<int>(luaL_checkinteger(L_, 2)); 209 _hook_count = static_cast<int>(luaL_checkinteger(L_, 2));
210 lua_remove(L_, 2); // argument is processed, remove it 210 lua_remove(L_, 2); // argument is processed, remove it
211 if (hook_count < 1) { 211 if (_hook_count < 1) {
212 raise_luaL_error(L_, "hook count cannot be < 1"); 212 raise_luaL_error(L_, "hook count cannot be < 1");
213 } 213 }
214 } 214 }
215 215
216 std::chrono::time_point<std::chrono::steady_clock> until{ std::chrono::time_point<std::chrono::steady_clock>::max() }; 216 std::chrono::time_point<std::chrono::steady_clock> _until{ std::chrono::time_point<std::chrono::steady_clock>::max() };
217 if (lua_type(L_, 2) == LUA_TNUMBER) { // we don't want to use lua_isnumber() because of autocoercion 217 if (lua_type(L_, 2) == LUA_TNUMBER) { // we don't want to use lua_isnumber() because of autocoercion
218 lua_Duration const duration{ lua_tonumber(L_, 2) }; 218 lua_Duration const duration{ lua_tonumber(L_, 2) };
219 if (duration.count() >= 0.0) { 219 if (duration.count() >= 0.0) {
220 until = std::chrono::steady_clock::now() + std::chrono::duration_cast<std::chrono::steady_clock::duration>(duration); 220 _until = std::chrono::steady_clock::now() + std::chrono::duration_cast<std::chrono::steady_clock::duration>(duration);
221 } else { 221 } else {
222 raise_luaL_argerror(L_, 2, "duration cannot be < 0"); 222 raise_luaL_argerror(L_, 2, "duration cannot be < 0");
223 } 223 }
@@ -227,16 +227,16 @@ LUAG_FUNC(thread_cancel)
227 } 227 }
228 228
229 // we wake by default in "hard" mode (remember that hook is hard too), but this can be turned off if desired 229 // we wake by default in "hard" mode (remember that hook is hard too), but this can be turned off if desired
230 bool wake_lane{ op != CancelOp::Soft }; 230 bool _wake_lane{ _op != CancelOp::Soft };
231 if (lua_gettop(L_) >= 2) { 231 if (lua_gettop(L_) >= 2) {
232 if (!lua_isboolean(L_, 2)) { 232 if (!lua_isboolean(L_, 2)) {
233 raise_luaL_error(L_, "wake_lindas parameter is not a boolean"); 233 raise_luaL_error(L_, "wake_lindas parameter is not a boolean");
234 } 234 }
235 wake_lane = lua_toboolean(L_, 2); 235 _wake_lane = lua_toboolean(L_, 2);
236 lua_remove(L_, 2); // argument is processed, remove it 236 lua_remove(L_, 2); // argument is processed, remove it
237 } 237 }
238 STACK_CHECK_START_REL(L_, 0); 238 STACK_CHECK_START_REL(L_, 0);
239 switch (thread_cancel(lane, op, hook_count, until, wake_lane)) { 239 switch (thread_cancel(_lane, _op, _hook_count, _until, _wake_lane)) {
240 default: // should never happen unless we added a case and forgot to handle it 240 default: // should never happen unless we added a case and forgot to handle it
241 LUA_ASSERT(L_, false); 241 LUA_ASSERT(L_, false);
242 break; 242 break;
@@ -248,7 +248,7 @@ LUAG_FUNC(thread_cancel)
248 248
249 case CancelResult::Cancelled: 249 case CancelResult::Cancelled:
250 lua_pushboolean(L_, 1); // true 250 lua_pushboolean(L_, 1); // true
251 lane->pushThreadStatus(L_); // true status 251 _lane->pushThreadStatus(L_); // true status
252 break; 252 break;
253 } 253 }
254 STACK_CHECK(L_, 2); 254 STACK_CHECK(L_, 2);