KallistiOS  ##version##
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Data Structures | Typedefs | Functions
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
 Thread-local storage key-value pair. More...
 

Typedefs

typedef int kthread_key_t
 Thread-local storage key type. More...
 
typedef struct kthread_tls_kv kthread_tls_kv_t
 Thread-local storage key-value pair. More...
 

Functions

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

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

typedef int kthread_key_t

Thread-local storage key type.

Thread-local storage key-value pair.

This is the structure that is actually used to store the specific value for a thread for a single TLS key.

You will not end up using these directly at all in programs, as they are only used internally.

Function Documentation

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.
int kthread_key_create ( kthread_key_t key,
void(*)(void *)  destructor 
)

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.
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.
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.