File tree Expand file tree Collapse file tree 2 files changed +27
-14
lines changed
src/main/clojure/clojure/core/async/impl Expand file tree Collapse file tree 2 files changed +27
-14
lines changed Original file line number Diff line number Diff line change 12
12
13
13
(set! *warn-on-reflection* true )
14
14
15
- (defonce ^:private in-dispatch (ThreadLocal. ))
16
-
17
15
(defonce executor nil )
18
16
19
17
(defn counted-thread-factory
37
35
(.setName (format name-format (swap! counter inc)))
38
36
(.setDaemon daemon))))))))
39
37
38
+ ; ; go blocking checking
39
+
40
+ (defonce in-go-dispatch (ThreadLocal. ))
41
+
42
+ (defmacro with-dispatch-thread-marking
43
+ [& body]
44
+ (if (Boolean/getBoolean " clojure.core.async.go-checking" )
45
+ `(try
46
+ (.set in-go-dispatch true )
47
+ ~@body
48
+ (finally
49
+ (.set in-go-dispatch false )))
50
+ `(do ~@body)))
51
+
40
52
(defn in-dispatch-thread?
41
- " Returns true if the current thread is a go block dispatch pool thread "
53
+ " Returns true if the current thread is used for go block dispatch"
42
54
[]
43
- (boolean (.get ^ThreadLocal in-dispatch)))
55
+ (boolean (.get ^ThreadLocal in-go- dispatch)))
44
56
45
57
(defn check-blocking-in-dispatch
46
- " If the current thread is a dispatch pool thread , throw an exception"
58
+ " If the current thread is being used for go block dispatch , throw an exception"
47
59
[]
48
- (when (.get ^ThreadLocal in-dispatch)
60
+ (when (in-dispatch-thread? )
49
61
(throw (IllegalStateException. " Invalid blocking call in dispatch thread" ))))
50
62
51
63
(defn ex-handler
Original file line number Diff line number Diff line change 1048
1048
captured-bindings# (Var/getThreadBindingFrame )]
1049
1049
(dispatch/run
1050
1050
(^:once fn* []
1051
- (let [~@(mapcat (fn [[l sym]] [sym `(^:once fn* [] ~(vary-meta l dissoc :tag ))]) crossing-env)
1052
- f# ~(state-machine
1053
- `(do ~@body) 1 [crossing-env env] rt/async-custom-terminators)
1054
- state# (-> (f# )
1055
- (rt/aset-all! rt/USER-START-IDX c#
1056
- rt/BINDINGS-IDX captured-bindings#))]
1057
- (rt/run-state-machine-wrapped state#))))
1058
- c#)))
1051
+ (dispatch/with-dispatch-thread-marking
1052
+ (let [~@(mapcat (fn [[l sym]] [sym `(^:once fn* [] ~(vary-meta l dissoc :tag ))]) crossing-env)
1053
+ f# ~(state-machine
1054
+ `(do ~@body) 1 [crossing-env env] rt/async-custom-terminators)
1055
+ state# (-> (f# )
1056
+ (rt/aset-all! rt/USER-START-IDX c#
1057
+ rt/BINDINGS-IDX captured-bindings#))]
1058
+ (rt/run-state-machine-wrapped state#)))))
1059
+ c#)))
You can’t perform that action at this time.
0 commit comments