blob: 7a95658e7bd7cc906734788436cfa1bc0a7912e9 [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
2// Copyright (c) 2002-2010 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
Geoff Lang17732822013-08-29 13:46:49 -04007#include "compiler/translator/PoolAlloc.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008
Jamie Madillb980c562018-11-27 11:34:27 -05009#include <assert.h>
Jamie Madill438dbcf2016-06-17 14:20:05 -040010#include "common/tls.h"
Jamie Madill438dbcf2016-06-17 14:20:05 -040011
Geoff Lang44fa7592014-05-30 11:50:07 -040012TLSIndex PoolIndex = TLS_INVALID_INDEX;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000013
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000014bool InitializePoolIndex()
15{
Geoff Lang44fa7592014-05-30 11:50:07 -040016 assert(PoolIndex == TLS_INVALID_INDEX);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000017
Geoff Lang44fa7592014-05-30 11:50:07 -040018 PoolIndex = CreateTLSIndex();
19 return PoolIndex != TLS_INVALID_INDEX;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000020}
21
22void FreePoolIndex()
23{
Geoff Lang44fa7592014-05-30 11:50:07 -040024 assert(PoolIndex != TLS_INVALID_INDEX);
Alok Priyadarshi8156b6b2013-09-23 14:56:58 -040025
Geoff Lang44fa7592014-05-30 11:50:07 -040026 DestroyTLSIndex(PoolIndex);
27 PoolIndex = TLS_INVALID_INDEX;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000028}
29
Tobin Ehlis05459e02019-01-17 12:25:54 -050030angle::PoolAllocator *GetGlobalPoolAllocator()
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000031{
Geoff Lang44fa7592014-05-30 11:50:07 -040032 assert(PoolIndex != TLS_INVALID_INDEX);
Tobin Ehlis05459e02019-01-17 12:25:54 -050033 return static_cast<angle::PoolAllocator *>(GetTLSValue(PoolIndex));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000034}
35
Tobin Ehlis05459e02019-01-17 12:25:54 -050036void SetGlobalPoolAllocator(angle::PoolAllocator *poolAllocator)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000037{
Geoff Lang44fa7592014-05-30 11:50:07 -040038 assert(PoolIndex != TLS_INVALID_INDEX);
39 SetTLSValue(PoolIndex, poolAllocator);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000040}