4 #include "xmlrpc_config.h"
7 #include "xmlrpc-c/string_int.h"
9 #include "xmlrpc-c/abyss.h"
18 TThreadDoneFn * threadDone;
21 #define THREAD_STACK_SIZE (16*1024L)
24 typedef uint32_t (WINAPI WinThreadProc)(void *);
28 ThreadCreate(TThread ** const threadPP,
29 void * const userHandle,
30 TThreadProc * const func,
31 TThreadDoneFn * const threadDone,
32 abyss_bool const useSigchld,
33 const char ** const errorP) {
41 xmlrpc_asprintf(errorP,
42 "Can't allocate memory for thread descriptor.");
44 threadP->userHandle = userHandle;
45 threadP->threadDone = threadDone;
46 threadP->handle = (HANDLE)_beginthreadex(NULL, THREAD_STACK_SIZE, func,
48 CREATE_SUSPENDED, &z);
49 if (threadP->handle == NULL)
50 xmlrpc_asprintf(errorP, "_beginthreadex() failed.");
63 ThreadRun(TThread * const threadP) {
64 return (ResumeThread(threadP->handle) != 0xFFFFFFFF);
70 ThreadStop(TThread * const threadP) {
72 return (SuspendThread(threadP->handle) != 0xFFFFFFFF);
78 ThreadKill(TThread * const threadP) {
79 return (TerminateThread(threadP->handle, 0) != 0);
85 ThreadWaitAndRelease(TThread * const threadP) {
87 ThreadRelease(threadP);
89 if (threadP->threadDone)
90 threadP->threadDone(threadP->userHandle);
98 ThreadExit(int const retValue) {
100 _endthreadex(retValue);
106 ThreadRelease(TThread * const threadP) {
108 CloseHandle(threadP->handle);
122 ThreadUpdateStatus(TThread * const threadP ATTR_UNUSED) {
124 /* Threads keep their own statuses up to date, so there's nothing
132 MutexCreate(TMutex * const mutexP) {
134 *mutexP = CreateMutex(NULL, FALSE, NULL);
136 return (*mutexP != NULL);
142 MutexLock(TMutex * const mutexP) {
144 return (WaitForSingleObject(*mutexP, INFINITE) != WAIT_TIMEOUT);
150 MutexUnlock(TMutex * const mutexP) {
151 return ReleaseMutex(*mutexP);
157 MutexTryLock(TMutex * const mutexP) {
158 return (WaitForSingleObject(*mutexP, 0) != WAIT_TIMEOUT);
164 MutexFree(TMutex * const mutexP) {
165 CloseHandle(*mutexP);