aboutsummaryrefslogtreecommitdiff
path: root/src/keeper.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/keeper.h')
-rw-r--r--src/keeper.h82
1 files changed, 42 insertions, 40 deletions
diff --git a/src/keeper.h b/src/keeper.h
index 7c55809..627c7ea 100644
--- a/src/keeper.h
+++ b/src/keeper.h
@@ -1,58 +1,60 @@
1#if !defined( __keeper_h__) 1#pragma once
2#define __keeper_h__ 1
3 2
3#ifdef __cplusplus
4extern "C" {
5#endif // __cplusplus
4#include "lua.h" 6#include "lua.h"
7#ifdef __cplusplus
8}
9#endif // __cplusplus
10
5#include "threading.h" 11#include "threading.h"
6#include "uniquekey.h" 12#include "uniquekey.h"
7 13
14#include <mutex>
15
8// forwards 16// forwards
9struct s_Universe; 17enum class LookupMode;
10typedef struct s_Universe Universe; 18class Universe;
11enum eLookupMode;
12typedef enum eLookupMode LookupMode;
13 19
14struct s_Keeper 20struct Keeper
15{ 21{
16 MUTEX_T keeper_cs; 22 std::mutex m_mutex;
17 lua_State* L; 23 lua_State* L{ nullptr };
18 //int count; 24 // int count;
19}; 25};
20typedef struct s_Keeper Keeper;
21 26
22struct s_Keepers 27struct Keepers
23{ 28{
24 int gc_threshold; 29 int gc_threshold{ 0 };
25 int nb_keepers; 30 int nb_keepers{ 0 };
26 Keeper keeper_array[1]; 31 Keeper keeper_array[1];
27}; 32};
28typedef struct s_Keepers Keepers;
29 33
30void init_keepers( Universe* U, lua_State* L); 34static constexpr uintptr_t KEEPER_MAGIC_SHIFT{ 3 };
31void close_keepers( Universe* U); 35// crc64/we of string "NIL_SENTINEL" generated at http://www.nitrxgen.net/hashgen/
36static constexpr UniqueKey NIL_SENTINEL{ 0x7eaafa003a1d11a1ull };
32 37
33Keeper* which_keeper( Keepers* keepers_, uintptr_t magic_); 38void init_keepers(Universe* U, lua_State* L);
34Keeper* keeper_acquire( Keepers* keepers_, uintptr_t magic_); 39void close_keepers(Universe* U);
35#define KEEPER_MAGIC_SHIFT 3
36void keeper_release( Keeper* K_);
37void keeper_toggle_nil_sentinels( lua_State* L, int val_i_, LookupMode const mode_);
38int keeper_push_linda_storage( Universe* U, lua_State* L, void* ptr_, uintptr_t magic_);
39 40
40// crc64/we of string "NIL_SENTINEL" generated at http://www.nitrxgen.net/hashgen/ 41[[nodiscard]] Keeper* which_keeper(Keepers* keepers_, uintptr_t magic_);
41static DECLARE_CONST_UNIQUE_KEY( NIL_SENTINEL, 0x7eaafa003a1d11a1); 42[[nodiscard]] Keeper* keeper_acquire(Keepers* keepers_, uintptr_t magic_);
43void keeper_release(Keeper* K_);
44void keeper_toggle_nil_sentinels(lua_State* L, int val_i_, LookupMode const mode_);
45[[nodiscard]] int keeper_push_linda_storage(Universe* U, Dest L, void* ptr_, uintptr_t magic_);
42 46
43typedef lua_CFunction keeper_api_t; 47using keeper_api_t = lua_CFunction;
44#define KEEPER_API( _op) keepercall_ ## _op 48#define KEEPER_API(_op) keepercall_##_op
45#define PUSH_KEEPER_FUNC lua_pushcfunction 49#define PUSH_KEEPER_FUNC lua_pushcfunction
46// lua_Cfunctions to run inside a keeper state (formerly implemented in Lua) 50// lua_Cfunctions to run inside a keeper state
47int keepercall_clear( lua_State* L); 51[[nodiscard]] int keepercall_clear(lua_State* L);
48int keepercall_send( lua_State* L); 52[[nodiscard]] int keepercall_send(lua_State* L);
49int keepercall_receive( lua_State* L); 53[[nodiscard]] int keepercall_receive(lua_State* L);
50int keepercall_receive_batched( lua_State* L); 54[[nodiscard]] int keepercall_receive_batched(lua_State* L);
51int keepercall_limit( lua_State* L); 55[[nodiscard]] int keepercall_limit(lua_State* L);
52int keepercall_get( lua_State* L); 56[[nodiscard]] int keepercall_get(lua_State* L);
53int keepercall_set( lua_State* L); 57[[nodiscard]] int keepercall_set(lua_State* L);
54int keepercall_count( lua_State* L); 58[[nodiscard]] int keepercall_count(lua_State* L);
55 59
56int keeper_call( Universe* U, lua_State* K, keeper_api_t _func, lua_State* L, void* linda, uint_t starting_index); 60[[nodiscard]] int keeper_call(Universe* U, lua_State* K, keeper_api_t _func, lua_State* L, void* linda, int starting_index);
57
58#endif // __keeper_h__ \ No newline at end of file