examples: replace pthread with mp_thread

This commit is contained in:
Reuben Dunnington 2023-07-30 21:21:25 -07:00
parent 003af621a0
commit 6ec113b708
Signed by: rdunnington
GPG Key ID: 4EC5290E704FD482
4 changed files with 10 additions and 20 deletions

View File

@ -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
set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle_headers /I %pthread_dir%\include
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 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
copy %pthread_dir%\bin\pthreadVC3.dll ..\..\bin

View File

@ -1,7 +1,6 @@
#include<stdlib.h> #include<stdlib.h>
#include<stdio.h> #include<stdio.h>
#include<pthread.h>
#define MG_INCLUDE_GL_API 1 #define MG_INCLUDE_GL_API 1
#include"milepost.h" #include"milepost.h"
@ -9,7 +8,7 @@
mg_surface surface = {0}; mg_surface surface = {0};
mg_canvas canvas = {0}; mg_canvas canvas = {0};
void* render_thread(void* user) i32 render_thread(void* user)
{ {
while(!mp_should_quit()) while(!mp_should_quit())
{ {
@ -79,16 +78,14 @@ int main()
mp_window_bring_to_front(window); mp_window_bring_to_front(window);
mp_window_focus(window); mp_window_focus(window);
pthread_t renderThread; mp_thread* renderThread = mp_thread_create(render_thread, NULL);
pthread_create(&renderThread, 0, render_thread, 0);
while(!mp_should_quit()) while(!mp_should_quit())
{ {
mp_pump_events(0); mp_pump_events(0);
} }
void* res; mp_thread_join(renderThread, NULL);
pthread_join(renderThread, &res);
mg_canvas_destroy(canvas); mg_canvas_destroy(canvas);
mg_surface_destroy(surface); mg_surface_destroy(surface);

View File

@ -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

View File

@ -17,8 +17,6 @@
#define MG_INCLUDE_GL_API #define MG_INCLUDE_GL_API
#include"milepost.h" #include"milepost.h"
#include<pthread.h>
unsigned int program; unsigned int program;
const char* vshaderSource = const char* vshaderSource =
@ -124,7 +122,7 @@ void update_and_render(app_data* app)
mem_arena_clear(mem_scratch()); mem_arena_clear(mem_scratch());
} }
void* render(void* user) i32 render(void* user)
{ {
app_data* app = (app_data*)user; app_data* app = (app_data*)user;
@ -210,16 +208,14 @@ int main()
app_data app = {.window = window, app_data app = {.window = window,
.surface = surface}; .surface = surface};
pthread_t renderThread; mp_thread* renderThread = mp_thread_create(render, &app);
pthread_create(&renderThread, 0, render, &app);
while(!mp_should_quit()) while(!mp_should_quit())
{ {
mp_pump_events(0); mp_pump_events(0);
} }
void* res; mp_thread_join(renderThread, NULL);
pthread_join(renderThread, &res);
mg_surface_destroy(surface); mg_surface_destroy(surface);
mp_window_destroy(window); mp_window_destroy(window);