---
name: "ACE_TSS_Emulation"
section: "3"
platform: "linux"
package: "libace-doc"
version: "5.0.7-4"
release: "Debian 2.2 (Potato)"
platforms: ["linux"]
url: "https://new.carta.tech/ACE_TSS_Emulation"
---

# ACE\_TSS\_Emulation(3)

Thread-specific storage emulation.

## NAME

ACE\_TSS\_Emulation -  Thread-specific storage emulation.

## SYNOPSIS

```
#include <ace/OS.h>
class ACE_TSS_Emulation
{
  public:
    typedef void (*ACE_TSS_DESTRUCTOR)(void *value) /* throw () */;
    enum { ACE_TSS_THREAD_KEYS_MAX = ACE_DEFAULT_THREAD_KEYS };
    static u_int total_keys ();
    static int next_key (ACE_thread_key_t &key);
    static ACE_TSS_DESTRUCTOR tss_destructor (
        const ACE_thread_key_t key
        );
    static void tss_destructor (
        const ACE_thread_key_t key,
        ACE_TSS_DESTRUCTOR destructor
        );
    static void *&ts_object (const ACE_thread_key_t key);
    static void *tss_open (void *ts_storage[ACE_TSS_THREAD_KEYS_MAX]);
    static void tss_close ();
  private:
    static u_int total_keys_;
        static ACE_TSS_DESTRUCTOR tss_destructor_ [ACE_TSS_THREAD_KEYS_MAX];

    static void **tss_base (
        void* ts_storage[] = 0,
        u_int *ts_created = 0
        );
    static void **&tss_base ();
    static ACE_OS_thread_key_t native_tss_key_;
    static int key_created_;
};
```

## DESCRIPTION

This provides a thread-specific storage implementation. It is intended for use on platforms that don't have a native TSS, or have a TSS with limitations such as the number of keys or lack of support for removing keys.

## PUBLIC MEMBERS

```
typedef void (*ACE_TSS_DESTRUCTOR)(void *value) /* throw () */;
```

```
static u_int total_keys ();
```

Returns the total number of keys allocated so far.

```
static int next_key (ACE_thread_key_t &key);
```

Sets the argument to the next available key.  Returns 0 on success, -1 if no keys are available.

```
static ACE_TSS_DESTRUCTOR tss_destructor (const ACE_thread_key_t key);
```

Returns the exit hook associated with the key.  Does \_not\_ check for a valid key.

```
static void tss_destructor (
    const ACE_thread_key_t key,
    ACE_TSS_DESTRUCTOR destructor
    );
```

Associates the TSS destructor with the key.  Does \_not\_ check for a valid key.

```
static void *&ts_object (const ACE_thread_key_t key);
```

Accesses the object referenced by key in the current thread's TSS array. Does \_not\_ check for a valid key.

```
static void *tss_open (void *ts_storage[ACE_TSS_THREAD_KEYS_MAX]);
```

Setup an array to be used for local TSS.  Returns the array address on success.  Returns 0 if local TSS had already been setup for this thread.  There is no corresponding tss\_close () because it is not needed. NOTE: tss\_open () is called by ACE for threads that it spawns. If your application spawns threads without using ACE, and it uses ACE's TSS emulation, each of those threads should call tss\_open ().  See the ace\_thread\_adapter () implementaiton for an example.

```
static void tss_close ();
```

Shutdown TSS emulation.  For use only by ACE\_OS::cleanup\_tss ().

## PRIVATE MEMBERS

```
static u_int total_keys_;
```

Always contains the value of the next key to be allocated.

```
static ACE_TSS_DESTRUCTOR tss_destructor_ [ACE_TSS_THREAD_KEYS_MAX];
```

Array of thread exit hooks (TSS destructors) that are called for each key (that has one) when the thread exits.

```
static void **tss_base (
    void* ts_storage[] = 0,
    u_int *ts_created = 0
    );
```

Location of current thread's TSS array.

```
static void **&tss_base ();
```

Location of current thread's TSS array.

```
static ACE_OS_thread_key_t native_tss_key_;
```

```
static int key_created_;
```

## AUTHOR

Doug Schmidt schmidt@cs.wustl.edu, Jesper S. M\|ller stophph@diku.dk, and a cast of thousands...

## The ACE\_Sched\_Priority type should be used for platform-

independent thread and process priorities, by convention. int should be used for OS-specific priorities.

## typedef for the \_stat data structure

## Giving unique ACE scoped names for some important

RTSignal-Related constants. Becuase sometimes, different platforms use different names for these constants.

## LIBRARY

ace
