| Qore Programming Language Reference Manual 2.2.0

Loading...
Searching...
No Matches
Public Member Functions | List of all members
Qore::Thread::AutoGate Class Reference

A helper class for the Gate class for exception-safe Gate handling. More...

`#include <QC_AutoGate.dox.h>`

## Public Member Functions
| constructor (Gate gate)
| Creates the AutoGate object based on the Gate argument passed and immediately calls Gate::enter()
| copy ()
| Throws an exception; objects of this class cannot be copied.
| destructor ()
| Calls Gate::exit() and destroys the AutoGate object.

## Detailed Description

A helper class for the Gate class for exception-safe Gate handling.

Restrictions:
  Qore::PO_NO_THREAD_CLASSES

AutoGate objects, when used along with a Gate object, allow Qore programmers to safely enter and exit a Gate lock, even if exceptions are thrown or return statements are executed in the block where the AutoGate object is created.

AutoGate objects enter the gate lock for the lifetime of the AutoGate object. For this reason, it is only appropriate to assign an AutoGate object to a local variable, so when the local variable goes out of scope, the AutoGate object will be deleted and the gate automatically exited.

For example:

our Gate gate();
sub check_error(bool error) {
# note that the Gate is entered in the AutoGate constructor, and
# the Gate will be exited as soon as the block is exited below.
# (with either the throw statement or the return statement)
AutoGate ag(gate);
if (error) {
throw "ERROR", "sorry, an error happened";
}
return "OK";
}

Note
  This class is not available with the PO_NO_THREAD_CLASSES parse option.

## Member Function Documentation

## ◆ constructor()

Qore::Thread::AutoGate::constructor | ( | Gate | gate | ) |

Creates the AutoGate object based on the Gate argument passed and immediately calls Gate::enter()

Parameters

  gate | the Gate object to enter for the lifetime of the AutoGate object

Example:
  AutoGate ag(gate);

## ◆ copy()

Qore::Thread::AutoGate::copy | ( |  | ) |

Throws an exception; objects of this class cannot be copied.

Exceptions

  AUTOGATE-COPY-ERROR | objects of this class cannot be copied