diff options
Diffstat (limited to 'cthread.c')
-rw-r--r-- | cthread.c | 23 |
1 files changed, 19 insertions, 4 deletions
@@ -27,6 +27,17 @@ CFRunLoopTimerRef timer = NULL; CFRunLoopSourceRef findActiveDevicesSource = NULL; #endif +#ifdef _WINDOWS + +#if defined(_WINDOWS) && !defined(WINCE) +extern void initializeThreadSecurityAttributes(); +#else +#define initializeThreadSecurityAttributes() +#endif +extern PSECURITY_ATTRIBUTES pSA; + +#endif + int StartCentralThread() { @@ -196,15 +207,15 @@ CThread_func_return_t CentralThreadFunction(CThread_func_arg_t lpdwParam) { #ifdef _MACOSX CentralThread.runLoop = CFRunLoopGetCurrent(); - - //setup notifications of Phidget attach/detach - CPhidgetManager_setupNotifications(CentralThread.runLoop); CFRunLoopAddTimer(CentralThread.runLoop, timer, kCFRunLoopDefaultMode); CFRunLoopAddSource(CentralThread.runLoop, findActiveDevicesSource, kCFRunLoopDefaultMode); CentralThread.macInitDone = PTRUE; + //setup notifications of Phidget attach/detach + CPhidgetManager_setupNotifications(CentralThread.runLoop); + //start run loop - note that this blocks until JoinCentralThread() is called. CFRunLoopRun(); #else @@ -456,7 +467,8 @@ int CThread_create(CThread *cp, CThread_func_t fp, CThread_func_arg_t arg) { #ifdef _WINDOWS - cp->m_ThreadHandle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)fp, arg, 0, &cp->m_ThreadIdentifier); + initializeThreadSecurityAttributes(); + cp->m_ThreadHandle = CreateThread(pSA, 0, (LPTHREAD_START_ROUTINE)fp, arg, 0, &cp->m_ThreadIdentifier); if(cp->m_ThreadHandle) return EPHIDGET_OK; else return GetLastError(); #else @@ -512,6 +524,9 @@ CThread_join(CThread *cp) while (GetExitCodeThread(cp->m_ThreadHandle, &ec) && ec == STILL_ACTIVE) SLEEP(10); + CloseHandle(cp->m_ThreadHandle); + cp->m_ThreadHandle = NULL; + #else if (cp->thread_status == TRUE) pthread_join(cp->m_ThreadHandle, 0); |