From a95141111c89803347c36501185a76fc73a9764a Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Fri, 5 May 2023 09:39:13 +0200 Subject: Fixed a bug in hot page global storage The original algorithm was suffering from an ABA race condition: A: fp = page_stack B: completely allocates the same page and writes into it some data A: unsuspecting, loads (invalid) next = fp->next B: finishes working with the page and returns it back to page_stack A: compare-exchange page_stack: fp => next succeeds and writes garbage to page_stack Fixed this by using an implicit spinlock in hot page allocator. --- lib/birdlib.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/birdlib.h') diff --git a/lib/birdlib.h b/lib/birdlib.h index 9132fb93..2eec5c0f 100644 --- a/lib/birdlib.h +++ b/lib/birdlib.h @@ -183,7 +183,11 @@ void bug(const char *msg, ...) NORET; void debug(const char *msg, ...); /* Printf to debug output */ void debug_safe(const char *msg); /* Printf to debug output, async-safe */ +/* Internal thread ID, useful for logging */ +extern _Atomic uint max_thread_id; extern _Thread_local uint this_thread_id; +#define THIS_THREAD_ID (this_thread_id ?: (this_thread_id = atomic_fetch_add_explicit(&max_thread_id, 1, memory_order_acq_rel))) + /* Debugging */ -- cgit v1.2.3