P99
Data Fields
p99_tss Struct Reference

A stub structure to hold a thread local variable if thread_local is not available. More...

#include <p99_tss.h>

Data Fields

tss_dtor_t p99_dtor
 Destructor function that is automatically called at the termination of a thread. More...
 

Detailed Description

A stub structure to hold a thread local variable if thread_local is not available.

In most cases you wouldn't use this type directly but use P99_TSS_DECLARE_LOCAL to declare a variable and P99_TSS_LOCAL to access it. This should in particular be the case where you don't make explicit use of p99_dtor to destroy particular instances of the variable.

The advantage of p99_tss over the C11 type tss_t is that it doesn't need an equivalent of ::tss_create. If they are properly initialized with the default initializer, variables of this type here will do the dynamic part of the initialization automatically at the first use. This could come with a tiny overhead of some instructions, which normally shouldn't even be measurable.

The dynamic initialization needs to know what the destructor function of the TSS should be. It can be provided through the field p99_dtor. If p99_dtor is 0 no destructor will be called.

The functions that are implemented follow the same line as those for tss_t, only that they always receive a pointer to a p99_tss such that they will be able to perform the initialization if necessary.

In addition to the tss_t interfaces we have #p99_tss_get_alloc to allocate a buffer if the TSS was not yet set for the executing thread before. Both need that the destructor value p99_dtor and the one that has been passed to the call to ::tss_create are consistent. Don't mess around with that.

See also
P99_TSS_DECLARE_LOCAL
P99_DECLARE_THREAD_LOCAL

Definition at line 230 of file p99_tss.h.


The documentation for this struct was generated from the following file: