mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-23 20:15:05 +02:00
Added (future-done?), unified (deref)
This commit is contained in:
parent
b5f526c2eb
commit
11784e9f1a
1 changed files with 18 additions and 7 deletions
|
@ -10,18 +10,21 @@
|
|||
)
|
||||
(include-c-header "<ck_pr.h>")
|
||||
(export
|
||||
;; Generic Concurrency
|
||||
deref
|
||||
;; Atoms
|
||||
make-atom
|
||||
atom
|
||||
atom?
|
||||
deref
|
||||
swap!
|
||||
compare-and-set!
|
||||
atom-deref
|
||||
;; Futures
|
||||
future?
|
||||
future
|
||||
future-call
|
||||
future-deref
|
||||
future-done?
|
||||
;; Immutable objects
|
||||
immutable?
|
||||
;; Shared objects
|
||||
|
@ -30,6 +33,13 @@
|
|||
)
|
||||
(begin
|
||||
|
||||
;; Dereference the given concurrency object
|
||||
(define (deref obj)
|
||||
(cond
|
||||
((atom? obj) (atom-deref obj))
|
||||
((future? obj) (future-deref obj))
|
||||
(else obj)))
|
||||
|
||||
(define-c atom?
|
||||
"(void *data, int argc, closure _, object k, object obj)"
|
||||
" object result = Cyc_is_atomic(obj);
|
||||
|
@ -68,7 +78,7 @@
|
|||
(%make-atom #f)))
|
||||
|
||||
;; - deref atomic
|
||||
(define-c deref
|
||||
(define-c atom-deref
|
||||
"(void *data, int argc, closure _, object k, object obj)"
|
||||
" atomic a;
|
||||
Cyc_check_atomic(data, obj);
|
||||
|
@ -183,11 +193,12 @@
|
|||
(thread-start! t)
|
||||
ftr))
|
||||
|
||||
;;(define (future-done? ftr)
|
||||
;; (when (not (future? ftr))
|
||||
;; (error "Expected future but received" ftr))
|
||||
;; TODO: may be a good candidate for a timed mutex lock, just return #f if minimum timeout is exceeded
|
||||
;;)
|
||||
(define (future-done? ftr)
|
||||
(when (not (future? ftr))
|
||||
(error "Expected future but received" ftr))
|
||||
(let ((result (mutex-lock! (get-lock ftr) 0.01))) ;; Not ideal but short block on failure
|
||||
(if result (mutex-unlock! (get-lock ftr))) ;; Ensure mutex is always not want to hold mutex longunlocked
|
||||
(if result #t #f))) ;; Bit awkward, but ensure boolean result
|
||||
|
||||
;; TODO: (future-cancel ftr)
|
||||
;; TODO: (future-cancelled? ftr)
|
||||
|
|
Loading…
Add table
Reference in a new issue