aboutsummaryrefslogtreecommitdiffstats
path: root/cthread.c
diff options
context:
space:
mode:
authorJonathan McCrohan <jmccrohan@gmail.com>2012-10-19 19:38:06 +0100
committerJonathan McCrohan <jmccrohan@gmail.com>2012-10-19 19:38:06 +0100
commit2891593727a0151a66ed7860fed6399548c74c02 (patch)
tree1cb52da179b4ab23ba2a22f44d88ea3523f51f0c /cthread.c
parentcff96463a694573a9f87b014482a45c25bf4c7b0 (diff)
parent8f3c91e91b634adaca77dac6cf314445cceefc78 (diff)
downloadlibphidget21-2891593727a0151a66ed7860fed6399548c74c02.tar.gz
Merge tag 'upstream/2.1.8.20120912'
Upstream version 2.1.8.20120912
Diffstat (limited to 'cthread.c')
-rw-r--r--cthread.c23
1 files changed, 19 insertions, 4 deletions
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);