From 13592d50fa5d2c8fed06b997d50edd8ddaf9ac81 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Tue, 17 Jul 2012 08:06:28 +0200 Subject: [PATCH] Use Windows thread ids instead of handles for comparisons * It seems that the HANDLE's returned from GetCurrentThread are often equal for two threads. GetCurrentThreadID doesn't have this problem. * Separate our cross platform thread_t and thread_id_t types even though on unix they're the same thing. https://bugzilla.gnome.org/show_bug.cgi?id=44740 --- p11-kit/modules.c | 6 +++--- p11-kit/util.h | 11 ++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/p11-kit/modules.c b/p11-kit/modules.c index 69fa88f..3f5a96b 100644 --- a/p11-kit/modules.c +++ b/p11-kit/modules.c @@ -109,7 +109,7 @@ typedef struct _Module { /* Initialization, mutex must be held */ mutex_t initialize_mutex; int initialize_called; - thread_t initialize_thread; + thread_id_t initialize_thread; } Module; /* @@ -531,10 +531,10 @@ static CK_RV initialize_module_unlocked_reentrant (Module *mod) { CK_RV rv = CKR_OK; - thread_t self; + thread_id_t self; assert (mod); - self = _p11_thread_self (); + self = _p11_thread_id_self (); if (mod->initialize_thread == self) { _p11_message ("p11-kit initialization called recursively"); diff --git a/p11-kit/util.h b/p11-kit/util.h index 2da4db6..b8d4a15 100644 --- a/p11-kit/util.h +++ b/p11-kit/util.h @@ -65,6 +65,8 @@ typedef CRITICAL_SECTION mutex_t; typedef HANDLE thread_t; +typedef DWORD thread_id_t; + #define _p11_mutex_init(m) \ (InitializeCriticalSection (m)) #define _p11_mutex_lock(m) \ @@ -80,8 +82,9 @@ int _p11_thread_create (thread_t *thread, thread_routine, void *arg); int _p11_thread_join (thread_t thread); -#define _p11_thread_self() \ - (GetCurrentThread ()) +/* Returns a thread_id_t */ +#define _p11_thread_id_self() \ + (GetCurrentThreadId ()) typedef HMODULE dl_module_t; @@ -122,13 +125,15 @@ void _p11_mutex_init (mutex_t *mutex); typedef pthread_t thread_t; +typedef pthread_t thread_id_t; + typedef void * (*thread_routine) (void *arg); #define _p11_thread_create(t, r, a) \ (pthread_create ((t), NULL, (r), (a))) #define _p11_thread_join(t) \ (pthread_join ((t), NULL)) -#define _p11_thread_self(m) \ +#define _p11_thread_id_self(m) \ (pthread_self ()) typedef void * dl_module_t; -- 1.7.10.4