aboutsummaryrefslogtreecommitdiff
path: root/src/lanes_private.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lanes_private.h')
-rw-r--r--src/lanes_private.h45
1 files changed, 30 insertions, 15 deletions
diff --git a/src/lanes_private.h b/src/lanes_private.h
index 1530b9e..7c52876 100644
--- a/src/lanes_private.h
+++ b/src/lanes_private.h
@@ -4,40 +4,46 @@
4#include "cancel.h" 4#include "cancel.h"
5#include "universe.h" 5#include "universe.h"
6 6
7enum class ThreadStatus
8{
9 Normal, // normal master side state
10 Killed // issued an OS kill
11};
12
13// NOTE: values to be changed by either thread, during execution, without 7// NOTE: values to be changed by either thread, during execution, without
14// locking, are marked "volatile" 8// locking, are marked "volatile"
15// 9//
16struct Lane 10class Lane
17{ 11{
12 private:
13
14 enum class ThreadStatus
15 {
16 Normal, // normal master side state
17 Killed // issued an OS kill
18 };
19
20 public:
21
22 using enum ThreadStatus;
23
18 THREAD_T thread; 24 THREAD_T thread;
19 // 25 //
20 // M: sub-thread OS thread 26 // M: sub-thread OS thread
21 // S: not used 27 // S: not used
22 28
23 char const* debug_name; 29 char const* debug_name{ "<unnamed>" };
24 30
31 Universe* const U;
25 lua_State* L; 32 lua_State* L;
26 Universe* U;
27 // 33 //
28 // M: prepares the state, and reads results 34 // M: prepares the state, and reads results
29 // S: while S is running, M must keep out of modifying the state 35 // S: while S is running, M must keep out of modifying the state
30 36
31 volatile enum e_status status; 37 volatile enum e_status status{ PENDING };
32 // 38 //
33 // M: sets to PENDING (before launching) 39 // M: sets to PENDING (before launching)
34 // S: updates -> RUNNING/WAITING -> DONE/ERROR_ST/CANCELLED 40 // S: updates -> RUNNING/WAITING -> DONE/ERROR_ST/CANCELLED
35 41
36 SIGNAL_T* volatile waiting_on; 42 SIGNAL_T* volatile waiting_on{ nullptr };
37 // 43 //
38 // When status is WAITING, points on the linda's signal the thread waits on, else nullptr 44 // When status is WAITING, points on the linda's signal the thread waits on, else nullptr
39 45
40 volatile CancelRequest cancel_request; 46 volatile CancelRequest cancel_request{ CancelRequest::None };
41 // 47 //
42 // M: sets to false, flags true for cancel request 48 // M: sets to false, flags true for cancel request
43 // S: reads to see if cancel is requested 49 // S: reads to see if cancel is requested
@@ -54,22 +60,31 @@ struct Lane
54 // lane status changes to DONE/ERROR_ST/CANCELLED. 60 // lane status changes to DONE/ERROR_ST/CANCELLED.
55#endif // THREADWAIT_METHOD == THREADWAIT_CONDVAR 61#endif // THREADWAIT_METHOD == THREADWAIT_CONDVAR
56 62
57 volatile ThreadStatus mstatus; 63 volatile ThreadStatus mstatus{ Normal };
58 // 64 //
59 // M: sets to Normal, if issued a kill changes to Killed 65 // M: sets to Normal, if issued a kill changes to Killed
60 // S: not used 66 // S: not used
61 67
62 Lane* volatile selfdestruct_next; 68 Lane* volatile selfdestruct_next{ nullptr };
63 // 69 //
64 // M: sets to non-nullptr if facing lane handle '__gc' cycle but the lane 70 // M: sets to non-nullptr if facing lane handle '__gc' cycle but the lane
65 // is still running 71 // is still running
66 // S: cleans up after itself if non-nullptr at lane exit 72 // S: cleans up after itself if non-nullptr at lane exit
67 73
68#if HAVE_LANE_TRACKING() 74#if HAVE_LANE_TRACKING()
69 Lane* volatile tracking_next; 75 Lane* volatile tracking_next{ nullptr };
70#endif // HAVE_LANE_TRACKING() 76#endif // HAVE_LANE_TRACKING()
71 // 77 //
72 // For tracking only 78 // For tracking only
79
80 static void* operator new(size_t size_, Universe* U_) noexcept { return U_->internal_allocator.alloc(size_); }
81 // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception
82 static void operator delete(void* p_, Universe* U_) { U_->internal_allocator.free(p_, sizeof(Lane)); }
83 // this one is for us, to make sure memory is freed by the correct allocator
84 static void operator delete(void* p_) { static_cast<Lane*>(p_)->U->internal_allocator.free(p_, sizeof(Lane)); }
85
86 Lane(Universe* U_, lua_State* L_);
87 ~Lane();
73}; 88};
74 89
75// xxh64 of string "LANE_POINTER_REGKEY" generated at https://www.pelock.com/products/hash-calculator 90// xxh64 of string "LANE_POINTER_REGKEY" generated at https://www.pelock.com/products/hash-calculator