Common Lisp Package: CHANL

README:

FUNCTION

Public

PCALL (FUNCTION &KEY (INITIAL-BINDINGS *DEFAULT-SPECIAL-BINDINGS*) (NAME Anonymous task))

PCALL -> Parallel Call; calls FUNCTION in a new thread. FUNCTION must be a no-argument function. INITIAL-BINDINGS, if provided, should be an alist representing dynamic variable bindings that BODY is to be executed with. The format is: '((*var* value)).

Undocumented

ALL-THREADS

CURRENT-THREAD

KILL (PROC)

POOLED-TASKS

POOLED-THREADS

THREAD-ALIVE-P (PROC)

THREAD-NAME (PROC)

THREADP (PROC)

Private

%DEQUEUE

Sets QUEUE's tail to QUEUE, increments QUEUE's tail pointer, and returns the previous tail ref

%ENQUEUE

Enqueue OBJECT and increment QUEUE's entry pointer

%MAKE-QUEUE

Creates a new queue of maximum size LENGTH

%QUEUE-COUNT

Returns QUEUE's effective length

%QUEUE-EMPTY-P

Checks whether QUEUE is effectively empty

%QUEUE-FULL-P

Checks whether QUEUE is effectively full

%QUEUE-IN

QUEUE's entry pointer

%QUEUE-LENGTH

Returns QUEUE's maximum length

%QUEUE-OUT

QUEUE's exit pointer

%QUEUE-PEEK

Dereference QUEUE's exit pointer

%QUEUE-ZERO-P

Checks whether QUEUE's theoretical length is zero

DEQUEUE (QUEUE)

Dequeues QUEUE

ENQUEUE (OBJECT QUEUE)

Enqueues OBJECT in QUEUE

MAKE-QUEUE (SIZE)

Makes a queue of maximum size SIZE

NUNZIP-ALIST (ALIST &AUX (KEYS ALIST) (VALS (CAR ALIST)))

Destructive, non-consing version of `unzip-alist'.

QUEUE-COUNT (QUEUE)

Returns the current size of QUEUE

QUEUE-EMPTY-P (QUEUE)

Tests whether QUEUE is empty

QUEUE-FULL-P (QUEUE)

Tests whether QUEUE is full

QUEUE-LENGTH (QUEUE)

Returns the maximum size of QUEUE

QUEUEP

If this returns NIL, X is not a queue

UNZIP-ALIST (ALIST)

Returns two fresh lists containing the keys and values of ALIST

Undocumented

%NEXT-INDEX

CAS-CHANNEL-SET (SLOT-NAME CHANNEL VALUE)

CHANNEL-BEING-READ-P (CHANNEL)

CHANNEL-BEING-WRITTEN-P (CHANNEL)

CLAUSE-TYPE (CLAUSE)

ENSURE-LIST (X)

NEW-WORKER-THREAD (THREAD-POOL &OPTIONAL TASK)

QUEUE-PEEK (QUEUE)

WRAP-SELECT-CLAUSE (CLAUSE)

MACRO

Public

PEXEC ((&KEY INITIAL-BINDINGS NAME) &BODY BODY)

Executes BODY in parallel. INITIAL-BINDINGS, if provided, should be an alist representing dynamic variable bindings that BODY is to be executed with. The format is: '((*var* value)).

SELECT (&BODY CLAUSES)

Non-deterministically select a non-blocking clause to execute. The syntax is: select clause* clause ::= (op form*) op ::= (recv c &optional variable channel-var) | (send c value &optional channel-var) | else | otherwise | t c ::= An evaluated form representing a channel, or a sequence of channels. variable ::= an unevaluated symbol RECV's return value is to be bound to. Made available to form*. value ::= An evaluated form representing a value to send into the channel. channel-var ::= An unevaluated symbol that will be bound to the channel the SEND/RECV operation succeeded on. SELECT will first attempt to find a clause with a non-blocking op, and execute it. Execution of the check-if-blocks-and-do-it part is atomic, but execution of the clause's body once the SEND/RECV clause executes is NOT atomic. If all channel clauses would block, and no else clause is provided, SELECT will block until one of the clauses is available for execution. SELECT's non-determinism is, in fact, very non-deterministic. Clauses are chosen at random, not in the order they are written. It's worth noting that SEND/RECV, when used on sequences of channels, are still linear in the way they go through the sequence -- the random selection is reserved for individual SELECT clauses.

Private

ECOND (&BODY COND-CLAUSES &AUX ERROR)

Like `ecase', but for `cond'. An optional initial string is used as the error message.

FUN (&BODY BODY)

This macro puts the FUN back in FUNCTION.

POP-DECLARATIONS (PLACE)

Returns and removes all leading declarations from PLACE, which should be a setf-able form. NOTE: Does not support docstrings.

Undocumented

AIF (TEST THEN &OPTIONAL ELSE)

AWHEN (TEST &BODY BODY)

DEFINE-PRINT-OBJECT (((OBJECT CLASS) &KEY (IDENTITY T) (TYPE T)) &BODY BODY)

DEFINE-SPEEDY-FUNCTION (NAME ARGS &BODY BODY)

PUSHEND (NEW-ITEM LIST LIST-END &ENVIRONMENT ENV)

WHEN-BIND (VARIABLE TEST &BODY BODY)

WITH-CAS-READ-STATE (CHANNEL &BODY BODY)

WITH-CAS-WRITE-STATE (CHANNEL &BODY BODY)

WITH-GENSYMS (NAMES &BODY BODY)

WITH-READ-STATE (CHANNEL &BODY BODY)

WITH-WRITE-STATE (CHANNEL &BODY BODY)

GENERIC-FUNCTION

Public

RECV (CHAN &KEY (BLOCKP T))

Tries to receive from either a single channel, or a sequence of channels. If BLOCKP is true, RECV will block until it's possible to receive something. Returns two values: The first is the actual value received through the channel. The second is the channel the value was received from. When BLOCKP is NIL, RECV will immediately return (values NIL NIL) instead of blocking (if it would block)

SEND (CHAN VALUE &KEY (BLOCKP T))

Tries to send VALUE into CHAN. If a sequence of channels is provided instead of a single channel, SEND will send the value into the first channel that doesn't block. If BLOCKP is true, SEND will continue to block until it's able to actually send a value. If BLOCKP is NIL, SEND will immediately return NIL instead of blocking, if there's no channel available to send input into. When SEND succeeds, it returns the channel the value was sent into.

SEND-BLOCKS-P (CHANNEL)

Returns T if trying to SEND to CHANNEL would block. Note that this is not an atomic operation, and should not be relied on in production. It's mostly meant for interactive/debugging purposes.

Undocumented

CHANNEL-GRAB-VALUE (CHANNEL)

CHANNEL-INSERT-VALUE (CHANNEL VALUE)

CHANNELP (CHANNEL)

RECV-BLOCKS-P (CHANNEL)

Private

CHANNEL-DEQUEUE (CHANNEL)

Dequeue a value from CHANNEL's buffer queue.

CHANNEL-ENQUEUE (VALUE CHANNEL)

Enqueue VALUE in CHANNEL's buffer queue.

CHANNEL-PEEK (CHANNEL)

Peek at the next value CHANNEL would dequeue. Note that this cannot be used atomically. Returns two values: The first is the value of interest or NIL, the second is a generalized boolean that is NIL when there is no available value in the queue.

Undocumented

ASSIGN-TASK (THREAD-POOL TASK)

CHANNEL-BUFFERED-P (CHANNEL)

CHANNEL-POP (CHANNEL)

CHANNEL-PUSH (VALUE CHANNEL)

QUEUE-CONDITION-QUEUE (CONDITION)

QUEUE-ERROR-ATTEMPTED-LENGTH (CONDITION)

QUEUE-OVERFLOW-EXTRA-ITEM (CONDITION)

SLOT-ACCESSOR

Public

Undocumented

TASK-NAME (OBJECT)

SETFTASK-NAME (NEW-VALUE OBJECT)

TASK-STATUS (OBJECT)

SETFTASK-STATUS (NEW-VALUE OBJECT)

TASK-THREAD (OBJECT)

SETFTASK-THREAD (NEW-VALUE OBJECT)

Private

Undocumented

CHANNEL-LOCK (OBJECT)

SETFCHANNEL-LOCK (NEW-VALUE OBJECT)

CHANNEL-READERS (OBJECT)

SETFCHANNEL-READERS (NEW-VALUE OBJECT)

CHANNEL-RECV-OK (OBJECT)

SETFCHANNEL-RECV-OK (NEW-VALUE OBJECT)

CHANNEL-SEND-OK (OBJECT)

SETFCHANNEL-SEND-OK (NEW-VALUE OBJECT)

CHANNEL-SEND-RETURN-WAIT (OBJECT)

SETFCHANNEL-SEND-RETURN-WAIT (NEW-VALUE OBJECT)

CHANNEL-VALUE (OBJECT)

SETFCHANNEL-VALUE (NEW-VALUE OBJECT)

CHANNEL-VECTOR (OBJECT)

SETFCHANNEL-VECTOR (NEW-VALUE OBJECT)

CHANNEL-WRITERS (OBJECT)

SETFCHANNEL-WRITERS (NEW-VALUE OBJECT)

FREE-THREAD-COUNTER (OBJECT)

SETFFREE-THREAD-COUNTER (NEW-VALUE OBJECT)

POOL-LEADER-LOCK (OBJECT)

POOL-LEADER-NOTIFIER (OBJECT)

POOL-LOCK (OBJECT)

POOL-PENDING-TASKS (OBJECT)

SETFPOOL-PENDING-TASKS (NEW-VALUE OBJECT)

POOL-SOFT-LIMIT (OBJECT)

SETFPOOL-SOFT-LIMIT (NEW-VALUE OBJECT)

POOL-TASKS (OBJECT)

SETFPOOL-TASKS (NEW-VALUE OBJECT)

POOL-THREADS (OBJECT)

SETFPOOL-THREADS (NEW-VALUE OBJECT)

RECV-GRABBED-VALUE-P (OBJECT)

SETFRECV-GRABBED-VALUE-P (NEW-VALUE OBJECT)

TASK-FUNCTION (OBJECT)

VARIABLE

Public

*DEFAULT-SPECIAL-BINDINGS*

This variable holds an alist associating special variable symbols to forms to evaluate. Special variables named in this list will be locally bound in the new thread before it begins executing user code. This variable may be rebound around calls to MAKE-THREAD to add/alter default bindings. The effect of mutating this list is undefined, but earlier forms take precedence over later forms for the same symbol, so defaults may be overridden by consing to the head of the list.

Private

*SECRET-UNBOUND-VALUE*

This value is used as a sentinel in channels.

Undocumented

*THREAD-POOL*

CLASS

Public

BUFFERED-CHANNEL

Abstract class for channels using various buffering styles.

CAS-CHANNEL

These channels use COMPARE-AND-SWAP to do their thing, instead of locks+condition-vars. Ideally, these would be faster than regular channels. In reality, they're not. It's possible there might be a way to speed these guys up while keeping the same behavior in the interface, but for now, they're about 100x slower, not to mention non-portable.

QUEUE-CHANNEL

These channels buffer objects in some sort of queue.

Undocumented

ABSTRACT-CHANNEL

BOUNDED-CHANNEL

CHANNEL

STACK-CHANNEL

TASK

UNBOUNDED-CHANNEL

Private

Undocumented

THREAD-POOL

CONDITION

Private

Undocumented

QUEUE-CONDITION

QUEUE-LENGTH-ERROR

QUEUE-OVERFLOW-ERROR

QUEUE-UNDERFLOW-ERROR

CONSTANT

Public

+MAXIMUM-BUFFER-SIZE+

The exclusive upper bound on the size of a channel's buffer.