Skip to content

Commit 4b328de

Browse files
committed
Added ensure-runtime-vthreads check on flag=target AOT emit
1 parent 97a0679 commit 4b328de

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -514,13 +514,10 @@ use vthreads in io-thread when available
514514
Returns a channel which will receive the result of the body when
515515
completed"
516516
[& body]
517-
(if (or (dispatch/aot-vthreads?) (dispatch/runtime-vthreads?))
518-
`(if (and (= dispatch/compiled-vthreads-flag "target") (not (dispatch/runtime-vthreads?)))
519-
(throw (ex-info "Code compiled to target virtual threads, but is running on a JVM without vthread support."
520-
{:compiled-vthreads-flag dispatch/compiled-vthreads-flag
521-
:runtime-jvm-version (System/getProperty "java.version")}))
522-
(thread-call (^:once fn* [] ~@body) :io))
523-
((find-var 'clojure.core.async.impl.go/go-impl) &env body)))
517+
(cond (dispatch/aot-vthreads?) `(do (dispatch/ensure-runtime-vthreads!)
518+
(thread-call (^:once fn* [] ~@body) :io))
519+
(dispatch/runtime-vthreads?) `(thread-call (^:once fn* [] ~@body) :io)
520+
:default ((find-var 'clojure.core.async.impl.go/go-impl) &env body)))
524521

525522
(defonce ^:private thread-macro-executor nil)
526523

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@
8585
[]
8686
(System/getProperty "clojure.core.async.vthreads"))
8787

88-
(def compiled-vthreads-flag (vthreads-directive))
89-
9088
(defn aot-vthreads? []
9189
(and clojure.core/*compile-files*
9290
(= (vthreads-directive) "target")))
@@ -98,6 +96,11 @@
9896
(not= (vthreads-directive) "avoid")
9997
@virtual-threads-available?))))
10098

99+
(defn ensure-runtime-vthreads! []
100+
(when (not (runtime-vthreads?))
101+
(throw (ex-info "Code compiled to target virtual threads, but is running on a JVM without vthread support."
102+
{:runtime-jvm-version (System/getProperty "java.version")}))))
103+
101104
(defn- make-io-executor
102105
[]
103106
(if (runtime-vthreads?)

0 commit comments

Comments
 (0)