|
12 | 12 | [clojure.core.async.impl.dispatch :as dispatch]
|
13 | 13 | [clojure.core.async.impl.mutex :as mutex])
|
14 | 14 | (:import [System.Collections.Generic |LinkedList`1[System.Object]| |Queue`1[System.Object]|] ;;; [java.util LinkedList Queue]
|
15 |
| - [clojure.core.async.impl.mutex Lock] ;;; [java.util.concurrent.locks Lock] |
| 15 | + [clojure.core.async.impl.mutex ILock] ;;; [java.util.concurrent.locks Lock] |
16 | 16 | [clojure.lang IDeref]))
|
17 | 17 |
|
18 | 18 | (set! *warn-on-reflection* true)
|
19 | 19 |
|
20 | 20 | (defmacro assert-unlock [lock test msg]
|
21 | 21 | `(when-not ~test
|
22 | 22 | (.unlock ~lock)
|
23 |
| - (throw (new InvalidOperationException (str "Assert failed: " ~msg "\n" (pr-str '~test)))))) ;;; AssertionError |
| 23 | + (throw (new InvalidOperationException (str "Assert failed: " ~msg "\n" (pr-str '~test)))))) ;;; AssertionError |
24 | 24 |
|
25 | 25 | (defn box [val]
|
26 | 26 | (reify IDeref
|
|
86 | 86 | ;; this is more straightforward -- enumerator vs iterator again, but no delete
|
87 | 87 | (let [iter (.GetEnumerator puts)]
|
88 | 88 | (when (.MoveNext iter)
|
89 |
| - (loop [[^Lock putter] (.Current iter)] |
| 89 | + (loop [[^ILock putter] (.Current iter)] ;;; ^Lock |
90 | 90 | (let [put-cb (and (impl/active? putter) (impl/commit putter))]
|
91 | 91 | (.unlock putter)
|
92 | 92 | (when put-cb
|
93 | 93 | (dispatch/run (fn [] (put-cb true))))
|
94 | 94 | (when (.MoveNext iter)
|
95 | 95 | (recur (.Current iter)))))))
|
96 |
| - (.Clear puts) ;;; .clear |
| 96 | + (.Clear puts) ;;; .clear |
97 | 97 | (impl/close! this))
|
98 | 98 |
|
99 | 99 | impl/WritePort
|
100 | 100 | (put!
|
101 | 101 | [this val handler]
|
102 | 102 | (when (nil? val)
|
103 |
| - (throw (ArgumentException. "Can't put nil on channel"))) ;;; IllegalArgumentException |
| 103 | + (throw (ArgumentException. "Can't put nil on channel"))) ;;; IllegalArgumentException |
104 | 104 | (.lock mutex)
|
105 | 105 | (cleanup this)
|
106 | 106 | (if @closed
|
107 |
| - (let [^Lock handler handler] |
| 107 | + (let [^ILock handler handler] ;;; ^Lock |
108 | 108 | (.lock handler)
|
109 | 109 | (when (impl/active? handler) (impl/commit handler))
|
110 | 110 | (.unlock handler)
|
111 | 111 | (.unlock mutex)
|
112 | 112 | (box false))
|
113 |
| - (let [^Lock handler handler] |
| 113 | + (let [^ILock handler handler] ;;; ^Lock |
114 | 114 | (if (and buf (not (impl/full? buf)) (not (= (.Count takes) 0))) ;;; (.isEmpty takes)
|
115 | 115 | (do
|
116 | 116 | (.lock handler)
|
|
135 | 135 | [take-cbs (loop [takers []
|
136 | 136 | curr-node (.First takes)]
|
137 | 137 | (if (and curr-node (pos? (count buf)))
|
138 |
| - (let [^Lock taker curr-node |
| 138 | + (let [^ILock taker curr-node ;;; ^Lock |
139 | 139 | next-node (.Next curr-node)]
|
140 | 140 | (.lock taker)
|
141 | 141 | (let [ret (and (impl/active? taker) (impl/commit taker))]
|
|
166 | 166 | nil))))
|
167 | 167 | (let ;;;[iter (.iterator takes)
|
168 | 168 | ;;;[put-cb take-cb] (when (.hasNext iter)
|
169 |
| - ;;; (loop [^Lock taker (.next iter)] |
| 169 | + ;;; (loop [^Lock taker (.next iter)] |
170 | 170 | ;;; (if (< (impl/lock-id handler) (impl/lock-id taker))
|
171 | 171 | ;;; (do (.lock handler) (.lock taker))
|
172 | 172 | ;;; (do (.lock taker) (.lock handler)))
|
|
181 | 181 | ;;; (when (.hasNext iter)
|
182 | 182 | ;;; (recur (.next iter)))))))]
|
183 | 183 | [[put-cb take-cb] (when (.First takes)
|
184 |
| - (loop [^Lock taker (.First takes) |
| 184 | + (loop [^ILock taker (.First takes) ;;; ^Lock |
185 | 185 | curr-node (.First takes)]
|
186 | 186 | (if (< (impl/lock-id handler) (impl/lock-id taker))
|
187 | 187 | (do (.lock handler) (.lock taker))
|
|
219 | 219 | (do
|
220 | 220 | (when (and (impl/active? handler) (impl/blockable? handler))
|
221 | 221 | (assert-unlock mutex
|
222 |
| - (< (.Count puts) impl/MAX-QUEUE-SIZE) ;;; .size |
| 222 | + (< (.Count puts) impl/MAX-QUEUE-SIZE) ;;; .size |
223 | 223 | (str "No more than " impl/MAX-QUEUE-SIZE
|
224 | 224 | " pending puts are allowed on a single channel."
|
225 | 225 | " Consider using a windowed buffer."))
|
|
232 | 232 | [this handler]
|
233 | 233 | (.lock mutex)
|
234 | 234 | (cleanup this)
|
235 |
| - (let [^Lock handler handler |
| 235 | + (let [^ILock handler handler ;;; ^Lock |
236 | 236 | commit-handler (fn []
|
237 | 237 | (.lock handler)
|
238 | 238 | (let [take-cb (and (impl/active? handler) (impl/commit handler))]
|
|
260 | 260 | (loop [cbs []
|
261 | 261 | curr-node (.First puts)]
|
262 | 262 | (let [next-node (.Next curr-node)
|
263 |
| - [^Lock putter val] (.Value curr-node)] |
| 263 | + [^ILock putter val] (.Value curr-node)] ;;; ^Lock |
264 | 264 | (.lock putter)
|
265 | 265 | (let [cb (and (impl/active? putter) (impl/commit putter))]
|
266 | 266 | (.unlock putter)
|
|
302 | 302 | (when (.First puts)
|
303 | 303 | (loop [curr-node (.First puts)]
|
304 | 304 | (let [next-node (.Next curr-node)
|
305 |
| - [^Lock putter val] (.Value curr-node)] |
| 305 | + [^ILock putter val] (.Value curr-node)] ;;; ^Lock |
306 | 306 | (if (< (impl/lock-id handler) (impl/lock-id putter))
|
307 | 307 | (do (.lock handler) (.lock putter))
|
308 | 308 | (do (.lock putter) (.lock handler)))
|
|
373 | 373 | (when (.First takes)
|
374 | 374 | (loop [curr-node (.First takes)]
|
375 | 375 | (let [next-node (.Next curr-node)
|
376 |
| - ^Lock taker (.Value curr-node)] |
| 376 | + ^ILock taker (.Value curr-node)] ;;; ^Lock |
377 | 377 | (.lock taker)
|
378 | 378 | (let [take-cb (and (impl/active? taker) (impl/commit taker))]
|
379 | 379 | (.unlock taker)
|
|
0 commit comments