blob: dfab027330de959162aba6eae825830d9250b493 [file] [log] [blame]
John Bauman66b8ab22014-05-06 15:57:45 -04001//
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/InitializeParseContext.h"
8
9#include "compiler/osinclude.h"
10
11OS_TLSIndex GlobalParseContextIndex = OS_INVALID_TLS_INDEX;
12
13bool InitializeParseContextIndex()
14{
Nicolas Capens978ddc52014-11-11 12:42:08 -050015 assert(GlobalParseContextIndex == OS_INVALID_TLS_INDEX);
John Bauman66b8ab22014-05-06 15:57:45 -040016
John Bauman66b8ab22014-05-06 15:57:45 -040017 GlobalParseContextIndex = OS_AllocTLSIndex();
Nicolas Capens978ddc52014-11-11 12:42:08 -050018 return GlobalParseContextIndex != OS_INVALID_TLS_INDEX;
John Bauman66b8ab22014-05-06 15:57:45 -040019}
20
Nicolas Capens978ddc52014-11-11 12:42:08 -050021void FreeParseContextIndex()
John Bauman66b8ab22014-05-06 15:57:45 -040022{
Nicolas Capens978ddc52014-11-11 12:42:08 -050023 assert(GlobalParseContextIndex != OS_INVALID_TLS_INDEX);
John Bauman66b8ab22014-05-06 15:57:45 -040024
Nicolas Capens978ddc52014-11-11 12:42:08 -050025 OS_FreeTLSIndex(GlobalParseContextIndex);
John Bauman66b8ab22014-05-06 15:57:45 -040026 GlobalParseContextIndex = OS_INVALID_TLS_INDEX;
John Bauman66b8ab22014-05-06 15:57:45 -040027}
28
Nicolas Capens978ddc52014-11-11 12:42:08 -050029void SetGlobalParseContext(TParseContext* context)
John Bauman66b8ab22014-05-06 15:57:45 -040030{
Nicolas Capens978ddc52014-11-11 12:42:08 -050031 assert(GlobalParseContextIndex != OS_INVALID_TLS_INDEX);
32 OS_SetTLSValue(GlobalParseContextIndex, context);
John Bauman66b8ab22014-05-06 15:57:45 -040033}
34
Nicolas Capens978ddc52014-11-11 12:42:08 -050035TParseContext* GetGlobalParseContext()
John Bauman66b8ab22014-05-06 15:57:45 -040036{
Nicolas Capens978ddc52014-11-11 12:42:08 -050037 assert(GlobalParseContextIndex != OS_INVALID_TLS_INDEX);
38 return static_cast<TParseContext*>(OS_GetTLSValue(GlobalParseContextIndex));
John Bauman66b8ab22014-05-06 15:57:45 -040039}
40