ThreadLocalPointer Class Reference

#include <threadlocalpointer.h>

Inheritance diagram for ThreadLocalPointer:

详细描述

Thread local pointer (to a data structure). Different threads may use this class to store different (local) values to it. These values are typically pointers to data which is to be used by the calling thread only.

注意
Thread local pointers are a scarce resource. Only a limited number of them can be allocated: On Windows about 1000 and on OS X about 500. You should only use them if they are the last and only resort to solve a problem. Furthemore for performance reasons it is best to avoid thread local pointers at all and instead use some sort of local context (for a group's jobs or with ParallelFor ).
A thread local pointer is bound to a OS thread and the pointer is stored for the lifetime of the thread.

公共成员函数

  ThreadLocalPointer ()
  ~ThreadLocalPointer ()
Bool   Init ()
void *  Get () const
Bool   Set (void *value)
Bool   重置 ()
Bool   IsValid () const

Protected Attributes

pthread_key_t  _key

Static Private Attributes

static const pthread_key_t  INVALID_KEY

构造函数 & 析构函数文档编制

◆  ThreadLocalPointer()

ThreadLocalPointer ( )

◆  ~ThreadLocalPointer()

~ ThreadLocalPointer ( )

成员函数文档编制

◆  Init()

Bool Init ( )

Allocates and initializes a thread local pointer.

注意
If you Init() an already initialized thread local pointer, a new one will be created and you cannot access the old one anymore. This behaviour is intended.
返回
False if thread local pointer cannot be created.

◆  Get()

void* Get ( ) const

Returns a thread local pointer value.

注意
If no value has been set yet, this function returns nullptr. THREADSAFE.
返回
Thread local pointer value.

◆  Set()

Bool Set ( void *  value )

Sets a thread local pointer value.

参数
[in] value Thread local pointer value. THREADSAFE.
返回
True unless an initial memory allocation failed or the initialization was missing.

◆  Reset()

Bool 重置 ( )

Resets a thread local pointer to the uninitialized state.

返回
False if previously uninitialized.

◆  IsValid()

Bool IsValid ( ) const

For debugging purposes.

返回
True if initialized.

Member Data Documentation

◆  INVALID_KEY

const pthread_key_t INVALID_KEY static private

◆  _key

pthread_key_t _key protected