medfall

A super great game engine
Log | Files | Refs

win32_thread.h (665B)


      1 #pragma once
      2 
      3 #include <windows.h>
      4 
      5 #include "intrinsics.h"
      6 #include "log.h"
      7 
      8 #define THREAD( f ) DWORD WINAPI f( void * data )
      9 typedef THREAD( ThreadProc );
     10 #define THREAD_END return 0
     11 
     12 struct Thread {
     13 	HANDLE handle;
     14 };
     15 
     16 inline void thread_init( Thread * thread, ThreadProc callback, void * data ) {
     17 	DWORD id;
     18 	HANDLE handle = CreateThread( 0, 0, callback, data, 0, &id );
     19 	if( handle == NULL ) {
     20 		FATAL( "CreateThread" );
     21 	}
     22 }
     23 
     24 inline u64 thread_getid() {
     25 	return checked_cast< u64 >( GetCurrentThreadId() );
     26 }
     27 
     28 inline void thread_join( Thread * thread ) {
     29 	WaitForSingleObject( thread->handle, INFINITE );
     30 }
     31 
     32 inline void thread_yield() {
     33 	SwitchToThread();
     34 }