2025-05-26 00:44:39 -05:00
|
|
|
#include "node.hpp"
|
2023-04-23 23:33:48 -04:00
|
|
|
|
2025-10-27 20:58:06 -05:00
|
|
|
#include <mutex>
|
|
|
|
|
|
2025-10-25 18:21:18 -05:00
|
|
|
#include <cstddef>
|
|
|
|
|
#include <cstdlib>
|
2023-04-23 23:33:48 -04:00
|
|
|
|
2025-10-25 18:21:18 -05:00
|
|
|
struct stack_t
|
2023-04-23 23:33:48 -04:00
|
|
|
{
|
2025-10-25 18:21:18 -05:00
|
|
|
stack_t *next;
|
|
|
|
|
};
|
2023-04-23 23:33:48 -04:00
|
|
|
|
2025-10-25 18:21:18 -05:00
|
|
|
thread_local static stack_t *g_stack = NULL;
|
2025-10-26 14:53:46 -05:00
|
|
|
thread_local bool gc = false;
|
2025-10-27 21:00:21 -05:00
|
|
|
thread_local bool g_initialized = false;
|
2023-04-23 23:33:48 -04:00
|
|
|
|
2025-05-26 00:44:39 -05:00
|
|
|
node_t*
|
2023-04-23 23:33:48 -04:00
|
|
|
node_alloc()
|
|
|
|
|
{
|
2025-10-25 18:21:18 -05:00
|
|
|
if(g_stack == NULL)
|
|
|
|
|
return (node_t*)calloc(1,sizeof(node_t));
|
2023-04-23 23:33:48 -04:00
|
|
|
|
2025-10-25 18:21:18 -05:00
|
|
|
node_t *node;
|
2023-04-23 23:33:48 -04:00
|
|
|
|
2025-10-25 18:21:18 -05:00
|
|
|
node = (node_t*)g_stack;
|
|
|
|
|
g_stack = g_stack->next;
|
|
|
|
|
|
|
|
|
|
return node;
|
2023-04-23 23:33:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2025-10-25 18:21:18 -05:00
|
|
|
node_free(node_t *node_)
|
2023-04-23 23:33:48 -04:00
|
|
|
{
|
2025-10-25 18:21:18 -05:00
|
|
|
stack_t *stack;
|
2023-04-23 23:33:48 -04:00
|
|
|
|
2025-10-25 18:21:18 -05:00
|
|
|
stack = (stack_t*)node_;
|
|
|
|
|
stack->next = g_stack;
|
|
|
|
|
g_stack = stack;
|
2023-04-23 23:33:48 -04:00
|
|
|
}
|