Home | History | Annotate | Download | only in translator
      1 //
      2 // Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
      3 // Use of this source code is governed by a BSD-style license that can be
      4 // found in the LICENSE file.
      5 //
      6 
      7 #include "compiler/translator/InitializeParseContext.h"
      8 
      9 #include "common/tls.h"
     10 
     11 #include <assert.h>
     12 
     13 TLSIndex GlobalParseContextIndex = TLS_INVALID_INDEX;
     14 
     15 bool InitializeParseContextIndex()
     16 {
     17     assert(GlobalParseContextIndex == TLS_INVALID_INDEX);
     18 
     19     GlobalParseContextIndex = CreateTLSIndex();
     20     return GlobalParseContextIndex != TLS_INVALID_INDEX;
     21 }
     22 
     23 void FreeParseContextIndex()
     24 {
     25     assert(GlobalParseContextIndex != TLS_INVALID_INDEX);
     26 
     27     DestroyTLSIndex(GlobalParseContextIndex);
     28     GlobalParseContextIndex = TLS_INVALID_INDEX;
     29 }
     30 
     31 void SetGlobalParseContext(TParseContext* context)
     32 {
     33     assert(GlobalParseContextIndex != TLS_INVALID_INDEX);
     34     SetTLSValue(GlobalParseContextIndex, context);
     35 }
     36 
     37 TParseContext* GetGlobalParseContext()
     38 {
     39     assert(GlobalParseContextIndex != TLS_INVALID_INDEX);
     40     return static_cast<TParseContext*>(GetTLSValue(GlobalParseContextIndex));
     41 }
     42 
     43