thread_win32.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00015 #include "config.h"
00016 #include "thread_generic.h"
00017 #include <assert.h>
00018
00022 int
00023 SYS_MutexInit(CRITICAL_SECTION *mutex)
00024 {
00025 InitializeCriticalSection(mutex);
00026 return 1;
00027 }
00028
00029
00033 int
00034 SYS_MutexDestroy(CRITICAL_SECTION *mutex)
00035 {
00036 DeleteCriticalSection(mutex);
00037 return 1;
00038 }
00039
00043 int
00044 SYS_MutexLock(CRITICAL_SECTION *mutex)
00045 {
00046 EnterCriticalSection(mutex);
00047 return 1;
00048 }
00049
00053 int
00054 SYS_MutexUnLock(CRITICAL_SECTION *mutex)
00055 {
00056 LeaveCriticalSection(mutex);
00057 return 1;
00058 }
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00098 int
00099 SYS_ThreadCreate(HANDLE *thread, int attributes,
00100 void* start_routine, void* arg)
00101 {
00102
00103 *thread = CreateThread(
00104 NULL,
00105 0,
00106 start_routine,
00107 arg,
00108 0,
00109 NULL
00110 );
00111
00112 if( *thread == NULL ) {
00113 return 0;
00114 } else {
00115 return 1;
00116 }
00117 }
00118
00122 int
00123 SYS_ThreadJoin(HANDLE *thread, void **retval)
00124 {
00125 DWORD status;
00126 BOOL rv;
00127
00128
00129 if( WaitForSingleObject(*thread, INFINITE) == WAIT_FAILED ) {
00130 return 0;
00131 }
00132 if( retval != NULL ) {
00133 rv = GetExitCodeThread(*thread, &status);
00134 if( rv == 0 ) {
00135
00136 return 0;
00137 }
00138 *retval = (void *)status;
00139 }
00140
00141 CloseHandle(*thread);
00142 *thread = NULL;
00143 return 1;
00144 }
00145
00146 int
00147 SYS_ThreadExit(void* arg)
00148 {
00149 DWORD status;
00150
00151 status = (DWORD)arg;
00152 ExitThread(status);
00153
00154
00155 assert(0);
00156
00157 return 0;
00158 }