w32pthreads: minor optimization using _declspec(thread) for internal thread handles, instead of TlsAlloc.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1924 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
Jake.Stine 2009-09-29 05:04:55 +00:00
parent 93d4f5a39c
commit 6c0afe7c48
13 changed files with 34 additions and 105 deletions

View File

@ -23,4 +23,8 @@
SubSystem="2"
ImportLibrary="$(OutDir)\$(ProjectName).lib"
/>
<Tool
Name="VCResourceCompilerTool"
AdditionalIncludeDirectories="&quot;$(SvnRootDir)/common/include&quot;"
/>
</VisualStudioPropertySheet>

View File

@ -37,18 +37,18 @@
#include "ptw32pch.h"
__declspec(thread) ptw32_thread_t* ptw32_selfThread = NULL;
int ptw32_processInitialized = PTW32_FALSE;
ptw32_thread_t * ptw32_threadReuseTop = PTW32_THREAD_REUSE_EMPTY;
ptw32_thread_t * ptw32_threadReuseBottom = PTW32_THREAD_REUSE_EMPTY;
pthread_key_t ptw32_selfThreadKey = NULL;
pthread_key_t ptw32_cleanupKey = NULL;
pthread_cond_t ptw32_cond_list_head = NULL;
pthread_cond_t ptw32_cond_list_tail = NULL;
int ptw32_concurrency = 0;
/* What features have been auto-detaected */
/* What features have been auto-detected */
int ptw32_features = 0;
BOOL ptw32_smp_system = PTW32_TRUE; /* Safer if assumed true initially. */

View File

@ -136,7 +136,7 @@ struct ptw32_thread_t_
void *parms;
int ptErrno;
int detachState;
pthread_mutex_t threadLock; /* Used for serialised access to public thread state */
pthread_mutex_t threadLock; /* Used for serialized access to public thread state */
int sched_priority; /* As set, not as currently is */
pthread_mutex_t cancelLock; /* Used for async-cancel safety */
int cancelState;
@ -528,10 +528,11 @@ extern "C"
{
#endif /* __cplusplus */
extern __declspec(thread) ptw32_thread_t* ptw32_selfThread;
extern int ptw32_processInitialized;
extern ptw32_thread_t * ptw32_threadReuseTop;
extern ptw32_thread_t * ptw32_threadReuseBottom;
extern pthread_key_t ptw32_selfThreadKey;
extern pthread_key_t ptw32_cleanupKey;
extern pthread_cond_t ptw32_cond_list_head;
extern pthread_cond_t ptw32_cond_list_tail;

View File

@ -65,13 +65,7 @@ pthread_exit (void *value_ptr)
* ------------------------------------------------------
*/
{
ptw32_thread_t * sp;
/*
* Don't use pthread_self() to avoid creating an implicit POSIX thread handle
* unnecessarily.
*/
sp = (ptw32_thread_t *) pthread_getspecific (ptw32_selfThreadKey);
ptw32_thread_t * sp = ptw32_selfThread;
#ifdef _UWIN
if (--pthread_count <= 0)

View File

@ -61,14 +61,7 @@ pthread_self (void)
{
pthread_t self;
pthread_t nil = {NULL, 0};
ptw32_thread_t * sp;
#ifdef _UWIN
if (!ptw32_selfThreadKey)
return nil;
#endif
sp = (ptw32_thread_t *) pthread_getspecific (ptw32_selfThreadKey);
ptw32_thread_t * sp = ptw32_selfThread;
if (sp != NULL)
{
@ -128,8 +121,7 @@ pthread_self (void)
* because the new handle is not yet public.
*/
sp->sched_priority = GetThreadPriority (sp->threadH);
pthread_setspecific (ptw32_selfThreadKey, (void *) sp);
ptw32_selfThread = ptw32_new().p;
}
}

View File

@ -68,40 +68,16 @@ pthread_setspecific (pthread_key_t key, const void *value)
pthread_t self;
int result = 0;
if (key != ptw32_selfThreadKey)
{
/*
* Using pthread_self will implicitly create
* an instance of pthread_t for the current
* thread if one wasn't explicitly created
*/
self = pthread_self ();
if (self.p == NULL)
{
return ENOENT;
}
}
else
{
/*
* Resolve catch-22 of registering thread with selfThread
* key
*/
ptw32_thread_t * sp = (ptw32_thread_t *) pthread_getspecific (ptw32_selfThreadKey);
if (sp == NULL)
{
if (value == NULL)
{
return ENOENT;
}
self = *((pthread_t *) value);
}
else
{
self = sp->ptHandle;
}
}
/*
* Using pthread_self will implicitly create
* an instance of pthread_t for the current
* thread if one wasn't explicitly created
*/
self = pthread_self ();
if (self.p == NULL)
{
return ENOENT;
}
result = 0;

View File

@ -213,7 +213,7 @@ pthread_win32_process_detach_np ()
{
if (ptw32_processInitialized)
{
ptw32_thread_t * sp = (ptw32_thread_t *) pthread_getspecific (ptw32_selfThreadKey);
ptw32_thread_t * sp = ptw32_selfThread;
if (sp != NULL)
{
@ -224,7 +224,8 @@ pthread_win32_process_detach_np ()
if (sp->detachState == PTHREAD_CREATE_DETACHED)
{
ptw32_threadDestroy (sp->ptHandle);
TlsSetValue (ptw32_selfThreadKey->key, NULL);
free(ptw32_selfThread);
ptw32_selfThread = NULL;
}
}
@ -277,7 +278,7 @@ pthread_win32_thread_detach_np ()
* Don't use pthread_self() - to avoid creating an implicit POSIX thread handle
* unnecessarily.
*/
ptw32_thread_t * sp = (ptw32_thread_t *) pthread_getspecific (ptw32_selfThreadKey);
ptw32_thread_t * sp = ptw32_selfThread;
if (sp != NULL) // otherwise Win32 thread with no implicit POSIX handle.
{
@ -294,8 +295,8 @@ pthread_win32_thread_detach_np ()
if (sp->detachState == PTHREAD_CREATE_DETACHED)
{
ptw32_threadDestroy (sp->ptHandle);
TlsSetValue (ptw32_selfThreadKey->key, NULL);
free(ptw32_selfThread);
ptw32_selfThread = NULL;
}
}
}

View File

@ -6,6 +6,7 @@
ProjectGUID="{26511268-2902-4997-8421-ECD7055F9E28}"
RootNamespace="pthreads"
Keyword="Win32Proj"
TargetFrameworkVersion="0"
>
<Platforms>
<Platform
@ -3998,32 +3999,8 @@
>
</File>
<File
RelativePath=".\w32pthreads.v2.rc"
RelativePath=".\w32pthreads.rc"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCResourceCompilerTool"
AdditionalIncludeDirectories="&quot;$(SvnRootDir)\common\include&quot;"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCResourceCompilerTool"
AdditionalIncludeDirectories="&quot;$(SvnRootDir)\common\include&quot;"
/>
</FileConfiguration>
<FileConfiguration
Name="Devel|Win32"
>
<Tool
Name="VCResourceCompilerTool"
AdditionalIncludeDirectories="&quot;$(SvnRootDir)\common\include&quot;"
/>
</FileConfiguration>
</File>
</Filter>
</Files>

View File

@ -80,10 +80,8 @@ ptw32_processInitialize (void)
/*
* Initialize Keys
*/
if ((pthread_key_create (&ptw32_selfThreadKey, NULL) != 0) ||
(pthread_key_create (&ptw32_cleanupKey, NULL) != 0))
if (pthread_key_create (&ptw32_cleanupKey, NULL) != 0)
{
ptw32_processTerminate ();
}

View File

@ -66,23 +66,9 @@ ptw32_processTerminate (void)
{
ptw32_thread_t * tp, * tpNext;
if (ptw32_selfThreadKey != NULL)
{
/*
* Release ptw32_selfThreadKey
*/
pthread_key_delete (ptw32_selfThreadKey);
ptw32_selfThreadKey = NULL;
}
if (ptw32_cleanupKey != NULL)
{
/*
* Release ptw32_cleanupKey
*/
pthread_key_delete (ptw32_cleanupKey);
ptw32_cleanupKey = NULL;
}

View File

@ -165,7 +165,7 @@ ptw32_threadStart (void *vthreadParms)
}
#endif
pthread_setspecific (ptw32_selfThreadKey, sp);
ptw32_selfThread = sp;
sp->state = PThreadStateRunning;

View File

@ -53,7 +53,7 @@ ptw32_throw (DWORD exception)
* Don't use pthread_self() to avoid creating an implicit POSIX thread handle
* unnecessarily.
*/
ptw32_thread_t * sp = (ptw32_thread_t *) pthread_getspecific (ptw32_selfThreadKey);
ptw32_thread_t * sp = ptw32_selfThread;
#ifdef __CLEANUP_SEH
DWORD exceptionInformation[3];
@ -81,7 +81,7 @@ ptw32_throw (DWORD exception)
exitCode = (unsigned) PTHREAD_CANCELED;
break;
case PTW32_EPS_EXIT:
exitCode = (unsigned) sp->exitStatus;;
exitCode = (unsigned) sp->exitStatus;
break;
}