From 7f8e51505e6fec4d37e83cdca1b93537146fc910 Mon Sep 17 00:00:00 2001 From: Parth Nobel Date: Fri, 19 Jun 2026 11:49:15 -0700 Subject: [PATCH] Adds thread-safety for parallel trees. --- CMakeLists.txt | 2 +- include/utils/tracked_alloc.h | 4 ++-- src/utils/tracked_alloc.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index edf246e..95143c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.15) project(DNLP_Diff_Engine C) -set(CMAKE_C_STANDARD 99) +set(CMAKE_C_STANDARD 11) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(DIFF_ENGINE_VERSION_MAJOR 0) diff --git a/include/utils/tracked_alloc.h b/include/utils/tracked_alloc.h index 50c3351..caf8e87 100644 --- a/include/utils/tracked_alloc.h +++ b/include/utils/tracked_alloc.h @@ -34,8 +34,8 @@ #define TRACKED_BLOCK_SIZE(p) malloc_usable_size(p) #endif -extern size_t g_allocated_bytes; /* current live bytes */ -extern size_t g_peak_bytes; /* high-water mark since last reset */ +extern _Thread_local size_t g_allocated_bytes; /* current live bytes */ +extern _Thread_local size_t g_peak_bytes; /* high-water mark since last reset */ /* All allocations in src/ must go through these wrappers (and pair sp_free with sp_malloc / sp_calloc). Tests may use plain malloc/free — those diff --git a/src/utils/tracked_alloc.c b/src/utils/tracked_alloc.c index 9b0f4d8..cba8e45 100644 --- a/src/utils/tracked_alloc.c +++ b/src/utils/tracked_alloc.c @@ -17,5 +17,5 @@ */ #include "utils/tracked_alloc.h" -size_t g_allocated_bytes = 0; -size_t g_peak_bytes = 0; +_Thread_local size_t g_allocated_bytes = 0; +_Thread_local size_t g_peak_bytes = 0;