From 8f3c91e91b634adaca77dac6cf314445cceefc78 Mon Sep 17 00:00:00 2001 From: Jonathan McCrohan Date: Fri, 19 Oct 2012 19:38:06 +0100 Subject: Imported Upstream version 2.1.8.20120912 --- cthread.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'cthread.c') diff --git a/cthread.c b/cthread.c index 86f2f9b..d84883e 100644 --- a/cthread.c +++ b/cthread.c @@ -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); -- cgit v1.2.3