From 313ca58550163380e072880b360bc6076d27c8e5 Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Wed, 27 Jul 2022 15:46:42 -0400 Subject: switched threading to SDL; works on windows now --- threading.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'threading.cpp') diff --git a/threading.cpp b/threading.cpp index 39e7b75..1b89136 100644 --- a/threading.cpp +++ b/threading.cpp @@ -1,26 +1,30 @@ internal void PushRect(rectangle RenderRegion) { - render_entry *Entry = Entries + EntryCount; + uint32 Q = SDL_AtomicGet(&QueuedEntries); + render_entry *Entry = Entries + Q; Entry->RenderRegion = RenderRegion; - __atomic_add_fetch(&EntryCount, 1, __ATOMIC_ACQ_REL); + SDL_AtomicAdd(&QueuedEntries, 1); SDL_SemPost(Semaphore); } +internal void +RenderLayers(render_queue *RenderInfo, rectangle RenderRegion); internal bool32 CheckQueue(render_queue RenderInfo, uint16 Index) { bool32 Result = 0; - uint32 OriginalEntry = NextEntryToDo; - if (NextEntryToDo < EntryCount) + uint32 Q = SDL_AtomicGet(&QueuedEntries); + uint32 C = SDL_AtomicGet(&CurrentEntry); + if (Q > C) { - if (__atomic_compare_exchange_n(&NextEntryToDo, &OriginalEntry, NextEntryToDo + 1, true, __ATOMIC_RELEASE, __ATOMIC_ACQUIRE)) { - render_entry *Entry = Entries + OriginalEntry; + if (SDL_AtomicCAS(&CurrentEntry, C, C + 1)) { + render_entry *Entry = Entries + C; Assert(Entry->RenderRegion.Max.x != 0); - RenderLayers(RenderInfo, Entry->RenderRegion); + RenderLayers(&RenderInfo, Entry->RenderRegion); // printf("(FINISHED) Thread %i, region X%i Y%i\n", Index, Entry->RenderRegion.Min.x/240, Entry->RenderRegion.Min.y/135); - __atomic_add_fetch(&CompletedJobs, 1, __ATOMIC_ACQ_REL); + SDL_AtomicAdd(&CompletedEntries, 1); Result = 1; } } -- cgit v1.2.3