These functions provide support for thread-local data structures defined by
types that are automatically initialized and destroyed.
A thread-local data structure is described by a static or global
each such structure must be initialized with the
static struct tinfo foo_info
= TINFO_INIT(&foo_type, "foo", fooinit);
type for the data structure,
type used to allocate memory to hold each threads instance, and
is an optional instance initializer function of this type:
typedef int tinfo_init_t(struct tinfo *t, void *data);
should initialize the data structure pointed to by
as an instance of
(which will also be available as
The memory pointed to by
will have been allocated with
but will be otherwise uninitialized.
is used to initialize the data structure to the default value defined by
thread-local data structure are automatically destroyed when the associated
thread exits, by calling
structs_free type NULL data
FREE mtype data.
returns the current threads instance of the data structure.
If this is the threads first invocation of
a new instance is automatically allocated and initialized.
The caller should
free the returned value, but may modify it in a way consistent
sets the current threads data structure instance to be a copy of
is unmodified and remains the callers responsibility to free.
Any existing thread-local data structure instance is automatically
replaced and freed.
is equivalent to
except that no copy of
is made; therefore,
must point to heap memory allocated with
(also available as
and the caller should not dereference
has returned successfully.
may take a
parameter; this causes any existing thread-local data structure instance
to be freed so that the next call to
will cause a new instance to be constructed.