mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-14 08:17:35 +02:00
Relocated (immutable?) procedure
This commit is contained in:
parent
f3881ec059
commit
1b0c5f3e78
2 changed files with 34 additions and 33 deletions
|
@ -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); ")
|
||||
|
||||
)
|
||||
)
|
||||
|
|
|
@ -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)"
|
||||
|
|
Loading…
Add table
Reference in a new issue