WRes Thread_Create(CThread *p, THREAD_FUNC_TYPE func, LPVOID param) { #if defined(__APPLE__) pthread_attr_t attr; int ret; p->_created = 0; ret = pthread_attr_init(&attr); if (ret) return ret; ret = pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_JOINABLE); if (ret) return ret; ret = pthread_create(&p->_tid, &attr, (void * (*)(void *))func, param); /* ret2 = */ pthread_attr_destroy(&attr); if (ret) return ret; p->_created = 1; return 0; // SZ_OK; #else /* Windows Me/98/95: threadId parameter may not be NULL in _beginthreadex/CreateThread functions */ #ifdef UNDER_CE DWORD threadId; *p = CreateThread(0, 0, func, param, 0, &threadId); #else unsigned threadId; *p = (HANDLE)_beginthreadex(NULL, 0, func, param, 0, &threadId); #endif /* maybe we must use errno here, but probably GetLastError() is also OK. */ return HandleToWRes(*p); #endif }
WRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter) { unsigned threadId; /* Windows Me/98/95: threadId parameter may not be NULL in _beginthreadex/CreateThread functions */ thread->handle = /* CreateThread(0, 0, startAddress, parameter, 0, &threadId); */ (HANDLE)_beginthreadex(NULL, 0, startAddress, parameter, 0, &threadId); /* maybe we must use errno here, but probably GetLastError() is also OK. */ return HandleToWRes(thread->handle); }
WRes Thread_Create(CThread *p, THREAD_FUNC_TYPE func, LPVOID param) { unsigned threadId; /* Windows Me/98/95: threadId parameter may not be NULL in _beginthreadex/CreateThread functions */ *p = #ifdef UNDER_CE CreateThread(0, 0, func, param, 0, &threadId); #else (HANDLE)_beginthreadex(NULL, 0, func, param, 0, &threadId); #endif /* maybe we must use errno here, but probably GetLastError() is also OK. */ return HandleToWRes(*p); }
WRes Event_Create(CEvent *p, BOOL manualReset, int signaled) { #if defined(__APPLE__) pthread_mutex_init(&p->_mutex,0); pthread_cond_init(&p->_cond,0); p->_manual_reset = manualReset; p->_state = (signaled ? True : False); p->_created = 1; return 0; #else *p = CreateEvent(NULL, manualReset, (signaled ? TRUE : FALSE), NULL); return HandleToWRes(*p); #endif }
WRes Semaphore_Create(CSemaphore *p, UInt32 initCount, UInt32 maxCount) { #if defined(__APPLE__) pthread_mutex_init(&p->_mutex,0); pthread_cond_init(&p->_cond,0); p->_count = initCount; p->_maxCount = maxCount; p->_created = 1; return 0; #else *p = CreateSemaphore(NULL, (LONG)initCount, (LONG)maxCount, NULL); return HandleToWRes(*p); #endif }
WRes Semaphore_Create(CSemaphore *p, UInt32 initCount, UInt32 maxCount) { *p = CreateSemaphore(NULL, (LONG)initCount, (LONG)maxCount, NULL); return HandleToWRes(*p); }
static WRes Event_Create(CEvent *p, BOOL manualReset, int signaled) { *p = CreateEvent(NULL, manualReset, (signaled ? TRUE : FALSE), NULL); return HandleToWRes(*p); }
WRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount) { p->handle = CreateSemaphore(NULL, (LONG)initiallyCount, (LONG)maxCount, NULL); return HandleToWRes(p->handle); }
WRes Event_Create(CEvent *p, BOOL manualReset, int initialSignaled) { p->handle = CreateEvent(NULL, manualReset, (initialSignaled ? TRUE : FALSE), NULL); return HandleToWRes(p->handle); }