diff options
author | Fox Caminiti <fox@foxcam.net> | 2022-07-27 15:46:42 -0400 |
---|---|---|
committer | Fox Caminiti <fox@foxcam.net> | 2022-07-27 15:46:42 -0400 |
commit | 313ca58550163380e072880b360bc6076d27c8e5 (patch) | |
tree | 899c945440a804711a33b34c5407ae8d789dc6c2 /threading.cpp | |
parent | 83ce428d8bb5f4a762abf879adec076bc34cf36a (diff) |
switched threading to SDL; works on windows now
Diffstat (limited to 'threading.cpp')
-rw-r--r-- | threading.cpp | 20 |
1 files changed, 12 insertions, 8 deletions
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; } } |