;;;; Copyright 2002, Jonathan Bachrach.  See file TERMS.

(use goo)
(use goo/boot)
(use time/threads)
(use time/lock)
(use time/%event.c)

(dl %event-create)
(dl %event-signal)
(dl %event-broadcast)
(dl %event-destroy)
;; (dl %event-pulse)
(dl %event-reset)
(dl %event-destroy)
(dl %event-wait)
(dl %event-wait-timed)

(dc <event> (<any>))
  (dp event-name (<event> => (t? <sym>)) #f)
  (dp! event-handle (<event> => <any>))

(dm new (c|(t< <event>) args|... => <event>)
  (def event (app-sup c args))
  (set (event-handle event)
       (%lb (%event-create (%su (as <str> (or (event-name event) ""))))))
  event)

(dm event-signal (e|<event>)
  (%event-signal (%lu (event-handle e))) #t)

(dm event-broadcast (e|<event>)
  (%event-broadcast (%lu (event-handle e))) #t)

;; (dm event-destroy (e|<event>)
;;   (%event-destroy (%lu (event-handle e))))

(dm event-reset (e|<event>)
  (%event-reset (%lu (event-handle e))) #t)

(dm event-wait (e|<event> l|<lock> => <log>)
  (%bb (%event-wait (%lu (event-handle e)) (%lu (lock-handle l)))))

(dm event-wait-timed (e|<event> l|<lock> secs|<flo> => <log>)
  (%bb (%event-wait-timed
        (%lu (event-handle e)) (%lu (lock-handle l)) (%fu secs))))

(export
  <event>
  event-name
  event-signal
  event-broadcast
  ;; event-destroy
  event-reset
  event-wait event-wait-timed)
  
