commit bce7b1d218de02141d9c219126e8b5b9279e0bd2 parent d15d90c2e72f6dfb91f9da99a4f647566a29f321 Author: Michael Savage <mikejsavage@gmail.com> Date: Sat Aug 20 20:49:43 +0100 Add win32_thread.h Diffstat:
platform_thread.h | | | 2 | ++ |
win32_thread.h | | | 32 | ++++++++++++++++++++++++++++++++ |
diff --git a/platform_thread.h b/platform_thread.h @@ -3,6 +3,8 @@ #if defined( __linux__ ) || defined( __APPLE__ ) #include "unix_thread.h" +#elif defined( _WIN32 ) +#include "win32_thread.h" #else #error new platform #endif diff --git a/win32_thread.h b/win32_thread.h @@ -0,0 +1,32 @@ +#ifndef _WINDOWS_THREAD_H_ +#define _WINDOWS_THREAD_H_ + +#include <windows.h> + +#include "intrinsics.h" + +#define THREAD( f ) DWORD WINAPI f( void * data ) +typedef THREAD( ThreadCallback ); +#define THREAD_END return 0 + +struct Thread { + HANDLE handle; +}; + +inline void thread_init( Thread * thread, ThreadCallback callback, void * data ) { + DWORD id; + HANDLE handle = CreateThread( 0, 0, callback, data, 0, &id ); + if( handle == NULL ) { + // TODO: make ERROR for windows properly. + printf( "CreateThread failed" ); + exit( 1 ); + } + CloseHandle( handle ); +} + +inline u32 thread_getid() { + // TODO: make this cast explicit and checked + return GetCurrentThreadId(); +} + +#endif // _WINDOWS_THREAD_H_