diff --git a/ice-9/ChangeLog b/ice-9/ChangeLog index e2a2a5e71..3b02d7921 100644 --- a/ice-9/ChangeLog +++ b/ice-9/ChangeLog @@ -1,6 +1,7 @@ 2003-01-10 Mikael Djurfeldt * occam-channel.scm (make-channel): Renamed from channel. + (make-timer): New function. * Makefile.am (ice9_sources): Added occam-channel.scm. diff --git a/ice-9/occam-channel.scm b/ice-9/occam-channel.scm index 8ced0b91d..4c7c90383 100644 --- a/ice-9/occam-channel.scm +++ b/ice-9/occam-channel.scm @@ -45,20 +45,27 @@ #:use-module (oop goops) #:use-module (ice-9 threads) ;;#:export-syntax (alt) - #:export (make-channel ? !)) + #:export (make-channel + ? + ! + make-timer + ) + ) (define no-data '(no-data)) (define receiver-waiting '(receiver-waiting)) -(define-class () +(define-class ()) + +(define-class () (data #:accessor data #:init-value no-data) (cv #:accessor cv #:init-form (make-condition-variable)) (mutex #:accessor mutex #:init-form (make-mutex))) (define-method (make-channel) - (make )) + (make )) -(define-method (? (ch )) +(define-method (? (ch )) (lock-mutex (mutex ch)) (cond ((eq? (data ch) no-data) (set! (data ch) receiver-waiting) @@ -75,7 +82,10 @@ (unlock-mutex (mutex ch)) res)) -(define-method (! (ch ) (x )) +(define-method (! (ch )) + (! ch *unspecified*)) + +(define-method (! (ch ) (x )) (lock-mutex (mutex ch)) (cond ((eq? (data ch) no-data) (set! (data ch) x) @@ -88,3 +98,43 @@ (scm-error 'misc-error '! "another process is already sending on ~A" (list ch) #f))) (unlock-mutex (mutex ch))) + +;;; Add protocols? + +(define-class () + (port #:accessor port #:init-keyword #:port)) + +(define-method (make-channel (port )) + (make #:port port)) + +(define-method (? (ch )) + (read (port ch))) + +(define-method (! (ch )) + (write (port ch))) + +(define-class ()) + +(define the-timer (make )) + +(define timer-cv (make-condition-variable)) +(define timer-mutex (make-mutex)) + +(define (make-timer) + the-timer) + +(define (timeofday->us t) + (+ (* 1000000 (car t)) (cdr t))) + +(define (us->timeofday n) + (cons (quotient n 1000000) + (remainder n 1000000))) + +(define-method (? (ch )) + (timeofday->us (gettimeofday))) + +(define-method (? (ch ) (t )) + (lock-mutex timer-mutex) + (wait-condition-variable timer-cv timer-mutex (us->timeofday t)) + (unlock-mutex timer-mutex)) +