Note: This class is not available with the PO_NO_THREAD_CLASSES
parse option.
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 = new Gate(); sub check_error($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) my $ag = new AutoGate($gate); if ($error) throw "ERROR", "sorry, an error happened"; return "OK"; }
Table 4.844. AutoGate Method Overview
Method | Except? | Description |
---|---|---|
Y | Creates the AutoGate object based on the Gate argument passed and immediately calls Gate::enter(). | |
Y | Calls Gate::exit() and destroys the AutoGate object. | |
Y | Throws an exception; objects of this class cannot be copied. |
Creates the AutoGate object based on the Gate argument passed and immediately calls Gate::enter().
new AutoGate(gate_object
)
my $gate = new AutoGate($gate);
Table 4.845. Arguments for AutoGate::constructor()
Argument | Type | Description |
---|---|---|
| The Gate object to enter for the lifetime of the AutoGate object. |
Table 4.846. Return Values for AutoGate::constructor()
Return Type | Description |
---|---|
AutoGate Object | The new AutoGate object. |
Calls Gate::exit() on the saved Gate object and destroys the AutoGate object.
delete lvalue
delete $ag;
Throws an exception; objects of this class cannot be copied.
Table 4.847. Arguments for AutoGate::copy()
Argument | Type | Description |
---|---|---|
n/a | n/a | This method takes no arguments. |
Table 4.848. Return Values for AutoGate::copy()
Return Type | Description |
---|---|
n/a | This method returns no value because it throws an exception. |
Table 4.849. Exceptions Thrown by AutoGate::copy()
err | desc |
---|---|
| Objects of this class cannot be copied. |