KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
tls.h File Reference

Thread-local storage support. More...

#include <sys/cdefs.h>
#include <sys/queue.h>

Go to the source code of this file.

Data Structures

struct  kthread_tls_kv_t
 Thread-local storage key-value pair. More...
 

Typedefs

typedef int kthread_key_t
 Thread-local storage key type.
 

Functions

int kthread_key_create (kthread_key_t *key, void(*destructor)(void *))
 Create a new thread-local storage key.
 
void * kthread_getspecific (kthread_key_t key)
 Retrieve a value associated with a TLS key.
 
int kthread_setspecific (kthread_key_t key, const void *value)
 Set thread specific data for a key.
 
int kthread_key_delete (kthread_key_t key)
 Delete a TLS key.
 

Detailed Description

Thread-local storage support.

This file contains the definitions used to support key/value pairs of thread-local storage in KOS.

Author
Lawrence Sebald

Typedef Documentation

◆ kthread_key_t

typedef int kthread_key_t

Thread-local storage key type.

Function Documentation

◆ kthread_getspecific()

void * kthread_getspecific ( kthread_key_t key)

Retrieve a value associated with a TLS key.

This function retrieves the thread-specific data associated with the given key.

Parameters
keyThe 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
keyThe key to use.
destructorA 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
-1On 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.
0On success.

◆ kthread_key_delete()

int kthread_key_delete ( kthread_key_t key)

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
keyThe key to delete.
Return values
-1On failure, and sets errno to one of the following: EINVAL if the key is invalid, EPERM if unsafe to call free.
0On 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
keyThe key to set data for.
valueThe thread-specific value to use.
Return values
-1On 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.
0On success.