File tree 2 files changed +25
-19
lines changed
src/main/clojure/clojure/core/async/impl
2 files changed +25
-19
lines changed Original file line number Diff line number Diff line change 13
13
14
14
(set! *warn-on-reflection* true )
15
15
16
- (defonce ^:private in-dispatch (ThreadLocal. ))
17
-
18
16
(defonce executor nil )
19
17
20
18
(defn counted-thread-factory
48
46
any use of the async thread pool."
49
47
(delay (or (Long/getLong " clojure.core.async.pool-size" ) 8 )))
50
48
49
+ ; ; used only for implementing go-checking
50
+ (def ^:private ^:dynamic *in-go-dispatch* false )
51
+
51
52
(defn in-dispatch-thread?
52
- " 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"
53
54
[]
54
- (boolean ( .get ^ThreadLocal in-dispatch) ))
55
+ (boolean * in-go- dispatch* ))
55
56
56
57
(defn check-blocking-in-dispatch
57
- " 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"
58
59
[]
59
- (when (.get ^ThreadLocal in-dispatch)
60
+ (when (in-dispatch-thread? )
60
61
(throw (IllegalStateException. " Invalid blocking call in dispatch thread" ))))
61
62
62
63
(defn ex-handler
Original file line number Diff line number Diff line change 1041
1041
second
1042
1042
(emit-state-machine num-user-params user-transitions))))
1043
1043
1044
+ (def ^:private go-checking (Boolean/getBoolean " clojure.core.async.go-checking" ))
1045
+
1044
1046
(defn go-impl
1045
1047
[env body]
1046
- (let [crossing-env (zipmap (keys env) (repeatedly gensym))]
1047
- `(let [c# (clojure.core.async/chan 1 )
1048
- captured-bindings# (Var/getThreadBindingFrame )]
1049
- (dispatch/run
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#)))
1048
+ (let [crossing-env (zipmap (keys env) (repeatedly gensym))
1049
+ run-body `(let [c# (clojure.core.async/chan 1 )
1050
+ captured-bindings# (Var/getThreadBindingFrame )]
1051
+ (dispatch/run
1052
+ (^:once fn* []
1053
+ (let [~@(mapcat (fn [[l sym]] [sym `(^:once fn* [] ~(vary-meta l dissoc :tag ))]) crossing-env)
1054
+ f# ~(state-machine
1055
+ `(do ~@body) 1 [crossing-env env] rt/async-custom-terminators)
1056
+ state# (-> (f# )
1057
+ (rt/aset-all! rt/USER-START-IDX c#
1058
+ rt/BINDINGS-IDX captured-bindings#))]
1059
+ (rt/run-state-machine-wrapped state#))))
1060
+ c#)]
1061
+ (if go-checking
1062
+ (list 'binding ['clojure.core.async.impl.dispatch/*in-go-dispatch* true ] run-body)
1063
+ run-body)))
You can’t perform that action at this time.
0 commit comments