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

View File

@ -1,7 +1,6 @@
#include<stdlib.h>
#include<stdio.h>
#include<pthread.h>
#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);

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
#include"milepost.h"
#include<pthread.h>
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);