mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-24 04:25:06 +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>")
|
(include-c-header "<ck_pr.h>")
|
||||||
(export
|
(export
|
||||||
|
;; Generic Concurrency
|
||||||
|
deref
|
||||||
;; Atoms
|
;; Atoms
|
||||||
make-atom
|
make-atom
|
||||||
atom
|
atom
|
||||||
atom?
|
atom?
|
||||||
deref
|
|
||||||
swap!
|
swap!
|
||||||
compare-and-set!
|
compare-and-set!
|
||||||
|
atom-deref
|
||||||
;; Futures
|
;; Futures
|
||||||
future?
|
future?
|
||||||
future
|
future
|
||||||
future-call
|
future-call
|
||||||
future-deref
|
future-deref
|
||||||
|
future-done?
|
||||||
;; Immutable objects
|
;; Immutable objects
|
||||||
immutable?
|
immutable?
|
||||||
;; Shared objects
|
;; Shared objects
|
||||||
|
@ -30,6 +33,13 @@
|
||||||
)
|
)
|
||||||
(begin
|
(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?
|
(define-c atom?
|
||||||
"(void *data, int argc, closure _, object k, object obj)"
|
"(void *data, int argc, closure _, object k, object obj)"
|
||||||
" object result = Cyc_is_atomic(obj);
|
" object result = Cyc_is_atomic(obj);
|
||||||
|
@ -68,7 +78,7 @@
|
||||||
(%make-atom #f)))
|
(%make-atom #f)))
|
||||||
|
|
||||||
;; - deref atomic
|
;; - deref atomic
|
||||||
(define-c deref
|
(define-c atom-deref
|
||||||
"(void *data, int argc, closure _, object k, object obj)"
|
"(void *data, int argc, closure _, object k, object obj)"
|
||||||
" atomic a;
|
" atomic a;
|
||||||
Cyc_check_atomic(data, obj);
|
Cyc_check_atomic(data, obj);
|
||||||
|
@ -183,11 +193,12 @@
|
||||||
(thread-start! t)
|
(thread-start! t)
|
||||||
ftr))
|
ftr))
|
||||||
|
|
||||||
;;(define (future-done? ftr)
|
(define (future-done? ftr)
|
||||||
;; (when (not (future? ftr))
|
(when (not (future? ftr))
|
||||||
;; (error "Expected future but received" 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
|
(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-cancel ftr)
|
||||||
;; TODO: (future-cancelled? ftr)
|
;; TODO: (future-cancelled? ftr)
|
||||||
|
|
Loading…
Add table
Reference in a new issue