diff options
| author | Antonis Geralis <[email protected]> | 2023-01-02 17:48:53 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-01-02 16:48:53 +0100 |
| commit | 1dbcce8b56933aa9983b81f33a2f6db64e93d5af (patch) | |
| tree | c112394845cf661f466d4be9efe8f0b0d448af87 /examples/core/core_loading_thread.c | |
| parent | 0ccc1d3686f7c9eeafd88c7385d908b23812231e (diff) | |
| download | raylib-1dbcce8b56933aa9983b81f33a2f6db64e93d5af.tar.gz raylib-1dbcce8b56933aa9983b81f33a2f6db64e93d5af.zip | |
Use explicit atomics (#2849)
* Use explicit atomics
* missed one
* use relaced ordering
Diffstat (limited to 'examples/core/core_loading_thread.c')
| -rw-r--r-- | examples/core/core_loading_thread.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/examples/core/core_loading_thread.c b/examples/core/core_loading_thread.c index d5c00fc5..5a988bb2 100644 --- a/examples/core/core_loading_thread.c +++ b/examples/core/core_loading_thread.c @@ -23,10 +23,10 @@ // Using C11 atomics for synchronization // NOTE: A plain bool (or any plain data type for that matter) can't be used for inter-thread synchronization -static atomic_bool dataLoaded = ATOMIC_VAR_INIT(false); // Data Loaded completion indicator +static atomic_bool dataLoaded = false; // Data Loaded completion indicator static void *LoadDataThread(void *arg); // Loading data thread function declaration -static int dataProgress = 0; // Data progress accumulator +static atomic_int dataProgress = 0; // Data progress accumulator //------------------------------------------------------------------------------------ // Program main entry point @@ -69,7 +69,7 @@ int main(void) case STATE_LOADING: { framesCounter++; - if (atomic_load(&dataLoaded)) + if (atomic_load_explicit(&dataLoaded, memory_order_relaxed)) { framesCounter = 0; int error = pthread_join(threadId, NULL); @@ -84,8 +84,8 @@ int main(void) if (IsKeyPressed(KEY_ENTER)) { // Reset everything to launch again - atomic_store(&dataLoaded, false); - dataProgress = 0; + atomic_store_explicit(&dataLoaded, false, memory_order_relaxed); + atomic_store_explicit(&dataProgress, 0, memory_order_relaxed); state = STATE_WAITING; } } break; @@ -104,7 +104,7 @@ int main(void) case STATE_WAITING: DrawText("PRESS ENTER to START LOADING DATA", 150, 170, 20, DARKGRAY); break; case STATE_LOADING: { - DrawRectangle(150, 200, dataProgress, 60, SKYBLUE); + DrawRectangle(150, 200, atomic_load_explicit(&dataProgress, memory_order_relaxed), 60, SKYBLUE); if ((framesCounter/15)%2) DrawText("LOADING DATA...", 240, 210, 40, DARKBLUE); } break; @@ -145,11 +145,11 @@ static void *LoadDataThread(void *arg) // We accumulate time over a global variable to be used in // main thread as a progress bar - dataProgress = timeCounter/10; + atomic_store_explicit(&dataProgress, timeCounter/10, memory_order_relaxed); } // When data has finished loading, we set global variable - atomic_store(&dataLoaded, true); + atomic_store_explicit(&dataLoaded, true, memory_order_relaxed); return NULL; } |
