Skip to content

Commit 821a671

Browse files
committed
finer-grained vthreads checking
1 parent fd16cb0 commit 821a671

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/main/clojure/clojure/core/async.clj

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ unset - default to ioc when aot, always
156156
(let [as (mapv #(list 'quote %) arglist)
157157
blockingop (-> op name (str "!") symbol)]
158158
`(def ~(with-meta op {:arglists `(list ~as) :doc doc})
159-
(if (dispatch/targetting-vthreads?)
159+
(if (dispatch/runtime-vthreads?)
160160
(fn [~'& ~'args]
161161
~(list* apply blockingop '[args]))
162162
(fn ~arglist
@@ -511,7 +511,7 @@ unset - default to ioc when aot, always
511511
Returns a channel which will receive the result of the body when
512512
completed"
513513
[& body]
514-
(if (dispatch/targetting-vthreads?)
514+
(if (or (dispatch/aot-vthreads?) (dispatch/runtime-vthreads?))
515515
`(thread-call (^:once fn* [] ~@body) :io)
516516
(#'clojure.core.async.impl.go/go-impl &env body)))
517517

src/main/clojure/clojure/core/async/impl/dispatch.clj

+8-6
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,17 @@
7575
[s]
7676
(= s (System/getProperty "clojure.core.async.vthreads")))
7777

78-
(defn targetting-vthreads? []
79-
(or (and aot-compiling? (vthreads-directive-of "target"))
80-
(and (not aot-compiling?)
81-
(not (vthreads-directive-of "avoid"))
82-
virtual-threads-available?)))
78+
(defn aot-vthreads? []
79+
(and aot-compiling? (vthreads-directive-of "target")))
80+
81+
(defn runtime-vthreads? []
82+
(and (not aot-compiling?)
83+
(not (vthreads-directive-of "avoid"))
84+
virtual-threads-available?))
8385

8486
(defn- make-io-executor
8587
[]
86-
(if (targetting-vthreads?)
88+
(if (runtime-vthreads?)
8789
(-> (.getDeclaredMethod Executors "newVirtualThreadPerTaskExecutor" (make-array Class 0))
8890
(.invoke nil (make-array Class 0)))
8991
(make-ctp-named :io)))

0 commit comments

Comments
 (0)