From 6ec113b708398bcf82a052a2bfb891b3265ca92e Mon Sep 17 00:00:00 2001 From: Reuben Dunnington Date: Sun, 30 Jul 2023 21:21:25 -0700 Subject: [PATCH] examples: replace pthread with mp_thread --- examples/render_thread/build.bat | 7 ++----- examples/render_thread/main.c | 9 +++------ examples/smooth_resize/build.bat | 4 ++-- examples/smooth_resize/main.c | 10 +++------- 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/examples/render_thread/build.bat b/examples/render_thread/build.bat index e2187a8..67d593c 100644 --- a/examples/render_thread/build.bat +++ b/examples/render_thread/build.bat @@ -1,7 +1,4 @@ -set pthread_dir=..\..\..\..\vcpkg\packages\pthreads_x64-windows -set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle_headers /I %pthread_dir%\include +set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle_headers -cl /we4013 /Zi /Zc:preprocessor /std:c11 %INCLUDES% main.c /link /MANIFEST:EMBED /MANIFESTINPUT:../../src/win32_manifest.xml /LIBPATH:../../bin milepost.dll.lib /LIBPATH:%pthread_dir%\lib pthreadVC3.lib /out:../../bin/example_render_thread.exe - -copy %pthread_dir%\bin\pthreadVC3.dll ..\..\bin +cl /we4013 /Zi /Zc:preprocessor /std:c11 /experimental:c11atomics %INCLUDES% main.c /link /MANIFEST:EMBED /MANIFESTINPUT:../../src/win32_manifest.xml /LIBPATH:../../bin milepost.dll.lib /out:../../bin/example_render_thread.exe diff --git a/examples/render_thread/main.c b/examples/render_thread/main.c index 9264c4b..ef7af1b 100644 --- a/examples/render_thread/main.c +++ b/examples/render_thread/main.c @@ -1,7 +1,6 @@ #include #include -#include #define MG_INCLUDE_GL_API 1 #include"milepost.h" @@ -9,7 +8,7 @@ mg_surface surface = {0}; mg_canvas canvas = {0}; -void* render_thread(void* user) +i32 render_thread(void* user) { while(!mp_should_quit()) { @@ -79,16 +78,14 @@ int main() mp_window_bring_to_front(window); mp_window_focus(window); - pthread_t renderThread; - pthread_create(&renderThread, 0, render_thread, 0); + mp_thread* renderThread = mp_thread_create(render_thread, NULL); while(!mp_should_quit()) { mp_pump_events(0); } - void* res; - pthread_join(renderThread, &res); + mp_thread_join(renderThread, NULL); mg_canvas_destroy(canvas); mg_surface_destroy(surface); diff --git a/examples/smooth_resize/build.bat b/examples/smooth_resize/build.bat index 4f2c691..fe06030 100644 --- a/examples/smooth_resize/build.bat +++ b/examples/smooth_resize/build.bat @@ -1,4 +1,4 @@ -set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle_headers /I ..\..\..\..\vcpkg\packages\pthreads_x64-windows\include +set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle_headers -cl /we4013 /Zi /Zc:preprocessor /std:c11 %INCLUDES% main.c /link /LIBPATH:../../bin milepost.dll.lib /LIBPATH:..\..\..\..\vcpkg\packages\pthreads_x64-windows\lib pthreadVC3.lib /out:../../bin/example_smooth_resize.exe +cl /we4013 /Zi /Zc:preprocessor /std:c11 /experimental:c11atomics %INCLUDES% main.c /link /LIBPATH:../../bin milepost.dll.lib /out:../../bin/example_smooth_resize.exe diff --git a/examples/smooth_resize/main.c b/examples/smooth_resize/main.c index 276c0e4..a5c8c4d 100644 --- a/examples/smooth_resize/main.c +++ b/examples/smooth_resize/main.c @@ -17,8 +17,6 @@ #define MG_INCLUDE_GL_API #include"milepost.h" -#include - unsigned int program; const char* vshaderSource = @@ -124,7 +122,7 @@ void update_and_render(app_data* app) mem_arena_clear(mem_scratch()); } -void* render(void* user) +i32 render(void* user) { app_data* app = (app_data*)user; @@ -210,16 +208,14 @@ int main() app_data app = {.window = window, .surface = surface}; - pthread_t renderThread; - pthread_create(&renderThread, 0, render, &app); + mp_thread* renderThread = mp_thread_create(render, &app); while(!mp_should_quit()) { mp_pump_events(0); } - void* res; - pthread_join(renderThread, &res); + mp_thread_join(renderThread, NULL); mg_surface_destroy(surface); mp_window_destroy(window);