Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
glslang
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
glslang
Commits
11fa4d0d
Unverified
Commit
11fa4d0d
authored
Jul 22, 2020
by
John Kessenich
Committed by
GitHub
Jul 22, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2348 from ben-clayton/thread-local
Simplify PoolAlloc by using `thread_local`
parents
1c42d4ee
abf92c80
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
150 deletions
+16
-150
InitializeDll.cpp
OGLCompilersDLL/InitializeDll.cpp
+0
-128
InitializeDll.h
OGLCompilersDLL/InitializeDll.h
+4
-4
InitializeGlobals.h
glslang/Include/InitializeGlobals.h
+1
-1
PoolAlloc.cpp
glslang/MachineIndependent/PoolAlloc.cpp
+11
-17
No files found.
OGLCompilersDLL/InitializeDll.cpp
View file @
11fa4d0d
...
@@ -32,134 +32,6 @@
...
@@ -32,134 +32,6 @@
// POSSIBILITY OF SUCH DAMAGE.
// POSSIBILITY OF SUCH DAMAGE.
//
//
#define SH_EXPORTING
#include <cassert>
#include "InitializeDll.h"
#include "../glslang/Include/InitializeGlobals.h"
#include "../glslang/Public/ShaderLang.h"
#include "../glslang/Include/PoolAlloc.h"
namespace
glslang
{
namespace
glslang
{
OS_TLSIndex
ThreadInitializeIndex
=
OS_INVALID_TLS_INDEX
;
// Per-process initialization.
// Needs to be called at least once before parsing, etc. is done.
// Will also do thread initialization for the calling thread; other
// threads will need to do that explicitly.
bool
InitProcess
()
{
glslang
::
GetGlobalLock
();
if
(
ThreadInitializeIndex
!=
OS_INVALID_TLS_INDEX
)
{
//
// Function is re-entrant.
//
glslang
::
ReleaseGlobalLock
();
return
true
;
}
ThreadInitializeIndex
=
OS_AllocTLSIndex
();
if
(
ThreadInitializeIndex
==
OS_INVALID_TLS_INDEX
)
{
assert
(
0
&&
"InitProcess(): Failed to allocate TLS area for init flag"
);
glslang
::
ReleaseGlobalLock
();
return
false
;
}
if
(
!
InitializePoolIndex
())
{
assert
(
0
&&
"InitProcess(): Failed to initialize global pool"
);
glslang
::
ReleaseGlobalLock
();
return
false
;
}
if
(
!
InitThread
())
{
assert
(
0
&&
"InitProcess(): Failed to initialize thread"
);
glslang
::
ReleaseGlobalLock
();
return
false
;
}
glslang
::
ReleaseGlobalLock
();
return
true
;
}
// Per-thread scoped initialization.
// Must be called at least once by each new thread sharing the
// symbol tables, etc., needed to parse.
bool
InitThread
()
{
//
// This function is re-entrant
//
if
(
ThreadInitializeIndex
==
OS_INVALID_TLS_INDEX
)
{
assert
(
0
&&
"InitThread(): Process hasn't been initalised."
);
return
false
;
}
if
(
OS_GetTLSValue
(
ThreadInitializeIndex
)
!=
0
)
return
true
;
if
(
!
OS_SetTLSValue
(
ThreadInitializeIndex
,
(
void
*
)
1
))
{
assert
(
0
&&
"InitThread(): Unable to set init flag."
);
return
false
;
}
glslang
::
SetThreadPoolAllocator
(
nullptr
);
return
true
;
}
// Not necessary to call this: InitThread() is reentrant, and the need
// to do per thread tear down has been removed.
//
// This is kept, with memory management removed, to satisfy any exiting
// calls to it that rely on it.
bool
DetachThread
()
{
bool
success
=
true
;
if
(
ThreadInitializeIndex
==
OS_INVALID_TLS_INDEX
)
return
true
;
//
// Function is re-entrant and this thread may not have been initialized.
//
if
(
OS_GetTLSValue
(
ThreadInitializeIndex
)
!=
0
)
{
if
(
!
OS_SetTLSValue
(
ThreadInitializeIndex
,
(
void
*
)
0
))
{
assert
(
0
&&
"DetachThread(): Unable to clear init flag."
);
success
=
false
;
}
}
return
success
;
}
// Not necessary to call this: InitProcess() is reentrant.
//
// This is kept, with memory management removed, to satisfy any exiting
// calls to it that rely on it.
//
// Users of glslang should call shFinalize() or glslang::FinalizeProcess() for
// process-scoped memory tear down.
bool
DetachProcess
()
{
bool
success
=
true
;
if
(
ThreadInitializeIndex
==
OS_INVALID_TLS_INDEX
)
return
true
;
success
=
DetachThread
();
OS_FreeTLSIndex
(
ThreadInitializeIndex
);
ThreadInitializeIndex
=
OS_INVALID_TLS_INDEX
;
return
success
;
}
}
// end namespace glslang
}
// end namespace glslang
OGLCompilersDLL/InitializeDll.h
View file @
11fa4d0d
...
@@ -38,10 +38,10 @@
...
@@ -38,10 +38,10 @@
namespace
glslang
{
namespace
glslang
{
bool
InitProcess
();
inline
bool
InitProcess
()
{
return
true
;
}
// DEPRECATED
bool
InitThread
();
inline
bool
InitThread
()
{
return
true
;
}
// DEPRECATED
bool
DetachThread
();
// not called from standalone, perhaps other tools rely on parts of it
inline
bool
DetachThread
()
{
return
true
;
}
// DEPRECATED
bool
DetachProcess
();
// not called from standalone, perhaps other tools rely on parts of it
inline
bool
DetachProcess
()
{
return
true
;
}
// DEPRECATED
}
// end namespace glslang
}
// end namespace glslang
...
...
glslang/Include/InitializeGlobals.h
View file @
11fa4d0d
...
@@ -37,7 +37,7 @@
...
@@ -37,7 +37,7 @@
namespace
glslang
{
namespace
glslang
{
bool
InitializePoolIndex
();
inline
bool
InitializePoolIndex
()
{
return
true
;
}
// DEPRECATED: No need to call
}
// end namespace glslang
}
// end namespace glslang
...
...
glslang/MachineIndependent/PoolAlloc.cpp
View file @
11fa4d0d
...
@@ -35,34 +35,28 @@
...
@@ -35,34 +35,28 @@
#include "../Include/Common.h"
#include "../Include/Common.h"
#include "../Include/PoolAlloc.h"
#include "../Include/PoolAlloc.h"
#include "../Include/InitializeGlobals.h"
#include "../OSDependent/osinclude.h"
namespace
glslang
{
namespace
glslang
{
// Process-wide TLS index
namespace
{
OS_TLSIndex
PoolIndex
;
thread_local
TPoolAllocator
*
threadPoolAllocator
=
nullptr
;
TPoolAllocator
*
GetDefaultThreadPoolAllocator
()
{
thread_local
TPoolAllocator
defaultAllocator
;
return
&
defaultAllocator
;
}
}
// anonymous namespace
// Return the thread-specific current pool.
// Return the thread-specific current pool.
TPoolAllocator
&
GetThreadPoolAllocator
()
TPoolAllocator
&
GetThreadPoolAllocator
()
{
{
return
*
static_cast
<
TPoolAllocator
*>
(
OS_GetTLSValue
(
PoolIndex
));
return
*
(
threadPoolAllocator
?
threadPoolAllocator
:
GetDefaultThreadPoolAllocator
(
));
}
}
// Set the thread-specific current pool.
// Set the thread-specific current pool.
void
SetThreadPoolAllocator
(
TPoolAllocator
*
poolAllocator
)
void
SetThreadPoolAllocator
(
TPoolAllocator
*
poolAllocator
)
{
{
OS_SetTLSValue
(
PoolIndex
,
poolAllocator
);
threadPoolAllocator
=
poolAllocator
;
}
// Process-wide set up of the TLS pool storage.
bool
InitializePoolIndex
()
{
// Allocate a TLS index.
if
((
PoolIndex
=
OS_AllocTLSIndex
())
==
OS_INVALID_TLS_INDEX
)
return
false
;
return
true
;
}
}
//
//
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment