diff options
| author | Ray <[email protected]> | 2023-01-02 17:06:55 +0100 |
|---|---|---|
| committer | Ray <[email protected]> | 2023-01-02 17:06:55 +0100 |
| commit | fabedf76367d238a18437190e1a984b468a94e60 (patch) | |
| tree | b71e831b0248a61fc551a7ddf2ddc479d261186c /examples | |
| parent | 62f63f9e485fdffa1e981ae4ae58f5eb8ccfff8e (diff) | |
| parent | 1dbcce8b56933aa9983b81f33a2f6db64e93d5af (diff) | |
| download | raylib-fabedf76367d238a18437190e1a984b468a94e60.tar.gz raylib-fabedf76367d238a18437190e1a984b468a94e60.zip | |
Merge branch 'master' of https://github.com/raysan5/raylib
Diffstat (limited to 'examples')
| -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; } |
