---
name: "ACE_Lock_Adapter"
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_Lock_Adapter"
---

# ACE\_Lock\_Adapter(3)

This is an adapter that allows applications to transparently combine the ACE\_Lock abstract base class (which contains pure virtual methods) with any of the other concrete ACE synchronization classes (e.g., ACE\_Mutex, ACE\_Semaphore, ACE\_RW\_Mutex, etc.).

## NAME

ACE\_Lock\_Adapter -  This is an adapter that allows applications to transparently combine the ACE\_Lock abstract base class (which contains pure virtual methods) with any of the other concrete ACE synchronization classes (e.g., ACE\_Mutex, ACE\_Semaphore, ACE\_RW\_Mutex, etc.).

## SYNOPSIS

```
#include <ace/Synch_T.h>
template<class ACE_LOCKING_MECHANISM>
class ACE_Lock_Adapter : public ACE_Lock
{
  public:
    typedef ACE_LOCKING_MECHANISM ACE_LOCK;
    ACE_Lock_Adapter (ACE_LOCKING_MECHANISM &lock);
    ACE_Lock_Adapter (void);
    virtual ~ACE_Lock_Adapter (void);
    virtual int acquire (void);
    virtual int tryacquire (void);
    virtual int release (void);
    virtual int acquire_read (void);
    virtual int acquire_write (void);
    virtual int tryacquire_read (void);
    virtual int tryacquire_write (void);
    virtual int remove (void);
  private:
    ACE_LOCKING_MECHANISM *lock_;
    int delete_lock_;
};
```

## DESCRIPTION

This class uses a form of the Adapter pattern.

## Initialization/Finalization methods.

```
ACE_Lock_Adapter (ACE_LOCKING_MECHANISM &lock);
```

Constructor. All locking requests will be forwarded to lock.

```
ACE_Lock_Adapter (void);
```

Constructor. Since no lock is provided by the user, one will be created internally.

```
virtual ~ACE_Lock_Adapter (void);
```

Destructor. If lock\_ was not passed in by the user, it will be deleted.

## Lock accessors.

```
virtual int acquire (void);
```

Block the thread until the lock is acquired.

```
virtual int tryacquire (void);
```

Conditionally acquire the lock (i.e., won't block).

```
virtual int release (void);
```

Release the lock.

```
virtual int acquire_read (void);
```

Block until the thread acquires a read lock.  If the locking mechanism doesn't support read locks then this just calls acquire.

```
virtual int acquire_write (void);
```

Block until the thread acquires a write lock.  If the locking mechanism doesn't support read locks then this just calls acquire.

```
virtual int tryacquire_read (void);
```

Conditionally acquire a read lock.  If the locking mechanism doesn't support read locks then this just calls acquire.

```
virtual int tryacquire_write (void);
```

Conditionally acquire a write lock.  If the locking mechanism doesn't support read locks then this just calls acquire.

```
virtual int remove (void);
```

Explicitly destroy the lock.

## AUTHOR

Doug Schmidt

## LIBRARY

ace
