mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 11:40:18 +02:00
srfi-18: Simplify thread-sleep!, thread-terminate!.
* module/srfi/srfi-18.scm (thread-sleep!): Use `when'. (thread-terminate!): Simplify.
This commit is contained in:
parent
4d23c835c4
commit
bbcc128153
1 changed files with 15 additions and 19 deletions
|
@ -233,8 +233,8 @@
|
||||||
'()))))
|
'()))))
|
||||||
(secs (inexact->exact (truncate t)))
|
(secs (inexact->exact (truncate t)))
|
||||||
(usecs (inexact->exact (truncate (* (- t secs) 1000000)))))
|
(usecs (inexact->exact (truncate (* (- t secs) 1000000)))))
|
||||||
(and (> secs 0) (sleep secs))
|
(when (> secs 0) (sleep secs))
|
||||||
(and (> usecs 0) (usleep usecs))
|
(when (> usecs 0) (usleep usecs))
|
||||||
*unspecified*))
|
*unspecified*))
|
||||||
|
|
||||||
;; A convenience function for installing exception handlers on SRFI-18
|
;; A convenience function for installing exception handlers on SRFI-18
|
||||||
|
@ -254,23 +254,19 @@
|
||||||
;; terminated-thread exception, as per SRFI-18,
|
;; terminated-thread exception, as per SRFI-18,
|
||||||
|
|
||||||
(define (thread-terminate! thread)
|
(define (thread-terminate! thread)
|
||||||
(define (thread-terminate-inner!)
|
(let ((current-handler (threads:thread-cleanup thread)))
|
||||||
(let ((current-handler (threads:thread-cleanup thread)))
|
(threads:set-thread-cleanup!
|
||||||
(if (thunk? current-handler)
|
thread
|
||||||
(threads:set-thread-cleanup!
|
(if (thunk? current-handler)
|
||||||
thread
|
(lambda ()
|
||||||
(lambda ()
|
(with-exception-handler initial-handler
|
||||||
(with-exception-handler initial-handler
|
current-handler)
|
||||||
current-handler)
|
(srfi-18-exception-preserver
|
||||||
(srfi-18-exception-preserver
|
terminated-thread-exception))
|
||||||
terminated-thread-exception)))
|
(lambda () (srfi-18-exception-preserver
|
||||||
(threads:set-thread-cleanup!
|
terminated-thread-exception))))
|
||||||
thread
|
(threads:cancel-thread thread)
|
||||||
(lambda () (srfi-18-exception-preserver
|
*unspecified*))
|
||||||
terminated-thread-exception))))
|
|
||||||
(threads:cancel-thread thread)
|
|
||||||
*unspecified*))
|
|
||||||
(thread-terminate-inner!))
|
|
||||||
|
|
||||||
(define (thread-join! thread . args)
|
(define (thread-join! thread . args)
|
||||||
(define thread-join-inner!
|
(define thread-join-inner!
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue