---
name: "ACE_Token_Manager"
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_Token_Manager"
---

# ACE\_Token\_Manager(3)

Manages all tokens in a process space.

## NAME

ACE\_Token\_Manager -  Manages all tokens in a process space.

## SYNOPSIS

```
#include <ace/Token_Manager.h>
class ACE_Token_Manager : public ACE_Cleanup
{
  public:
    ACE_Token_Manager (void);
    virtual ~ACE_Token_Manager (void);
    static ACE_Token_Manager *instance (void);
    void instance (ACE_Token_Manager *);
    void get_token (ACE_Token_Proxy *, const ASYS_TCHAR *token_name);
    int check_deadlock (ACE_Token_Proxy *proxy);
    int check_deadlock (ACE_Tokens *token, ACE_Token_Proxy *proxy);
    void release_token (ACE_Tokens *&token);
    ACE_TOKEN_CONST::MUTEX &mutex (void);
    void dump (void) const;
    void debug (int d);
  private:
    int debug_;
    static ACE_Token_Manager *token_manager_;
    ACE_Tokens *token_waiting_for (const ASYS_TCHAR *client_id);
    ACE_TOKEN_CONST::MUTEX lock_;
    typedef ACE_Token_Name TOKEN_NAME;
        typedef ACE_Map_Manager<TOKEN_NAME, ACE_Tokens *, ACE_Null_Mutex> COLLECTION;

        typedef ACE_Map_Iterator<TOKEN_NAME, ACE_Tokens *, ACE_Null_Mutex> COLLECTION_ITERATOR;

    typedef ACE_Map_Entry<TOKEN_NAME, ACE_Tokens *> COLLECTION_ENTRY;
    COLLECTION collection_;
};
```

## DESCRIPTION

Factory:  Proxies use the token manager to obtain token references.  This allows multiple proxies to reference the same logical token. Deadlock detection:  Tokens use the manager to check for deadlock situations during acquires.

## PUBLIC MEMBERS

```
ACE_Token_Manager (void);
```

```
virtual ~ACE_Token_Manager (void);
```

```
static ACE_Token_Manager *instance (void);
```

```
void instance (ACE_Token_Manager *);
```

```
void get_token (ACE_Token_Proxy *, const ASYS_TCHAR *token_name);
```

The Token manager uses ACE\_Token\_Proxy::token\_id\_ to look for an existing token.  If none is found, the Token Manager calls ACE\_Token\_Proxy::create\_token to create a new one.  When finished, sets ACE\_Token\_Proxy::token\_.  token\_name uniquely id's the token name.

```
int check_deadlock (ACE_Token_Proxy *proxy);
```

```
int check_deadlock (ACE_Tokens *token, ACE_Token_Proxy *proxy);
```

returns 1 if the acquire will \_not\_ cause deadlock. returns 0 if the acquire \_will\_ cause deadlock. this method ignores recursive acquisition.  That is, it will not report deadlock if the client holding the token requests the token again.  Thus, it assumes recursive mutexes.

```
void release_token (ACE_Tokens *&token);
```

notify the token manager that a token has been released.  If as a result, there is no owner of the token, the token is deleted.

```
ACE_TOKEN_CONST::MUTEX &mutex (void);
```

This is to allow Tokens to perform atomic transactions.  The typical usage is to acquire this mutex, check for a safe\_acquire, perform some queueing (if need be) and then release the lock. This is necessary since safe\_acquire is implemented in terms of the Token queues.

```
void dump (void) const;
```

Dump the state of the class.

```
void debug (int d);
```

Turn debug mode on/off.

## PRIVATE MEMBERS

```
int debug_;
```

Whether to print debug messages or not.

```
static ACE_Token_Manager *token_manager_;
```

pointer to singleton token manager.

```
ACE_Tokens *token_waiting_for (const ASYS_TCHAR *client_id);
```

return the token that the given client\_id is waiting for, if any

```
ACE_TOKEN_CONST::MUTEX lock_;
```

ACE\_Mutex\_Token used to lock internal data structures.

```
typedef ACE_Token_Name TOKEN_NAME;
```

This may be changed to a template type.

```
    typedef ACE_Map_Manager<TOKEN_NAME, ACE_Tokens *, ACE_Null_Mutex> COLLECTION;

```

COLLECTION maintains a mapping from token names to ACE\_Tokens\*

```
    typedef ACE_Map_Iterator<TOKEN_NAME, ACE_Tokens *, ACE_Null_Mutex> COLLECTION_ITERATOR;

```

Allows iterations through collection\_

```
typedef ACE_Map_Entry<TOKEN_NAME, ACE_Tokens *> COLLECTION_ENTRY;
```

Allows iterations through collection\_

```
COLLECTION collection_;
```

COLLECTION maintains a mapping from token names to ACE\_Tokens\*.

## AUTHOR

Tim Harrison (harrison@cs.wustl.edu)

## LIBRARY

ace
