Memory: Reference count number of clients, to support multiple independent clients in same process.

Addresses 2nd item in #976.
This commit is contained in:
John Kessenich 2017-11-16 22:48:41 -07:00
parent b63f4a3808
commit e2c15b4f6e
2 changed files with 25 additions and 6 deletions

View file

@ -69,6 +69,10 @@
namespace { // anonymous namespace for file-local functions and symbols
// Total number of successful initializers of glslang: a refcount
// Shared global; access should be protected by a global mutex/critical section.
int NumberOfClients = 0;
using namespace glslang;
// Create a language specific version of parseables.
@ -1193,6 +1197,10 @@ int ShInitialize()
if (! InitProcess())
return 0;
glslang::GetGlobalLock();
++NumberOfClients;
glslang::ReleaseGlobalLock();
if (PerProcessGPA == nullptr)
PerProcessGPA = new TPoolAllocator();
@ -1259,6 +1267,14 @@ void ShDestruct(ShHandle handle)
//
int __fastcall ShFinalize()
{
glslang::GetGlobalLock();
--NumberOfClients;
assert(NumberOfClients >= 0);
bool finalize = NumberOfClients == 0;
glslang::ReleaseGlobalLock();
if (! finalize)
return 1;
for (int version = 0; version < VersionCount; ++version) {
for (int spvVersion = 0; spvVersion < SpvVersionCount; ++spvVersion) {
for (int p = 0; p < ProfileCount; ++p) {