mergerfs/libfuse/lib/node.cpp

56 lines
877 B
C++
Raw Normal View History

#include "node.hpp"
2025-10-27 20:58:06 -05:00
#include <mutex>
2025-10-27 21:39:29 -05:00
#include <vector>
2025-10-27 20:58:06 -05:00
2025-10-25 18:21:18 -05:00
#include <cstddef>
#include <cstdlib>
2025-10-25 18:21:18 -05:00
struct stack_t
{
2025-10-25 18:21:18 -05:00
stack_t *next;
};
2025-10-27 21:40:22 -05:00
struct StackInfo
2025-10-27 21:39:29 -05:00
{
2025-10-27 21:46:04 -05:00
stack_t *stack;
bool *should_gc;
2025-10-27 21:39:29 -05:00
};
2025-10-27 21:00:38 -05:00
thread_local static stack_t *g_stack = NULL;
thread_local bool g_should_gc = false;
thread_local bool g_initialized = false;
2025-10-27 21:37:59 -05:00
static std::mutex g_mutex;
2025-10-27 21:40:18 -05:00
static std::vector<StackInfo> g_all_stacks;
node_t*
node_alloc()
{
2025-10-27 21:41:56 -05:00
if(g_initialized == false)
{
std::lock_guard<std::mutex> guard(g_mutex);
2025-10-27 21:50:10 -05:00
g_all_stacks.push_back({g_stack,&g_should_gc});
2025-10-27 21:41:56 -05:00
}
2025-10-25 18:21:18 -05:00
if(g_stack == NULL)
return (node_t*)calloc(1,sizeof(node_t));
2025-10-25 18:21:18 -05:00
node_t *node;
2025-10-25 18:21:18 -05:00
node = (node_t*)g_stack;
g_stack = g_stack->next;
return node;
}
void
2025-10-25 18:21:18 -05:00
node_free(node_t *node_)
{
2025-10-25 18:21:18 -05:00
stack_t *stack;
2025-10-25 18:21:18 -05:00
stack = (stack_t*)node_;
stack->next = g_stack;
g_stack = stack;
}