|
8 | 8 |
|
9 | 9 | (ns ^{:skip-wiki true}
|
10 | 10 | clojure.core.async.impl.dispatch
|
11 |
| - (:require [clojure.core.async.impl.protocols :as impl]) |
12 | 11 | (:import [java.util.concurrent Executors ExecutorService ThreadFactory]))
|
13 | 12 |
|
14 | 13 | (set! *warn-on-reflection* true)
|
15 | 14 |
|
16 |
| -(defonce ^:private in-dispatch (ThreadLocal.)) |
17 |
| - |
18 | 15 | (defonce executor nil)
|
19 | 16 |
|
20 | 17 | (defn counted-thread-factory
|
|
38 | 35 | (.setName (format name-format (swap! counter inc)))
|
39 | 36 | (.setDaemon daemon))))))))
|
40 | 37 |
|
41 |
| -(defonce |
42 |
| - ^{:doc "Number of processors reported by the JVM"} |
43 |
| - processors (.availableProcessors (Runtime/getRuntime))) |
44 |
| - |
45 |
| -(def ^:private pool-size |
46 |
| - "Value is set via clojure.core.async.pool-size system property; defaults to 8; uses a |
47 |
| - delay so property can be set from code after core.async namespace is loaded but before |
48 |
| - any use of the async thread pool." |
49 |
| - (delay (or (Long/getLong "clojure.core.async.pool-size") 8))) |
| 38 | +;; used only for implementing go-checking |
| 39 | +(def ^:private ^:dynamic *in-go-dispatch* false) |
50 | 40 |
|
51 | 41 | (defn in-dispatch-thread?
|
52 |
| - "Returns true if the current thread is a go block dispatch pool thread" |
| 42 | + "Returns true if the current thread is used for go block dispatch" |
53 | 43 | []
|
54 |
| - (boolean (.get ^ThreadLocal in-dispatch))) |
| 44 | + (boolean *in-go-dispatch*)) |
55 | 45 |
|
56 | 46 | (defn check-blocking-in-dispatch
|
57 |
| - "If the current thread is a dispatch pool thread, throw an exception" |
| 47 | + "If the current thread is being used for go block dispatch, throw an exception" |
58 | 48 | []
|
59 |
| - (when (.get ^ThreadLocal in-dispatch) |
| 49 | + (when (in-dispatch-thread?) |
60 | 50 | (throw (IllegalStateException. "Invalid blocking call in dispatch thread"))))
|
61 | 51 |
|
62 | 52 | (defn ex-handler
|
|
68 | 58 | nil)
|
69 | 59 |
|
70 | 60 | (defn- make-ctp-named
|
71 |
| - [workflow] |
72 |
| - (Executors/newCachedThreadPool (counted-thread-factory (str "async-" (name workflow) "-%d") true))) |
| 61 | + [workload] |
| 62 | + (Executors/newCachedThreadPool (counted-thread-factory (str "async-" (name workload) "-%d") true))) |
73 | 63 |
|
74 | 64 | (def virtual-threads-available?
|
75 | 65 | (try
|
|
0 commit comments