This is a followup to <https://bugs.gnu.org/29704>.
* module/srfi/srfi-18.scm (thread-sleep!): When TIMEOUT is a number,
keep it as-is.
* test-suite/tests/srfi-18.test ("thread sleep with number"): Pass 0 as
the timeout.
("thread sleeps fractions of a second"): Pass 0.5 as the timeout.
Fixes <https://bugs.gnu.org/29704>.
Reported by David Beswick <dlbeswick@gmail.com>.
* module/srfi/srfi-18.scm (timeout->absolute-time): New procedure.
(mutex-lock!): Use it in 'thread:lock-mutex' call.
(mutex-unlock!): Use it.
* test-suite/tests/srfi-18.test ("mutex-lock! returns false on timeout")
("mutex-lock! returns true when lock obtained within timeout")
("recursive lock waits")
("mutex unlock is false when condition times out"): Adjust cases where
the 'timeout' parameter is a number so that it's a relative number.
* module/srfi/srfi-18.scm (mutex-unlock!): Implement the
ignore-unlock-errors and wait-condition-variable behavior of
mutex-unlock! directly, without relying on Guile.
* module/srfi/srfi-18.scm (<mutex>, with-thread-mutex-cleanup)
(make-mutex, mutex-state, abandon-mutex!, mutex-lock!): Manage
"abandoned" bit on Scheme side with no need for thread cleanup
handler.
* module/srfi/srfi-18.scm (<condition-variable>): New data type.
(make-thread): Use srfi-18 interfaces.
(mutex-unlock!): Adapt to optional cond argument being disjoint from
Guile condition variables.
(make-condition-variable, condition-variable-signal!)
(condition-variable-broadcast!): Adapt.
* module/srfi/srfi-18.scm (<mutex>): Define as a wrapper type around
Guile mutexes.
(thread-mutexes): New variable.
(with-thread-mutex-cleanup): New facility to abandon mutexes on
SRFI-18 thread exit. Not yet used.
(make-thread): Use SRFI-18 interfaces.
(make-mutex): Reimplement for our boxed mutexes.
(mutex-state): Adapt.
(mutex-lock!): Adapt.
(mutex-unlock!): Adapt.
* test-suite/tests/srfi-18.test: Don't assume that SRFI-18 mutexes are
the same as Guile mutexes.
* module/srfi/srfi-18.scm (%cancel-sentinel, thread-terminate!): Just
use cancel-thread to cause the thread to return a sentinel value.
(%timeout-sentinel): Rename from %sentinel.
(thread-join!): Adapt and transform %cancel-sentinel to a
&terminated-thread-exception.
* module/srfi/srfi-18.scm (make-thread): Inline some helpers, and use
just one catch block.
(thread->exception): Move up definition.
(exception-handler-for-foreign-threads): Use this as the default
handler, not the one that squirrels away exceptions in
thread->exception.
(thread-terminate!): Don't instate an exception handler for the thread
cleanup proc.
* module/srfi/srfi-18.scm (with-exception-handlers-here): New function.
(wrap): Remove.
(thread-join!, mutex-lock!): Use with-exception-handlers-here instead
of the call/cc+wrap mess.
* module/srfi/srfi-18.scm: Use srfi-35 conditions instead of our
home-grown equivalent system.
(thread-exception-handlers): Remove unused table.
(srfi-18-exception-handler): Always capture key consed to args; no
special case for bare key.
* test-suite/tests/srfi-18.test (provided?): Adapt to reason always
being key+args.
* module/srfi/srfi-18.scm: Use srfi-34 internally with srfi-34: prefix.
(current-exception-handler): Be a parameter.
(with-exception-handler): Adapt to current-exception-handler change.
(thread-join!, mutex-lock!): Adapt to use srfi-34: prefix.
* module/language/tree-il/compile-glil.scm (flatten): For applications in
"drop" context, allow the procedure to return unspecified values
(including 0 values).
* test-suite/tests/tree-il.test ("application"): Adapt test.
* module/srfi/srfi-18.scm (wrap): Clarify.
* test-suite/tests/srfi-18.test: Fix so that the expression importing
srfi-18 is expanded before the tests. However the tests are still
failing, something about 0-valued returns...