OpenMPI  0.1.1
tsd.h File Reference

Thread Specific Datastore Interface. More...

#include "opal_config.h"
#include "opal/constants.h"

Go to the source code of this file.

Typedefs

typedef void(* opal_tsd_destructor_t )(void *value)
 Prototype for callback when tsd data is being destroyed.
 
typedef void * opal_tsd_key_t
 Typedef for thread-specific data key.
 

Functions

OPAL_DECLSPEC int opal_tsd_key_create (opal_tsd_key_t *key, opal_tsd_destructor_t destructor)
 Create thread-specific data key. More...
 
OPAL_DECLSPEC int opal_tsd_key_delete (opal_tsd_key_t key)
 Delete a thread-specific data key. More...
 
OPAL_DECLSPEC int opal_tsd_setspecific (opal_tsd_key_t key, void *value)
 Set a thread-specific data value. More...
 
OPAL_DECLSPEC int opal_tsd_getspecific (opal_tsd_key_t key, void **valuep)
 Get a thread-specific data value. More...
 

Detailed Description

Thread Specific Datastore Interface.

Functions for providing thread-specific datastore capabilities.

Function Documentation

OPAL_DECLSPEC int opal_tsd_getspecific ( opal_tsd_key_t  key,
void **  valuep 
)

Get a thread-specific data value.

Get the data associated with the given key, as set by opal_tsd_setspecific(). If opal_tsd_setspecific() hasn't been called in the current thread with the given key, NULL is returned in valuep.

Parameters
key[in]Thread specific data key to modify
value[out]Value to associate with key
Return values
OPAL_SUCCESSSuccess
ENOMEMInsufficient memory exists to associate the value with the key
EINVALInvalid key
OPAL_DECLSPEC int opal_tsd_key_create ( opal_tsd_key_t key,
opal_tsd_destructor_t  destructor 
)

Create thread-specific data key.

Create a thread-specific data key visible to all threads in the current process. The returned key is valid in all threads, although the values bound to the key by opal_tsd_setspecific() are allocated on a per-thread basis and persist for the life of the calling thread.

Upon key creation, the value NULL is associated with the new key in all active threads. When a new thread is created, the value NULL is associated with all defined keys in the new thread.

The destructor parameter may be NULL. At thread exit, if destructor is non-NULL AND the thread has a non-NULL value associated with the key, the function is called with the current value as its argument.

Parameters
key[out]The key for accessing thread-specific data
destructor[in]Cleanup function to call when a thread exits
Return values
OPAL_SUCCESSSuccess
EAGAINThe system lacked the necessary resource to create another thread specific data key
ENOMEMInsufficient memory exists to create the key
OPAL_DECLSPEC int opal_tsd_key_delete ( opal_tsd_key_t  key)

Delete a thread-specific data key.

Delete a thread-specific data key previously returned by opal_tsd_key_create(). The destructor associated with the key is not fired in any thread and memory cleanup is the responsibility of the caller.

Note
Unlike pthread_key_delete, this function should not be called from within a destructor. It can not be universally supported at this time.
Parameters
key[in]The key for accessing thread-specific data
Return values
OPAL_SUCCESSSuccess
EINVALInvalid key
OPAL_DECLSPEC int opal_tsd_setspecific ( opal_tsd_key_t  key,
void *  value 
)

Set a thread-specific data value.

Associates value with key in the current thread. The value for the key in other threads is not changed. Different threads may assign different values to the same key.

Note
This function should not be called within opal_tsd_key_delete().
Parameters
key[in]Thread specific data key to modify
value[in]Value to associate with key
Return values
OPAL_SUCCESSSuccess
ENOMEMInsufficient memory exists to associate the value with the key
EINVALInvalid key