Fixed memory leak associated with TLS.

We used to allocate thread-local memory on each compile.
If the compile did not happen on the same thread as ShInitialize,
we leaked the thread-local memory.

It turns out that there is no need to allocate any thread-local
memory. This patch cleans up all the unnecessary junk around TLS.

BUG=chromium:181691

Change-Id: I4b67ab23dc856d93424ae51ebf8aaf8966b732e4
Reviewed-on: https://swiftshader-review.googlesource.com/1361
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/OpenGL/compiler/InitializeParseContext.cpp b/src/OpenGL/compiler/InitializeParseContext.cpp
index 1f40cf5..dfab027 100644
--- a/src/OpenGL/compiler/InitializeParseContext.cpp
+++ b/src/OpenGL/compiler/InitializeParseContext.cpp
@@ -12,85 +12,29 @@
 
 bool InitializeParseContextIndex()
 {
-    if (GlobalParseContextIndex != OS_INVALID_TLS_INDEX) {
-        assert(0 && "InitializeParseContextIndex(): Parse Context already initalized");
-        return false;
-    }
+    assert(GlobalParseContextIndex == OS_INVALID_TLS_INDEX);
 
-    //
-    // Allocate a TLS index.
-    //
     GlobalParseContextIndex = OS_AllocTLSIndex();
-    
-    if (GlobalParseContextIndex == OS_INVALID_TLS_INDEX) {
-        assert(0 && "InitializeParseContextIndex(): Parse Context already initalized");
-        return false;
-    }
-
-    return true;
+    return GlobalParseContextIndex != OS_INVALID_TLS_INDEX;
 }
 
-bool FreeParseContextIndex()
+void FreeParseContextIndex()
 {
-    OS_TLSIndex tlsiIndex = GlobalParseContextIndex;
+    assert(GlobalParseContextIndex != OS_INVALID_TLS_INDEX);
 
-    if (GlobalParseContextIndex == OS_INVALID_TLS_INDEX) {
-        assert(0 && "FreeParseContextIndex(): Parse Context index not initalized");
-        return false;
-    }
-
+    OS_FreeTLSIndex(GlobalParseContextIndex);
     GlobalParseContextIndex = OS_INVALID_TLS_INDEX;
-
-    return OS_FreeTLSIndex(tlsiIndex);
 }
 
-bool InitializeGlobalParseContext()
+void SetGlobalParseContext(TParseContext* context)
 {
-    if (GlobalParseContextIndex == OS_INVALID_TLS_INDEX) {
-        assert(0 && "InitializeGlobalParseContext(): Parse Context index not initalized");
-        return false;
-    }
-
-    TThreadParseContext *lpParseContext = static_cast<TThreadParseContext *>(OS_GetTLSValue(GlobalParseContextIndex));
-    if (lpParseContext != 0) {
-        assert(0 && "InitializeParseContextIndex(): Parse Context already initalized");
-        return false;
-    }
-
-    TThreadParseContext *lpThreadData = new TThreadParseContext();
-    if (lpThreadData == 0) {
-        assert(0 && "InitializeGlobalParseContext(): Unable to create thread parse context");
-        return false;
-    }
-
-    lpThreadData->lpGlobalParseContext = 0;
-    OS_SetTLSValue(GlobalParseContextIndex, lpThreadData);
-
-    return true;
+    assert(GlobalParseContextIndex != OS_INVALID_TLS_INDEX);
+    OS_SetTLSValue(GlobalParseContextIndex, context);
 }
 
-bool FreeParseContext()
+TParseContext* GetGlobalParseContext()
 {
-    if (GlobalParseContextIndex == OS_INVALID_TLS_INDEX) {
-        assert(0 && "FreeParseContext(): Parse Context index not initalized");
-        return false;
-    }
-
-    TThreadParseContext *lpParseContext = static_cast<TThreadParseContext *>(OS_GetTLSValue(GlobalParseContextIndex));
-    if (lpParseContext)
-        delete lpParseContext;
-
-    return true;
-}
-
-TParseContextPointer& GetGlobalParseContext()
-{
-    //
-    // Minimal error checking for speed
-    //
-
-    TThreadParseContext *lpParseContext = static_cast<TThreadParseContext *>(OS_GetTLSValue(GlobalParseContextIndex));
-
-    return lpParseContext->lpGlobalParseContext;
+    assert(GlobalParseContextIndex != OS_INVALID_TLS_INDEX);
+    return static_cast<TParseContext*>(OS_GetTLSValue(GlobalParseContextIndex));
 }