## Summary - ChatGPT により bench_profile.h の setenv segfault を修正(RTLD_NEXT 経由に切り替え) - core/box/pool_zero_mode_box.h 新設:ENV キャッシュ経由で ZERO_MODE を統一管理 - core/hakmem_pool.c で zero mode に応じた memset 制御(FULL/header/off) - A/B テスト結果:ZERO_MODE=header で +15.34% improvement(1M iterations, C6-heavy) ## Files Modified - core/box/pool_api.inc.h: pool_zero_mode_box.h include - core/bench_profile.h: glibc setenv → malloc+putenv(segfault 回避) - core/hakmem_pool.c: zero mode 参照・制御ロジック - core/box/pool_zero_mode_box.h (新設): enum/getter - CURRENT_TASK.md: Phase ML1 結果記載 ## Test Results | Iterations | ZERO_MODE=full | ZERO_MODE=header | Improvement | |-----------|----------------|-----------------|------------| | 10K | 3.06 M ops/s | 3.17 M ops/s | +3.65% | | 1M | 23.71 M ops/s | 27.34 M ops/s | **+15.34%** | 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
42 lines
1.2 KiB
C
42 lines
1.2 KiB
C
// log_once_box.h - Simple one-shot logging helpers (Box)
|
|
// Provides: lightweight, thread-safe "log once" primitives for stderr/write
|
|
// Used by: guard boxes that need single notification without spamming
|
|
#ifndef HAKMEM_LOG_ONCE_BOX_H
|
|
#define HAKMEM_LOG_ONCE_BOX_H
|
|
|
|
#include <stdatomic.h>
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <stdarg.h>
|
|
|
|
typedef struct {
|
|
_Atomic int logged;
|
|
} hak_log_once_t;
|
|
|
|
#define HAK_LOG_ONCE_INIT {0}
|
|
|
|
static inline bool hak_log_once_should_log(hak_log_once_t* flag, bool quiet) {
|
|
if (quiet) return false;
|
|
if (!flag) return true;
|
|
return atomic_exchange_explicit(&flag->logged, 1, memory_order_relaxed) == 0;
|
|
}
|
|
|
|
static inline void hak_log_once_write(hak_log_once_t* flag, bool quiet, int fd, const char* buf, size_t len) {
|
|
if (!buf) return;
|
|
if (!hak_log_once_should_log(flag, quiet)) return;
|
|
(void)write(fd, buf, len);
|
|
}
|
|
|
|
static inline void hak_log_once_fprintf(hak_log_once_t* flag, bool quiet, FILE* stream, const char* fmt, ...) {
|
|
if (!stream || !fmt) return;
|
|
if (!hak_log_once_should_log(flag, quiet)) return;
|
|
va_list ap;
|
|
va_start(ap, fmt);
|
|
(void)vfprintf(stream, fmt, ap);
|
|
va_end(ap);
|
|
}
|
|
|
|
#endif // HAKMEM_LOG_ONCE_BOX_H
|