libGimbal 0.2.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_tls.h
Go to the documentation of this file.
1/*! \file
2 * \brief Thread-local variable management
3 * \ingroup core
4 *
5 * This file provides a pair of macros serving as an abstraction layer
6 * between a platform's preferred thread-local storage mechanism, and
7 * the application.
8 *
9 * Where supported, GBL_TLS() will use real, compiler-enabled static
10 * TLS by simply declaring the variable with the "thread_local" keyword
11 * and proceeding to access it normally.
12 *
13 * If this preferred path is not available, using the same semantics,
14 * TinyCThread will emulate this behavior by creating OS-level TLS storage.
15 * In a single-threaded build, it will use ordinary static storage.
16 *
17 * \author 2023 Falco Girgis
18 * \author 2026 Agustín Bellagamba
19 * \copyright MIT License
20 */
21
22#ifndef GIMBAL_TLS_H
23#define GIMBAL_TLS_H
24
25#include <tinycthread_tls.h>
26
27/*! \def GBL_TLS(type, name, init)
28 *
29 * Defines a thread-local variable using the given information,
30 * and either using compiler or OS-level TLS depending on the
31 * platform.
32 *
33 * \param type variable type
34 * \param name variable name
35 * \param init variable initializer
36 *
37 * \sa GBL_TLS_LOAD()
38 */
39#define GBL_TLS(type, name, ...) TTHREAD_TLS(type, name, __VA_ARGS__)
40
41/*! \def GBL_TLS_LOAD(name)
42 *
43 * Fetches a pointer to a thread-local variable that was
44 * previously declared with GBL_TLS()
45 *
46 * \param name variable name
47 * \return pointer address of the given TLS variable
48 *
49 * \sa GBL_TLS()
50 */
51#define GBL_TLS_LOAD(name) TTHREAD_TLS_LOAD(name)
52
53#endif // GIMBAL_TLS_H