summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2014-12-26 12:23:52 +0100
committerGravatar Martin Szulecki2015-01-13 00:14:55 +0100
commitf3c4db4f30731f6cfc2c37a39d5ce3501d42f45e (patch)
treecaa0ffcfdd84a31c945408e9e7ccd56b72318e2e /common
parentaa14c053bc909c56d31c12799f13013f845ddb71 (diff)
downloadlibimobiledevice-f3c4db4f30731f6cfc2c37a39d5ce3501d42f45e.tar.gz
libimobiledevice-f3c4db4f30731f6cfc2c37a39d5ce3501d42f45e.tar.bz2
thread: Introduce thread_new and thread_free to cover handle leaks on WIN32
Diffstat (limited to 'common')
-rw-r--r--common/thread.c15
-rw-r--r--common/thread.h3
2 files changed, 13 insertions, 5 deletions
diff --git a/common/thread.c b/common/thread.c
index d6d6c1a..f4a00cf 100644
--- a/common/thread.c
+++ b/common/thread.c
@@ -21,13 +21,13 @@
#include "thread.h"
-int thread_create(thread_t *thread, thread_func_t thread_func, void* data)
+int thread_new(thread_t *thread, thread_func_t thread_func, void* data)
{
#ifdef WIN32
HANDLE th = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)thread_func, data, 0, NULL);
- if (th == NULL) {
+ if (th == NULL) {
return -1;
- }
+ }
*thread = th;
return 0;
#else
@@ -36,6 +36,13 @@ int thread_create(thread_t *thread, thread_func_t thread_func, void* data)
#endif
}
+void thread_free(thread_t thread)
+{
+#ifdef WIN32
+ CloseHandle(thread);
+#endif
+}
+
void thread_join(thread_t thread)
{
/* wait for thread to complete */
@@ -95,5 +102,5 @@ void thread_once(thread_once_t *once_control, void (*init_routine)(void))
InterlockedExchange(&(once_control->lock), 0);
#else
pthread_once(once_control, init_routine);
-#endif
+#endif
}
diff --git a/common/thread.h b/common/thread.h
index 9b15cc4..d0eebdf 100644
--- a/common/thread.h
+++ b/common/thread.h
@@ -43,7 +43,8 @@ typedef pthread_once_t thread_once_t;
typedef void* (*thread_func_t)(void* data);
-int thread_create(thread_t* thread, thread_func_t thread_func, void* data);
+int thread_new(thread_t* thread, thread_func_t thread_func, void* data);
+void thread_free(thread_t thread);
void thread_join(thread_t thread);
void mutex_init(mutex_t* mutex);