rt/include/rt/tls.h

34 lines
1.1 KiB
C

#pragma once
#include <rt/stack.h>
#ifndef RT_TASK_LOCAL_STORAGE_ENABLE
#define RT_TASK_LOCAL_STORAGE_ENABLE 0
#endif // !defined(RT_TASK_LOCAL_STORAGE_ENABLE)
#if RT_TASK_LOCAL_STORAGE_ENABLE
#include <rt/arch/tls.h>
#ifndef RT_TASK_LOCAL_STORAGE_SIZE
#define RT_TASK_LOCAL_STORAGE_SIZE 32
#endif // !defined(RT_TASK_LOCAL_STORAGE_SIZE)
#endif // RT_TASK_LOCAL_STORAGE_ENABLE
/* During a context switch, the scheduler will call rt_tls_set in order to
* update the active thread-local storage pointer. */
void rt_tls_set(void *tls);
/* Get the current thread-local storage pointer. This may be used on platforms
* without toolchain support for thread-local storage. Platforms with toolchain
* support for thread-local storage need not implement this function. */
void *rt_tls_get(void);
#ifndef RT_TLS_SECTION
#define RT_TLS_SECTION(name) ".tls." #name
#endif
#define RT_TLS(name, size) \
char name[RT_STACK_SIZE(size)] \
__attribute__((aligned(RT_STACK_ALIGN(size)), \
section(RT_TLS_SECTION(name))))