Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

iv_tls_user_ptr(3) [debian man page]

iv_tls(3)						    ivykis programmer's manual							 iv_tls(3)

NAME
iv_tls_user_register, iv_tls_user_ptr - thread-local storage handling for ivykis modules SYNOPSIS
#include <iv_tls.h> struct iv_tls_user { size_t sizeof_state; void (*init_thread)(void *st); void (*deinit_thread)(void *st); }; void iv_tls_user_register(struct iv_tls_user *tu); void *iv_tls_user_ptr(struct iv_tls_user *tu); DESCRIPTION
The iv_tls interface provides thread-local storage handling to ivykis modules. An ivykis module can arrange for an amount of memory to be allocated for its use in each ivykis thread by calling iv_tls_user_register. This must be done before any calls to iv_init have been made in this process, and is typically done from a module initialization function marked as a constructor function. The ->sizeof_state member of the passed-in structure indicates how many bytes of memory the module wants allocated for its use in every ivykis thread. When a thread calls iv_init, ->sizeof_state bytes of memory will be allocated for use by this module in that thread, and initialised to zero. A pointer to this memory area can be obtained by calling iv_tls_user_ptr (which returns NULL in non-ivykis threads). If the specified ->init_thread function pointer is not NULL, it will be invoked at the end of iv_init, with its argument pointing to this thread's memory area allocation for this module. If ->deinit_thread is not NULL, it will be invoked at the start of iv_deinit, or if the thread fails to call iv_deinit before terminating, at thread termination time. The argument passed into ->deinit_thread is the same as for ->init_thread. It is permitted to call any ivykis API functions from the ->init_thread and ->deinit_thread callbacks. There is no explicit serialization on calls to ->init_thread and ->deinit_thread. Care must be taken when calling iv_tls_user_ptr from a signal handler, as there is a time window where it will return a non-NULL value before ->init_thread or after ->deinit_thread have been called. Use of iv_tls for managing thread-local state is preferred over direct use of the __thread keyword, as not all platforms that ivykis runs on provide the __thread keyword. Use of iv_tls for managing thread-local state is preferred over direct use of the pthread_key_create and pthread_setspecific APIs, as iv_tls provides a thread init hook as well as a destructor hook, and properly sequences ->init_thread and ->deinit_thread calls with core ivykis initialization and cleanup. SEE ALSO
iv_init(3) ivykis 2012-03-30 iv_tls(3)

Check Out this Related Man Page

iv_event(3)						    ivykis programmer's manual						       iv_event(3)

NAME
IV_EVENT_INIT, iv_event_register, iv_event_unregister, iv_event_post - manage ivykis objects for event notification SYNOPSIS
#include <iv_event.h> struct iv_event { void *cookie; void (*handler)(void *); }; int IV_EVENT_INIT(struct iv_event *this); int iv_event_register(struct iv_event *this); void iv_event_unregister(struct iv_event *this); void iv_event_post(struct iv_event *this); DESCRIPTION
iv_event provides a way for delivering events to ivykis(3) recipients across thread boundaries. The intended event recipient calls IV_EVENT_INIT on a struct iv_event object, fills in ->cookie and ->handler, and then calls iv_event_reg- ister on the object. To generate an event, call iv_event_post on the previously initialized struct iv_event object. This will cause the callback specified by ->handler to be called in the thread that the struct iv_event object was registered in, with ->cookie as its sole argument. To deinitialize a struct iv_event object, call iv_event_unregister from the same thread that iv_event_register was called from on that object. It is permitted to unregister a struct iv_event object from any ivykis callback function in the thread it was registered in, including from a callback function triggered by this object, and it is permitted to free the memory corresponding to an unregistered object from its own callback function. iv_event_post can be called from the same thread that iv_event_register was called from, or from a different thread within the same process, but can not be called from a different process, and can not be called from signal handlers. If you need this functionality, look at iv_event_raw(3). Internally, iv_event is implemented as a wrapper around iv_event_raw(3), and multiplexes multiple struct iv_event objects over per-thread struct iv_event_raw objects, to save file descriptors and kernel resources. SEE ALSO
ivykis(3), iv_event_raw(3) ivykis 2010-09-03 iv_event(3)
Man Page