diff --git a/libs/cyclone/concurrent.sld b/libs/cyclone/concurrent.sld index 173147f1..eb2465e8 100644 --- a/libs/cyclone/concurrent.sld +++ b/libs/cyclone/concurrent.sld @@ -23,6 +23,8 @@ deref swap! compare-and-set! + ;; Immutable objects + immutable? ;; Shared objects make-shared share-all! @@ -95,23 +97,6 @@ (apply swap! atom f args) ;; Value changed, try again ))) -;; Return a reference to an object that can be safely shared by many threads. -;; -;; If the given object is atomic or already shared it it simply returned. -;; Otherwise it is necessary to create a copy of the object. -;; -;; Note this function may trigger a minor GC if a thread-local pair or vector -;; is passed. -(define-c make-shared - "(void *data, int argc, closure _, object k, object obj)" - " Cyc_make_shared_object(data, k, obj); ") - -;; Allow all objects currently on the calling thread's local stack to be shared -;; with other threads. -(define-c share-all! - "(void *data, int argc, closure _, object k)" - " Cyc_trigger_minor_gc(data, k); ") - ;; (compare-and-set! atom oldval newval) ;; https://clojuredocs.org/clojure.core/compare-and-set! ;; Atomically sets the value of atom to newval if and only if the @@ -130,5 +115,37 @@ object rv = result ? boolean_t : boolean_f; return_closcall1(data, k, rv); ") +;; Return a reference to an object that can be safely shared by many threads. +;; +;; If the given object is atomic or already shared it it simply returned. +;; Otherwise it is necessary to create a copy of the object. +;; +;; Note this function may trigger a minor GC if a thread-local pair or vector +;; is passed. +(define-c make-shared + "(void *data, int argc, closure _, object k, object obj)" + " Cyc_make_shared_object(data, k, obj); ") + +;; Allow all objects currently on the calling thread's local stack to be shared +;; with other threads. +(define-c share-all! + "(void *data, int argc, closure _, object k)" + " Cyc_trigger_minor_gc(data, k); ") + +;; Predicate - is the given object immutable? +(define-c immutable? + "(void *data, int argc, closure _, object k, object obj)" + "object result = boolean_t; + if (is_object_type(obj) && + (type_of(obj) == pair_tag || + type_of(obj) == vector_tag || + type_of(obj) == bytevector_tag || + type_of(obj) == string_tag + ) && + !immutable(obj) ) { + result = boolean_f; + } + return_closcall1(data, k, result); ") + ) ) diff --git a/scheme/cyclone/util.sld b/scheme/cyclone/util.sld index c909fe87..dd7536ff 100644 --- a/scheme/cyclone/util.sld +++ b/scheme/cyclone/util.sld @@ -77,7 +77,6 @@ define-c-inline? define-c->inline-var ;; Immutable objects - immutable? Cyc-set-immutable! ;; String functions string-join @@ -755,21 +754,6 @@ ;; Immutable Object section -;; Predicate - is the given object immutable? -(define-c immutable? - "(void *data, int argc, closure _, object k, object obj)" - "object result = boolean_t; - if (is_object_type(obj) && - (type_of(obj) == pair_tag || - type_of(obj) == vector_tag || - type_of(obj) == bytevector_tag || - type_of(obj) == string_tag - ) && - !immutable(obj) ) { - result = boolean_f; - } - return_closcall1(data, k, result); ") - ;; Internal helper function - set immutable field on a single obj (define-c _Cyc-set-immutable! "(void *data, int argc, closure _, object k, object obj, object val)"