with
#define with(...)
Perform operations in between start
and stop
.
start
void start(var self);
Start the object self
.
stop
void stop(var self);
Stop the object self
.
join
void join(var self);
Block and wait for the object self
to stop.
running
bool running(var self);
Check if the object self
is running.
Usage
var x = new(Mutex);
start(x); /* Lock Mutex */
print("Inside Mutex!\n");
stop(x); /* unlock Mutex */
Scoped
var x = new(Mutex);
with (mut in x) { /* Lock Mutex */
print("Inside Mutex!\n");
} /* unlock Mutex */
Can be started or stopped
The Start
class can be implemented by types which provide an abstract notion of a started and stopped state. This can be real processes such as Thread
, or something like File
where the on/off correspond to if the file is open or not.
The main nicety of the Start
class is that it allows use of the with
macro which performs the start
function at the opening of a scope block and the stop
function at the end.
struct Start {
void (*start)(var);
void (*stop)(var);
void (*join)(var);
bool (*running)(var);
};