mirror of
https://github.com/PCSX2/pcsx2.git
synced 2025-12-16 04:08:48 +00:00
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:
parent
93d4f5a39c
commit
6c0afe7c48
4
3rdparty/3rdpartyDLL.vsprops
vendored
4
3rdparty/3rdpartyDLL.vsprops
vendored
@ -23,4 +23,8 @@
|
|||||||
SubSystem="2"
|
SubSystem="2"
|
||||||
ImportLibrary="$(OutDir)\$(ProjectName).lib"
|
ImportLibrary="$(OutDir)\$(ProjectName).lib"
|
||||||
/>
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCResourceCompilerTool"
|
||||||
|
AdditionalIncludeDirectories=""$(SvnRootDir)/common/include""
|
||||||
|
/>
|
||||||
</VisualStudioPropertySheet>
|
</VisualStudioPropertySheet>
|
||||||
|
|||||||
4
3rdparty/w32pthreads/global.c
vendored
4
3rdparty/w32pthreads/global.c
vendored
@ -37,18 +37,18 @@
|
|||||||
|
|
||||||
#include "ptw32pch.h"
|
#include "ptw32pch.h"
|
||||||
|
|
||||||
|
__declspec(thread) ptw32_thread_t* ptw32_selfThread = NULL;
|
||||||
|
|
||||||
int ptw32_processInitialized = PTW32_FALSE;
|
int ptw32_processInitialized = PTW32_FALSE;
|
||||||
ptw32_thread_t * ptw32_threadReuseTop = PTW32_THREAD_REUSE_EMPTY;
|
ptw32_thread_t * ptw32_threadReuseTop = PTW32_THREAD_REUSE_EMPTY;
|
||||||
ptw32_thread_t * ptw32_threadReuseBottom = 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_key_t ptw32_cleanupKey = NULL;
|
||||||
pthread_cond_t ptw32_cond_list_head = NULL;
|
pthread_cond_t ptw32_cond_list_head = NULL;
|
||||||
pthread_cond_t ptw32_cond_list_tail = NULL;
|
pthread_cond_t ptw32_cond_list_tail = NULL;
|
||||||
|
|
||||||
int ptw32_concurrency = 0;
|
int ptw32_concurrency = 0;
|
||||||
|
|
||||||
/* What features have been auto-detaected */
|
/* What features have been auto-detected */
|
||||||
int ptw32_features = 0;
|
int ptw32_features = 0;
|
||||||
|
|
||||||
BOOL ptw32_smp_system = PTW32_TRUE; /* Safer if assumed true initially. */
|
BOOL ptw32_smp_system = PTW32_TRUE; /* Safer if assumed true initially. */
|
||||||
|
|||||||
5
3rdparty/w32pthreads/include/implement.h
vendored
5
3rdparty/w32pthreads/include/implement.h
vendored
@ -136,7 +136,7 @@ struct ptw32_thread_t_
|
|||||||
void *parms;
|
void *parms;
|
||||||
int ptErrno;
|
int ptErrno;
|
||||||
int detachState;
|
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 */
|
int sched_priority; /* As set, not as currently is */
|
||||||
pthread_mutex_t cancelLock; /* Used for async-cancel safety */
|
pthread_mutex_t cancelLock; /* Used for async-cancel safety */
|
||||||
int cancelState;
|
int cancelState;
|
||||||
@ -528,10 +528,11 @@ extern "C"
|
|||||||
{
|
{
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
extern __declspec(thread) ptw32_thread_t* ptw32_selfThread;
|
||||||
|
|
||||||
extern int ptw32_processInitialized;
|
extern int ptw32_processInitialized;
|
||||||
extern ptw32_thread_t * ptw32_threadReuseTop;
|
extern ptw32_thread_t * ptw32_threadReuseTop;
|
||||||
extern ptw32_thread_t * ptw32_threadReuseBottom;
|
extern ptw32_thread_t * ptw32_threadReuseBottom;
|
||||||
extern pthread_key_t ptw32_selfThreadKey;
|
|
||||||
extern pthread_key_t ptw32_cleanupKey;
|
extern pthread_key_t ptw32_cleanupKey;
|
||||||
extern pthread_cond_t ptw32_cond_list_head;
|
extern pthread_cond_t ptw32_cond_list_head;
|
||||||
extern pthread_cond_t ptw32_cond_list_tail;
|
extern pthread_cond_t ptw32_cond_list_tail;
|
||||||
|
|||||||
8
3rdparty/w32pthreads/pthread_exit.c
vendored
8
3rdparty/w32pthreads/pthread_exit.c
vendored
@ -65,13 +65,7 @@ pthread_exit (void *value_ptr)
|
|||||||
* ------------------------------------------------------
|
* ------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
ptw32_thread_t * sp;
|
ptw32_thread_t * sp = ptw32_selfThread;
|
||||||
|
|
||||||
/*
|
|
||||||
* Don't use pthread_self() to avoid creating an implicit POSIX thread handle
|
|
||||||
* unnecessarily.
|
|
||||||
*/
|
|
||||||
sp = (ptw32_thread_t *) pthread_getspecific (ptw32_selfThreadKey);
|
|
||||||
|
|
||||||
#ifdef _UWIN
|
#ifdef _UWIN
|
||||||
if (--pthread_count <= 0)
|
if (--pthread_count <= 0)
|
||||||
|
|||||||
12
3rdparty/w32pthreads/pthread_self.c
vendored
12
3rdparty/w32pthreads/pthread_self.c
vendored
@ -61,14 +61,7 @@ pthread_self (void)
|
|||||||
{
|
{
|
||||||
pthread_t self;
|
pthread_t self;
|
||||||
pthread_t nil = {NULL, 0};
|
pthread_t nil = {NULL, 0};
|
||||||
ptw32_thread_t * sp;
|
ptw32_thread_t * sp = ptw32_selfThread;
|
||||||
|
|
||||||
#ifdef _UWIN
|
|
||||||
if (!ptw32_selfThreadKey)
|
|
||||||
return nil;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
sp = (ptw32_thread_t *) pthread_getspecific (ptw32_selfThreadKey);
|
|
||||||
|
|
||||||
if (sp != NULL)
|
if (sp != NULL)
|
||||||
{
|
{
|
||||||
@ -128,8 +121,7 @@ pthread_self (void)
|
|||||||
* because the new handle is not yet public.
|
* because the new handle is not yet public.
|
||||||
*/
|
*/
|
||||||
sp->sched_priority = GetThreadPriority (sp->threadH);
|
sp->sched_priority = GetThreadPriority (sp->threadH);
|
||||||
|
ptw32_selfThread = ptw32_new().p;
|
||||||
pthread_setspecific (ptw32_selfThreadKey, (void *) sp);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
44
3rdparty/w32pthreads/pthread_setspecific.c
vendored
44
3rdparty/w32pthreads/pthread_setspecific.c
vendored
@ -68,40 +68,16 @@ pthread_setspecific (pthread_key_t key, const void *value)
|
|||||||
pthread_t self;
|
pthread_t self;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
if (key != ptw32_selfThreadKey)
|
/*
|
||||||
{
|
* Using pthread_self will implicitly create
|
||||||
/*
|
* an instance of pthread_t for the current
|
||||||
* Using pthread_self will implicitly create
|
* thread if one wasn't explicitly created
|
||||||
* an instance of pthread_t for the current
|
*/
|
||||||
* thread if one wasn't explicitly created
|
self = pthread_self ();
|
||||||
*/
|
if (self.p == NULL)
|
||||||
self = pthread_self ();
|
{
|
||||||
if (self.p == NULL)
|
return ENOENT;
|
||||||
{
|
}
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result = 0;
|
result = 0;
|
||||||
|
|
||||||
|
|||||||
@ -213,7 +213,7 @@ pthread_win32_process_detach_np ()
|
|||||||
{
|
{
|
||||||
if (ptw32_processInitialized)
|
if (ptw32_processInitialized)
|
||||||
{
|
{
|
||||||
ptw32_thread_t * sp = (ptw32_thread_t *) pthread_getspecific (ptw32_selfThreadKey);
|
ptw32_thread_t * sp = ptw32_selfThread;
|
||||||
|
|
||||||
if (sp != NULL)
|
if (sp != NULL)
|
||||||
{
|
{
|
||||||
@ -224,7 +224,8 @@ pthread_win32_process_detach_np ()
|
|||||||
if (sp->detachState == PTHREAD_CREATE_DETACHED)
|
if (sp->detachState == PTHREAD_CREATE_DETACHED)
|
||||||
{
|
{
|
||||||
ptw32_threadDestroy (sp->ptHandle);
|
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
|
* Don't use pthread_self() - to avoid creating an implicit POSIX thread handle
|
||||||
* unnecessarily.
|
* 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.
|
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)
|
if (sp->detachState == PTHREAD_CREATE_DETACHED)
|
||||||
{
|
{
|
||||||
ptw32_threadDestroy (sp->ptHandle);
|
ptw32_threadDestroy (sp->ptHandle);
|
||||||
|
free(ptw32_selfThread);
|
||||||
TlsSetValue (ptw32_selfThreadKey->key, NULL);
|
ptw32_selfThread = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
27
3rdparty/w32pthreads/pthreads_2008.vcproj
vendored
27
3rdparty/w32pthreads/pthreads_2008.vcproj
vendored
@ -6,6 +6,7 @@
|
|||||||
ProjectGUID="{26511268-2902-4997-8421-ECD7055F9E28}"
|
ProjectGUID="{26511268-2902-4997-8421-ECD7055F9E28}"
|
||||||
RootNamespace="pthreads"
|
RootNamespace="pthreads"
|
||||||
Keyword="Win32Proj"
|
Keyword="Win32Proj"
|
||||||
|
TargetFrameworkVersion="0"
|
||||||
>
|
>
|
||||||
<Platforms>
|
<Platforms>
|
||||||
<Platform
|
<Platform
|
||||||
@ -3998,32 +3999,8 @@
|
|||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\w32pthreads.v2.rc"
|
RelativePath=".\w32pthreads.rc"
|
||||||
>
|
>
|
||||||
<FileConfiguration
|
|
||||||
Name="Debug|Win32"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCResourceCompilerTool"
|
|
||||||
AdditionalIncludeDirectories=""$(SvnRootDir)\common\include""
|
|
||||||
/>
|
|
||||||
</FileConfiguration>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Release|Win32"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCResourceCompilerTool"
|
|
||||||
AdditionalIncludeDirectories=""$(SvnRootDir)\common\include""
|
|
||||||
/>
|
|
||||||
</FileConfiguration>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Devel|Win32"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCResourceCompilerTool"
|
|
||||||
AdditionalIncludeDirectories=""$(SvnRootDir)\common\include""
|
|
||||||
/>
|
|
||||||
</FileConfiguration>
|
|
||||||
</File>
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
</Files>
|
</Files>
|
||||||
|
|||||||
@ -80,10 +80,8 @@ ptw32_processInitialize (void)
|
|||||||
/*
|
/*
|
||||||
* Initialize Keys
|
* Initialize Keys
|
||||||
*/
|
*/
|
||||||
if ((pthread_key_create (&ptw32_selfThreadKey, NULL) != 0) ||
|
if (pthread_key_create (&ptw32_cleanupKey, NULL) != 0)
|
||||||
(pthread_key_create (&ptw32_cleanupKey, NULL) != 0))
|
|
||||||
{
|
{
|
||||||
|
|
||||||
ptw32_processTerminate ();
|
ptw32_processTerminate ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
14
3rdparty/w32pthreads/ptw32_processTerminate.c
vendored
14
3rdparty/w32pthreads/ptw32_processTerminate.c
vendored
@ -66,23 +66,9 @@ ptw32_processTerminate (void)
|
|||||||
{
|
{
|
||||||
ptw32_thread_t * tp, * tpNext;
|
ptw32_thread_t * tp, * tpNext;
|
||||||
|
|
||||||
if (ptw32_selfThreadKey != NULL)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* Release ptw32_selfThreadKey
|
|
||||||
*/
|
|
||||||
pthread_key_delete (ptw32_selfThreadKey);
|
|
||||||
|
|
||||||
ptw32_selfThreadKey = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ptw32_cleanupKey != NULL)
|
if (ptw32_cleanupKey != NULL)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
* Release ptw32_cleanupKey
|
|
||||||
*/
|
|
||||||
pthread_key_delete (ptw32_cleanupKey);
|
pthread_key_delete (ptw32_cleanupKey);
|
||||||
|
|
||||||
ptw32_cleanupKey = NULL;
|
ptw32_cleanupKey = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
3rdparty/w32pthreads/ptw32_threadStart.c
vendored
2
3rdparty/w32pthreads/ptw32_threadStart.c
vendored
@ -165,7 +165,7 @@ ptw32_threadStart (void *vthreadParms)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pthread_setspecific (ptw32_selfThreadKey, sp);
|
ptw32_selfThread = sp;
|
||||||
|
|
||||||
sp->state = PThreadStateRunning;
|
sp->state = PThreadStateRunning;
|
||||||
|
|
||||||
|
|||||||
4
3rdparty/w32pthreads/ptw32_throw.c
vendored
4
3rdparty/w32pthreads/ptw32_throw.c
vendored
@ -53,7 +53,7 @@ ptw32_throw (DWORD exception)
|
|||||||
* Don't use pthread_self() to avoid creating an implicit POSIX thread handle
|
* Don't use pthread_self() to avoid creating an implicit POSIX thread handle
|
||||||
* unnecessarily.
|
* unnecessarily.
|
||||||
*/
|
*/
|
||||||
ptw32_thread_t * sp = (ptw32_thread_t *) pthread_getspecific (ptw32_selfThreadKey);
|
ptw32_thread_t * sp = ptw32_selfThread;
|
||||||
|
|
||||||
#ifdef __CLEANUP_SEH
|
#ifdef __CLEANUP_SEH
|
||||||
DWORD exceptionInformation[3];
|
DWORD exceptionInformation[3];
|
||||||
@ -81,7 +81,7 @@ ptw32_throw (DWORD exception)
|
|||||||
exitCode = (unsigned) PTHREAD_CANCELED;
|
exitCode = (unsigned) PTHREAD_CANCELED;
|
||||||
break;
|
break;
|
||||||
case PTW32_EPS_EXIT:
|
case PTW32_EPS_EXIT:
|
||||||
exitCode = (unsigned) sp->exitStatus;;
|
exitCode = (unsigned) sp->exitStatus;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user