module: threads-internal Synopsis: The implementation of the class Author: Tony Mann Copyright: Original Code is Copyright (c) 1995-2004 Functional Objects, Inc. All rights reserved. License: Functional Objects Library Public License Version 1.0 Dual-license: GNU Lesser General Public License Warranty: Distributed WITHOUT WARRANTY OF ANY KIND define sealed class (, ) /* constant */ slot associated-lock :: , required-init-keyword: lock:; end class; define sealed domain synchronization-name (); // A little grounding goes a long way. define constant make-notification = method (lock :: ) => (notification :: ); let instance :: = system-allocate-simple-instance(, fill: #f); associated-lock(instance) := lock; initialize-notification(instance); instance end method; define constant initialize-notification = method (notif :: ) => () drain-finalization-queue(); let res = primitive-make-notification(notif, notif.synchronization-name); check-synchronization-creation(notif, res); finalize-when-unreachable(notif); end method; define sealed method initialize (notif :: , #key) => () next-method(); initialize-notification(notif); end method; define function notification-release-result (notif :: , res :: ) => () unless (res == $success) select (res) $unlocked => error(make(, lock: notif.associated-lock)); otherwise => error(make(, synchronization: notif)); end select; end unless; end function notification-release-result; define sealed method release (notif :: , #key) => () let res = primitive-release-notification(notif, notif.associated-lock); notification-release-result(notif, res); end method; define function release-all (notif :: , #key) => () let res = primitive-release-all-notification(notif, notif.associated-lock); notification-release-result(notif, res); end; define sealed method wait-for (notif :: , #key timeout) => (success?) let lock = notif.associated-lock; let res = if (timeout) primitive-wait-for-notification-timed(notif, lock, timeout.millisecs) else primitive-wait-for-notification(notif, lock) end if; select (res) $success => #t; $timeout => #f; $unlocked => error(make(, lock: lock)); otherwise => error(make(, synchronization: notif)); end select; end method; define method finalize (notif :: ) => () let res = primitive-destroy-notification(notif); check-synchronization-finalization(notif, res); end method;