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
commit8f3c91e91b634adaca77dac6cf314445cceefc78 (patch)
tree8a779a28ccfbbfae413f6f7df21fb0a8650d3747 /cthread.c
parentbd7a4f258643bf72d5e97f86f0f2272b381ed1ba (diff)
downloadlibphidget21-8f3c91e91b634adaca77dac6cf314445cceefc78.tar.gz
Imported Upstream version 2.1.8.20120912upstream/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);