Description

Synchronization Forms

Author

Kon Lovett

Usage

(require-extension synch)

Download

synch.egg

Requires

Documentation

Simple critical region helpers.

Synchronized Invocation - Continuation Safe

macro: (call/synch MUTEX PROCEDURE [ARGUMENT ...])

Invoke PROCEDURE on the argument list ARGUMENT ... while MUTEX locked.

macro: (call-with/synch MUTEX PROCEDURE [ARGUMENT ...])

Invoke PROCEDURE on the (mutex-specific MUTEX) and the ARGUMENT ... while MUTEX locked.

macro: (apply/synch MUTEX PROCEDURE [ARGUMENT ...])

Apply PROCEDURE to the argument list ARGUMENT ... while MUTEX locked.

macro: (apply-with/synch MUTEX PROCEDURE [ARGUMENT ...])

Apply PROCEDURE to the (mutex-specific MUTEX) and the ARGUMENT ... while MUTEX locked.

macro: (synch MUTEX [BODY ...])

Execute BODY ... while MUTEX locked.

macro: (synch-with MUTEX VARIABLE [BODY ...])

Execute BODY ... while MUTEX locked and the mutex-specific bound to VARIABLE.

macro: (synch/lock MUTEX [BODY ...])

Execute BODY ... while MUTEX locked, and leave mutex locked.

macro: (synch/unlock MUTEX [BODY ...])

Execute BODY ... while MUTEX locked, and leave mutex unlocked.

macro: (let/synch BINDINGS [BODY ...])

Expands into a nested (synch-with BINDVAL BINDVAR ...) form, a synch-with for each binding pair in BINDINGS. The leftmost binding pair is the outermost.

macro: (set!/synch BINDING BODY ...)

While the mutex of the BINDING is locked, evaluates BODY with the variable of the BINDING bound to the mutex-specific. Sets the mutex-specific of the mutex to the result of the evaluation. Returns the new value.

macro: (object/synch MUTEX [BODY ...])

Execute BODY ... while MUTEX locked.

The top-level forms of BODY ... are parsed for occurrences of ><. All such occurrences are replaced by the mutex-specific value.

macro: (record/synch RECORD-SYMBOL RECORD-OBJECT [BODY ...])

Execute BODY ... while the RECORD-OBJECT mutex is locked. The mutex is a field of the record named {RECORD-SYMBOL}-mutex.

macro: (record-synch/lock RECORD-SYMBOL RECORD-OBJECT [BODY ...])

Execute BODY ... while the RECORD-OBJECT mutex is locked, and leave the mutex locked.

macro: (record-synch/unlock RECORD-SYMBOL RECORD-OBJECT [BODY ...])

Execute BODY ... while the RECORD-OBJECT mutex is locked, and leave the mutex unlocked.

Synchronized Invocation - Continuation Unsafe

These forms do not have the mutex lock/unlock wrapped in dynamic-wind, otherwise the same behavior.

macro: (%call/synch MUTEX PROCEDURE [ARGUMENT ...])
macro: (%call-with/synch MUTEX PROCEDURE [ARGUMENT ...])
macro: (%apply/synch MUTEX PROCEDURE [ARGUMENT ...])
macro: (%apply-with/synch MUTEX PROCEDURE [ARGUMENT ...])
macro: (%synch MUTEX [BODY ...])
macro: (%synch-with MUTEX VARIABLE [BODY ...])
macro: (%synch/lock MUTEX [BODY ...])
macro: (%synch/unlock MUTEX [BODY ...])
macro: (%let/synch BINDINGS [BODY ...])
macro: (%set!/synch BINDING BODY ...)
macro: (%object/synch MUTEX [BODY ...])
macro: (%record/synch RECORD-SYMBOL RECORD-OBJECT [BODY ...])
macro: (%record-synch/lock RECORD-SYMBOL RECORD-OBJECT [BODY ...])
macro: (%record-synch/unlock RECORD-SYMBOL RECORD-OBJECT [BODY ...])

Synchronized Object Routines

macro: (set-object!/synch MUTEX OBJECT)

Synonym for mutex-specific-set!.

Name is confusing since it implies synchronization.

procedure: (make-object/synch OBJECT [NAME])

Returns a mutex with a mutex-specific value of OBJECT, and optional mutex NAME.

NAME is either a symbol or a one element list of symbol. When a list the first element is used as the basis for a generated symbol. When a symbol it is used literally as the mutex name.

When NAME is missing a generated symbol with the prefix synchobj is provided.

procedure: (object?/synch OBJECT [PREDICATE])

Is the OBJECT a synchronized object - a mutex with a non-void mutex specific?

The optional PREDICATE is used to verify the type of the mutex specific binding. Otherwise any object is accepted.

Contributions

Inspired by Thomas Chust.

Version

License

Copyright (c) 2006, Kon Lovett.  All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the Software),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.