Sane C++ Libraries
C++ Platform Abstraction Libraries
Globals.h
1// Copyright (c) Stefano Cristiano
2// SPDX-License-Identifier: MIT
3#pragma once
4#include "../Foundation/PrimitiveTypes.h"
5namespace SC
6{
7struct SC_COMPILER_EXPORT GlobalSettings;
8struct SC_COMPILER_EXPORT Globals;
9struct MemoryAllocator;
10} // namespace SC
13
16{
18};
19
37{
38 enum Type
39 {
40 Global = 0,
42 };
43 MemoryAllocator& allocator;
44
45 Globals(MemoryAllocator& allocator) : allocator(allocator) {}
46
49 static void init(Type type, GlobalSettings settings = {});
50
53 static Globals* push(Type type, Globals& globals);
54
57 static Globals* pop(Type type);
58
60 static Globals& get(Type type);
61
62 private:
63 Globals* prev = nullptr; // Pointer to previous Globals to restore on ::pop()
64 struct Internal;
65};
66
#define SC_COMPILER_EXPORT
Macro for symbol visibility in non-MSVC compilers.
Definition: Compiler.h:78
Settings to initialize Globals.
Definition: Globals.h:16
size_t ownershipTrackingBytes
Memory to allocate for ownership tracking.
Definition: Globals.h:17
Customizable thread-local and global variables for memory handling.
Definition: Globals.h:37
static Globals * push(Type type, Globals &globals)
Sets Globals as current, saving previous one.
static Globals & get(Type type)
Obtains current set of Globals.
static Globals * pop(Type type)
Restores Globals previously replaced by a push.
Type
Definition: Globals.h:39
@ Global
Shared globals (NOT thread-safe)
Definition: Globals.h:40
@ ThreadLocal
Thread-specific globals (separate copy for each thread)
Definition: Globals.h:41
static void init(Type type, GlobalSettings settings={})
Initialized Globals for current thread.
Customizable functions to allocate, reallocate and deallocate memory.
Definition: Memory.h:36