diff --git a/core/hakmem_batch.c b/core/hakmem_batch.c index f8fb0377..03d4cd76 100644 --- a/core/hakmem_batch.c +++ b/core/hakmem_batch.c @@ -10,6 +10,7 @@ #include "hakmem_batch.h" #include "hakmem_sys.h" // Phase 6.11.1: Syscall wrappers with timing #include "hakmem_whale.h" // Phase 6.11.1: Whale fast-path cache +#include "hakmem_env_cache.h" // Priority-2: ENV cache #include #include #include @@ -70,8 +71,8 @@ void hak_batch_init(void) { g_immediate_dontneed = 0; // Background worker toggle - const char* e_bg = getenv("HAKMEM_BATCH_BG"); - if (e_bg) g_bg_enabled = (atoi(e_bg) != 0); + // Priority-2: Use cached ENV + g_bg_enabled = HAK_ENV_BATCH_BG(); // Sync primitives pthread_mutex_init(&g_batch_mu, NULL); diff --git a/core/hakmem_env_cache.h b/core/hakmem_env_cache.h index 6b14b0ff..103078a2 100644 --- a/core/hakmem_env_cache.h +++ b/core/hakmem_env_cache.h @@ -87,6 +87,9 @@ typedef struct { // ===== Cold Path: Debug/Timing (1 variable) ===== int timing_enabled; // HAKMEM_TIMING (default: 0) + // ===== Cold Path: Batch (1 variable) ===== + int batch_bg; // HAKMEM_BATCH_BG (default: 0) + } HakEnvCache; // Global cache instance (initialized once at startup) @@ -278,10 +281,17 @@ static inline void hakmem_env_cache_init(void) { g_hak_env_cache.timing_enabled = (e && strcmp(e, "1") == 0) ? 1 : 0; // default: 0 (OFF) } + // ===== Cold Path: Batch ===== + { + const char* e; + e = getenv("HAKMEM_BATCH_BG"); + g_hak_env_cache.batch_bg = (e && atoi(e) != 0) ? 1 : 0; // default: 0 (OFF) + } + #if !HAKMEM_BUILD_RELEASE // Debug: Print cache summary (stderr only) if (!g_hak_env_cache.quiet) { - fprintf(stderr, "[ENV_CACHE_INIT] Parsed %d ENV variables at startup\n", 48); + fprintf(stderr, "[ENV_CACHE_INIT] Parsed %d ENV variables at startup\n", 49); fprintf(stderr, "[ENV_CACHE_INIT] Hot path syscalls eliminated: ~2000/sec → 0/sec\n"); fflush(stderr); } @@ -347,4 +357,7 @@ static inline void hakmem_env_cache_init(void) { // Cold path: Debug/Timing #define HAK_ENV_TIMING_ENABLED() (g_hak_env_cache.timing_enabled) +// Cold path: Batch +#define HAK_ENV_BATCH_BG() (g_hak_env_cache.batch_bg) + #endif // HAKMEM_ENV_CACHE_H