From c016b8ccccc7e0353403c299f0cb845fc4c5062a Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Sun, 10 Oct 2021 11:03:22 -0700 Subject: [PATCH] [examples] fix indexing bug in multi threaded example; make the intrinsic work with clang too --- examples/integration/multi_threaded.c | 10 ++++++---- examples/intro/sets.mdesk | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/integration/multi_threaded.c b/examples/integration/multi_threaded.c index ff6446e..e78471e 100644 --- a/examples/integration/multi_threaded.c +++ b/examples/integration/multi_threaded.c @@ -13,8 +13,10 @@ //~ multi-threaded parse setup //////////////////////////////////////////////// -#if MD_COMPILER_CL -# define atomic_inc_u64(p) InterlockedIncrement64((LONG64*)p) +// for this intrinsic we're assume pre-increment behavior + +#if MD_OS_WINDOWS +# define atomic_inc_then_eval_u64(p) InterlockedIncrement64((LONG64*)p) #else # error Not implemented for this compiler #endif @@ -42,7 +44,7 @@ parse_worker_loop(ThreadData *thread_data) TaskData *task = thread_data->task; for (;;) { - MD_u64 task_index = atomic_inc_u64(&task->task_counter); + MD_u64 task_index = atomic_inc_then_eval_u64(&task->task_counter) - 1; if (task_index >= task->task_max) { break; @@ -53,7 +55,7 @@ parse_worker_loop(ThreadData *thread_data) MD_PushNewReference(thread_data->arena, thread_data->list, parse.node); } - atomic_inc_u64(&task->thread_counter); + atomic_inc_then_eval_u64(&task->thread_counter); } #if MD_OS_WINDOWS diff --git a/examples/intro/sets.mdesk b/examples/intro/sets.mdesk index b23f6d4..5376e7f 100644 --- a/examples/intro/sets.mdesk +++ b/examples/intro/sets.mdesk @@ -95,6 +95,7 @@ baz: foo_again // undelimited sets may not contain unlabeled delimited sets // the following forms one undelimited set followed by a delimited set // the delimited set is a sibling to foo, not a child to foo. +// this also emits a warning because it's weird. foo: bar (baz) // undelimited sets *may* however contain labeled delimited sets