summaryrefslogtreecommitdiff
path: root/threading.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'threading.cpp')
-rw-r--r--threading.cpp20
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;
}
}