[examples] fix indexing bug in multi threaded example; make the intrinsic work with clang too

This commit is contained in:
Allen Webster
2021-10-10 11:03:22 -07:00
parent f07b74da5f
commit c016b8cccc
2 changed files with 7 additions and 4 deletions
+6 -4
View File
@@ -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
+1
View File
@@ -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