xref: /aosp_15_r20/external/angle/src/compiler/translator/PoolAlloc.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2002 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/PoolAlloc.h"
8 
9 #include "common/debug.h"
10 #include "common/tls.h"
11 
12 angle::TLSIndex PoolIndex = TLS_INVALID_INDEX;
13 
InitializePoolIndex()14 bool InitializePoolIndex()
15 {
16     ASSERT(PoolIndex == TLS_INVALID_INDEX);
17 
18     PoolIndex = angle::CreateTLSIndex(nullptr);
19     return PoolIndex != TLS_INVALID_INDEX;
20 }
21 
FreePoolIndex()22 void FreePoolIndex()
23 {
24     ASSERT(PoolIndex != TLS_INVALID_INDEX);
25 
26     angle::DestroyTLSIndex(PoolIndex);
27     PoolIndex = TLS_INVALID_INDEX;
28 }
29 
GetGlobalPoolAllocator()30 angle::PoolAllocator *GetGlobalPoolAllocator()
31 {
32     ASSERT(PoolIndex != TLS_INVALID_INDEX);
33     return static_cast<angle::PoolAllocator *>(angle::GetTLSValue(PoolIndex));
34 }
35 
SetGlobalPoolAllocator(angle::PoolAllocator * poolAllocator)36 void SetGlobalPoolAllocator(angle::PoolAllocator *poolAllocator)
37 {
38     ASSERT(PoolIndex != TLS_INVALID_INDEX);
39     angle::SetTLSValue(PoolIndex, poolAllocator);
40 }
41