From fc64b4fa83af2c661178750c02a0062d16c1337d Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 4 Aug 2012 20:07:39 +0200 Subject: [PATCH] Permit empth_self() before empth_init() Next commit wants this. --- include/empthread.h | 5 +++-- src/lib/empthread/ntthread.c | 4 +--- src/lib/empthread/pthread.c | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/include/empthread.h b/include/empthread.h index 67856cda2..39ef99a3b 100644 --- a/include/empthread.h +++ b/include/empthread.h @@ -30,7 +30,7 @@ * Sasha Mikheev * Doug Hay, 1998 * Steve McClure, 1998 - * Markus Armbruster, 2005-2009 + * Markus Armbruster, 2005-2012 * Ron Koenderink, 2005-2009 */ @@ -125,7 +125,8 @@ empth_t *empth_create(void (*entry)(void *), int size, int flags, char *name, void *ud); /* - * Return the current thread. + * Return the current thread, NULL before empth_init(). + * This is the only function that may be called before empth_init(). */ empth_t *empth_self(void); diff --git a/src/lib/empthread/ntthread.c b/src/lib/empthread/ntthread.c index 2a39f5bbb..dd41aa745 100644 --- a/src/lib/empthread/ntthread.c +++ b/src/lib/empthread/ntthread.c @@ -467,9 +467,7 @@ bad: empth_t * empth_self(void) { - empth_t *pThread = TlsGetValue(dwTLSIndex); - - return pThread; + return ppvUserData ? TlsGetValue(dwTLSIndex) : NULL; } /************************ diff --git a/src/lib/empthread/pthread.c b/src/lib/empthread/pthread.c index 83f2b6c4e..9c7b24fd0 100644 --- a/src/lib/empthread/pthread.c +++ b/src/lib/empthread/pthread.c @@ -29,7 +29,7 @@ * Known contributors to this file: * Sasha Mikheev * Steve McClure, 1998 - * Markus Armbruster, 2005-2011 + * Markus Armbruster, 2005-2012 * Ron Koenderink, 2007-2009 */ @@ -240,7 +240,7 @@ empth_restorectx(void) empth_t * empth_self(void) { - return pthread_getspecific(ctx_key); + return udata ? pthread_getspecific(ctx_key) : NULL; } char * -- 2.43.0