Thread-local storage support.
More...
#include <sys/cdefs.h>
#include <sys/queue.h>
Go to the source code of this file.
Thread-local storage support.
This file contains the definitions used to support key/value pairs of thread-local storage in KOS.
- Author
- Lawrence Sebald
◆ kthread_key_t
Thread-local storage key type.
◆ kthread_getspecific()
Retrieve a value associated with a TLS key.
This function retrieves the thread-specific data associated with the given key.
- Parameters
-
key | The key to look up data for. |
- Returns
- The data associated with the key, or NULL if the key is not valid or no data has been set in the current thread.
◆ kthread_key_create()
int kthread_key_create |
( |
kthread_key_t * | key, |
|
|
void(* | destructor )(void *) ) |
Create a new thread-local storage key.
This function creates a new thread-local storage key that shall be visible to all threads. Each thread is then responsible for associating any data with the key that it deems fit (by default a thread will have no data associated with a newly created key).
- Parameters
-
key | The key to use. |
destructor | A destructor for use with this key. If it is non-NULL, and a value associated with the key is non-NULL at thread exit, then the destructor will be called with the value as its argument. |
- Return values
-
-1 | On failure, and sets errno to one of the following: EPERM if called inside an interrupt and another call is in progress, ENOMEM if out of memory. |
0 | On success. |
◆ kthread_key_delete()
Delete a TLS key.
This function deletes a TLS key, removing all threads' values for the given key. This function does not cause any destructors to be called.
- Parameters
-
- Return values
-
-1 | On failure, and sets errno to one of the following: EINVAL if the key is invalid, EPERM if unsafe to call free. |
0 | On success. |
◆ kthread_setspecific()
int kthread_setspecific |
( |
kthread_key_t | key, |
|
|
const void * | value ) |
Set thread specific data for a key.
This function sets the thread-specific data associated with the given key.
- Parameters
-
key | The key to set data for. |
value | The thread-specific value to use. |
- Return values
-
-1 | On failure, and sets errno to one of the following: EINVAL if the key is not valid, ENOMEM if out of memory, or EPERM if called inside an interrupt and another call is in progress. |
0 | On success. |