Back to index

nux  3.0.0
Public Types | Static Public Member Functions | Static Public Attributes
nux::NThreadLocalStorage Class Reference

#include <ThreadGNU.h>

List of all members.

Public Types

enum  { NbTLS = 128, InvalidTLS = 0xFFFFFFFF }
typedef void(* TLS_ShutdownCallback )()

Static Public Member Functions

static void Initialize ()
static void Shutdown ()
static BOOL RegisterTLS (unsigned int index, TLS_ShutdownCallback shutdownCallback)
static BOOL UnRegisterTLS (unsigned int index)
static void ThreadInit ()
static void ThreadShutdown ()
template<class T >
static T GetData (unsigned int index)
template<class T >
static void SetData (unsigned int index, T value)

Static Public Attributes

static BOOL m_TLSUsed [NbTLS]
static __thread void * m_TLSIndex [NbTLS]
static TLS_ShutdownCallback m_TLSCallbacks [NbTLS]

Detailed Description

Definition at line 180 of file ThreadGNU.h.


Member Typedef Documentation

Definition at line 189 of file ThreadGNU.h.


Member Enumeration Documentation

anonymous enum
Enumerator:
NbTLS 
InvalidTLS 

Definition at line 183 of file ThreadGNU.h.

    {
      NbTLS = 128,
      InvalidTLS = 0xFFFFFFFF
    };

Member Function Documentation

template<class T >
static T nux::NThreadLocalStorage::GetData ( unsigned int  index) [inline, static]

Definition at line 204 of file ThreadGNU.h.

    {
      nuxAssert (sizeof (T) <= sizeof (size_t) );
      nuxAssert (index < NbTLS);
      nuxAssert (m_TLSUsed[index]);

      // T and (unsigned long) can be of different sizes
      // but this limits the use of GetData to classes without copy constructors
      union
      {
        T       t;
        void   *v;
      } temp;
      temp.v = m_TLSIndex[index];
      return temp.t;
    }

Definition at line 90 of file ThreadGNU.cpp.

  {
    for (unsigned int i = 0; i < NThreadLocalStorage::NbTLS; i++)
    {
      m_TLSUsed[i] = FALSE;
      // Fill the array with invalid values
      m_TLSIndex[i] = 0;
    }
  }

Here is the caller graph for this function:

BOOL nux::NThreadLocalStorage::RegisterTLS ( unsigned int  index,
NThreadLocalStorage::TLS_ShutdownCallback  shutdownCallback 
) [static]

Definition at line 68 of file ThreadGNU.cpp.

  {
    NUX_RETURN_VALUE_IF_FALSE(index < NThreadLocalStorage::NbTLS, FALSE);
    NUX_RETURN_VALUE_IF_TRUE(m_TLSUsed[index], TRUE); // already registered

    m_TLSUsed[index]  = TRUE;
    m_TLSCallbacks[index] =  shutdownCallback;
    return TRUE;
  }
template<class T >
static void nux::NThreadLocalStorage::SetData ( unsigned int  index,
value 
) [inline, static]

Definition at line 221 of file ThreadGNU.h.

    {
      nuxAssert (sizeof (T) <= sizeof (size_t) );
      nuxAssert (index < NbTLS);
      nuxAssert (m_TLSUsed[index]);

      // T and (unsigned long) can be of different sizes
      // but this limits the use of GetData to classes without copy constructors
      union
      {
        T       t;
        void   *v;
      } temp;
      temp.t = value;
      m_TLSIndex[index] = temp.v;
    }

Definition at line 100 of file ThreadGNU.cpp.

Here is the call graph for this function:

Definition at line 105 of file ThreadGNU.cpp.

  {
  }

Definition at line 109 of file ThreadGNU.cpp.

  {
    TLS_ShutdownCallback *callback = m_TLSCallbacks;

    for (unsigned int i = 0; i < NThreadLocalStorage::NbTLS; ++i, ++callback)
    {
      if (*callback)
      {
        (**callback) ();
      }
    }
  }

Here is the caller graph for this function:

BOOL nux::NThreadLocalStorage::UnRegisterTLS ( unsigned int  index) [static]

Definition at line 78 of file ThreadGNU.cpp.

  {
    NUX_RETURN_VALUE_IF_FALSE(index < NThreadLocalStorage::NbTLS, FALSE);
    NUX_RETURN_VALUE_IF_FALSE(m_TLSUsed[index], FALSE);

    m_TLSUsed[index]  = FALSE;
    m_TLSCallbacks[index] =  NULL;
    m_TLSIndex[index]  = NULL;

    return TRUE;
  }

Member Data Documentation

Definition at line 193 of file ThreadGNU.h.

__thread void * nux::NThreadLocalStorage::m_TLSIndex [static]

Definition at line 192 of file ThreadGNU.h.

Definition at line 191 of file ThreadGNU.h.


The documentation for this class was generated from the following files: