diff options
| author | 2014-12-26 12:23:52 +0100 | |
|---|---|---|
| committer | 2015-01-13 00:14:55 +0100 | |
| commit | f3c4db4f30731f6cfc2c37a39d5ce3501d42f45e (patch) | |
| tree | caa0ffcfdd84a31c945408e9e7ccd56b72318e2e /common | |
| parent | aa14c053bc909c56d31c12799f13013f845ddb71 (diff) | |
| download | libimobiledevice-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.c | 15 | ||||
| -rw-r--r-- | common/thread.h | 3 |
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 @@ | |||
| 21 | 21 | ||
| 22 | #include "thread.h" | 22 | #include "thread.h" |
| 23 | 23 | ||
| 24 | int thread_create(thread_t *thread, thread_func_t thread_func, void* data) | 24 | int thread_new(thread_t *thread, thread_func_t thread_func, void* data) |
| 25 | { | 25 | { |
| 26 | #ifdef WIN32 | 26 | #ifdef WIN32 |
| 27 | HANDLE th = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)thread_func, data, 0, NULL); | 27 | HANDLE th = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)thread_func, data, 0, NULL); |
| 28 | if (th == NULL) { | 28 | if (th == NULL) { |
| 29 | return -1; | 29 | return -1; |
| 30 | } | 30 | } |
| 31 | *thread = th; | 31 | *thread = th; |
| 32 | return 0; | 32 | return 0; |
| 33 | #else | 33 | #else |
| @@ -36,6 +36,13 @@ int thread_create(thread_t *thread, thread_func_t thread_func, void* data) | |||
| 36 | #endif | 36 | #endif |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | void thread_free(thread_t thread) | ||
| 40 | { | ||
| 41 | #ifdef WIN32 | ||
| 42 | CloseHandle(thread); | ||
| 43 | #endif | ||
| 44 | } | ||
| 45 | |||
| 39 | void thread_join(thread_t thread) | 46 | void thread_join(thread_t thread) |
| 40 | { | 47 | { |
| 41 | /* wait for thread to complete */ | 48 | /* wait for thread to complete */ |
| @@ -95,5 +102,5 @@ void thread_once(thread_once_t *once_control, void (*init_routine)(void)) | |||
| 95 | InterlockedExchange(&(once_control->lock), 0); | 102 | InterlockedExchange(&(once_control->lock), 0); |
| 96 | #else | 103 | #else |
| 97 | pthread_once(once_control, init_routine); | 104 | pthread_once(once_control, init_routine); |
| 98 | #endif | 105 | #endif |
| 99 | } | 106 | } |
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; | |||
| 43 | 43 | ||
| 44 | typedef void* (*thread_func_t)(void* data); | 44 | typedef void* (*thread_func_t)(void* data); |
| 45 | 45 | ||
| 46 | int thread_create(thread_t* thread, thread_func_t thread_func, void* data); | 46 | int thread_new(thread_t* thread, thread_func_t thread_func, void* data); |
| 47 | void thread_free(thread_t thread); | ||
| 47 | void thread_join(thread_t thread); | 48 | void thread_join(thread_t thread); |
| 48 | 49 | ||
| 49 | void mutex_init(mutex_t* mutex); | 50 | void mutex_init(mutex_t* mutex); |
