From 92fe9cfb454de6998e125db698699bc091d78b33 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 29 Aug 2008 01:00:39 -0500 Subject: [PATCH] use new accessors, throw -> ERROR: --- basis/concurrency/messaging/messaging.factor | 12 ++++++------ .../concurrency/semaphores/semaphores.factor | 19 ++++++++++++------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/basis/concurrency/messaging/messaging.factor b/basis/concurrency/messaging/messaging.factor index e77760408c..810e4430f1 100755 --- a/basis/concurrency/messaging/messaging.factor +++ b/basis/concurrency/messaging/messaging.factor @@ -4,7 +4,7 @@ ! Concurrency library for Factor, based on Erlang/Termite style ! concurrency. USING: kernel threads concurrency.mailboxes continuations -namespaces assocs random ; +namespaces assocs random accessors ; IN: concurrency.messaging GENERIC: send ( message thread -- ) @@ -45,11 +45,11 @@ TUPLE: synchronous data sender tag ; TUPLE: reply data tag ; : ( data synchronous -- reply ) - synchronous-tag \ reply boa ; + tag>> \ reply boa ; : synchronous-reply? ( response synchronous -- ? ) over reply? - [ >r reply-tag r> synchronous-tag = ] + [ >r tag>> r> tag>> = ] [ 2drop f ] if ; : send-synchronous ( message thread -- reply ) @@ -58,15 +58,15 @@ TUPLE: reply data tag ; ] [ >r dup r> send [ synchronous-reply? ] curry receive-if - reply-data + data>> ] if ; : reply-synchronous ( message synchronous -- ) - [ ] keep synchronous-sender send ; + [ ] keep sender>> send ; : handle-synchronous ( quot -- ) receive [ - synchronous-data swap call + data>> swap call ] keep reply-synchronous ; inline ( n -- semaphore ) - dup 0 < [ "Cannot have semaphore with negative count" throw ] when + dup 0 < [ negative-count-semaphore ] when semaphore boa ; : wait-to-acquire ( semaphore timeout -- ) - >r semaphore-threads r> "semaphore" wait ; + [ threads>> ] dip "semaphore" wait ; : acquire-timeout ( semaphore timeout -- ) - over semaphore-count zero? + over count>> zero? [ dupd wait-to-acquire ] [ drop ] if - dup semaphore-count 1- swap set-semaphore-count ; + [ 1- ] change-count drop ; : acquire ( semaphore -- ) f acquire-timeout ; : release ( semaphore -- ) - dup semaphore-count 1+ over set-semaphore-count - semaphore-threads notify-1 ; + [ 1+ ] change-count + threads>> notify-1 ; : with-semaphore-timeout ( semaphore timeout quot -- ) pick rot acquire-timeout swap