Skip to content

Commit 0508695

Browse files
committed
Tidy the source a bit
1 parent 15fc918 commit 0508695

File tree

8 files changed

+72
-70
lines changed

8 files changed

+72
-70
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ to catch and handle."
3131
[clojure.core.async.impl.concurrent :as conc]
3232
)
3333
(:import [clojure.lang AtomicLong] ;;; [java.util.concurrent.atomic AtomicLong]
34-
[clojure.core.async.impl.mutex ILock] ;;; [java.util.concurrent.locks Lock]
34+
[clojure.core.async.impl.mutex ILock] ;;; [java.util.concurrent.locks Lock]
3535
;;; [java.util.concurrent Executors Executor ThreadLocalRandom]
3636
[System.Collections ArrayList] ;;; [java.util Arrays ArrayList]
3737
[clojure.lang Var]))
@@ -45,7 +45,7 @@ to catch and handle."
4545
(fn-handler f true))
4646
([f blockable]
4747
(reify
48-
ILock ;;; Lock
48+
ILock ;;; Lock
4949
(lock [_])
5050
(unlock [_])
5151

@@ -239,11 +239,11 @@ to catch and handle."
239239
(recur (inc i)))))))
240240

241241
(defn- alt-flag []
242-
(let [^ILock m (mutex/mutex) ;;; Lock
242+
(let [^ILock m (mutex/mutex) ;;; Lock
243243
flag (atom true)
244244
id (.incrementAndGet id-gen)]
245245
(reify
246-
ILock ;;; Lock
246+
ILock ;;; Lock
247247
(lock [_] (.lock m))
248248
(unlock [_] (.unlock m))
249249

@@ -257,7 +257,7 @@ to catch and handle."
257257

258258
(defn- alt-handler [^ILock flag cb] ;;; ^Lock
259259
(reify
260-
ILock ;;; Lock
260+
ILock ;;; Lock
261261
(lock [_] (.lock flag))
262262
(unlock [_] (.unlock flag))
263263

@@ -470,8 +470,8 @@ to catch and handle."
470470
(ioc/run-state-machine-wrapped state#))))
471471
c#)))
472472

473-
(defonce ^:private counted-thread-factory ;;; ^Executor thread-macro-executor ***** Not having executors, we will have to use our regular thread pool.
474-
(conc/counted-thread-factory "async-thread-macro-%d" true)) ;;; (Executors/newCachedThreadPool (conc/counted-thread-factory "async-thread-macro-%d" true)) ***** However, we did define conc/count-thread-factory
473+
(defonce ^:private counted-thread-factory ;;; ^Executor thread-macro-executor ***** Not having executors, we will have to use our regular thread pool.
474+
(conc/counted-thread-factory "async-thread-macro-%d" true)) ;;; (Executors/newCachedThreadPool (conc/counted-thread-factory "async-thread-macro-%d" true)) ***** However, we did define conc/count-thread-factory
475475

476476
(defn thread-call
477477
"Executes f in another thread, returning immediately to the calling
@@ -480,7 +480,7 @@ to catch and handle."
480480
[f]
481481
(let [c (chan 1)]
482482
(let [binds (clojure.lang.Var/getThreadBindingFrame)]
483-
(.Start (.newThread counted-thread-factory ;;; .execute thread-macro-executor
483+
(.Start (.newThread counted-thread-factory ;;; .execute thread-macro-executor
484484
(fn []
485485
(Var/resetThreadBindingFrame binds)
486486
(try
@@ -1237,7 +1237,7 @@ to catch and handle."
12371237
(recur (make-array Object n) 0)))))
12381238
(do (when (> idx 0)
12391239
(let [narray (make-array Object idx)]
1240-
(Array/Copy arr 0 narray 0 idx) ;;; System/arraycopy
1240+
(Array/Copy arr 0 narray 0 idx) ;;; System/arraycopy
12411241
(>! out (vec narray))))
12421242
(close! out))))))
12431243
out)))

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,18 @@
101101
(put!
102102
[this val handler]
103103
(when (nil? val)
104-
(throw (ArgumentException. "Can't put nil on channel"))) ;;; IllegalArgumentException
104+
(throw (ArgumentException. "Can't put nil on channel"))) ;;; IllegalArgumentException
105105
(.lock mutex)
106106
(cleanup this)
107107
(if @closed
108-
(let [^ILock handler handler] ;;; ^Lock
108+
(let [^ILock handler handler] ;;; ^Lock
109109
(.lock handler)
110110
(when (impl/active? handler) (impl/commit handler))
111111
(.unlock handler)
112112
(.unlock mutex)
113113
(box false))
114-
(let [^ILock handler handler] ;;; ^Lock
115-
(if (and buf (not (impl/full? buf)) (not (= (.Count takes) 0))) ;;; (.isEmpty takes)
114+
(let [^ILock handler handler] ;;; ^Lock
115+
(if (and buf (not (impl/full? buf)) (not (= (.Count takes) 0))) ;;; (.isEmpty takes)
116116
(do
117117
(.lock handler)
118118
(let [put-cb (and (impl/active? handler) (impl/commit handler))]
@@ -261,7 +261,7 @@
261261
(loop [cbs []
262262
curr-node (.First puts)]
263263
(let [next-node (.Next curr-node)
264-
[^ILock putter val] (.Value curr-node)] ;;; ^Lock
264+
[^ILock putter val] (.Value curr-node)] ;;; ^Lock
265265
(.lock putter)
266266
(let [cb (and (impl/active? putter) (impl/commit putter))]
267267
(.unlock putter)
@@ -303,7 +303,7 @@
303303
(when (.First puts)
304304
(loop [curr-node (.First puts)]
305305
(let [next-node (.Next curr-node)
306-
[^ILock putter val] (.Value curr-node)] ;;; ^Lock
306+
[^ILock putter val] (.Value curr-node)] ;;; ^Lock
307307
(if (< (impl/lock-id handler) (impl/lock-id putter))
308308
(do (.lock handler) (.lock putter))
309309
(do (.lock putter) (.lock handler)))
@@ -338,10 +338,10 @@
338338
(do
339339
(when (impl/blockable? handler)
340340
(assert-unlock mutex
341-
(< (.Count takes) impl/MAX-QUEUE-SIZE) ;;; .size
341+
(< (.Count takes) impl/MAX-QUEUE-SIZE) ;;; .size
342342
(str "No more than " impl/MAX-QUEUE-SIZE
343343
" pending takes are allowed on a single channel."))
344-
(.AddLast takes handler)) ;;; .add
344+
(.AddLast takes handler)) ;;; .add
345345
(.unlock mutex)
346346
nil)))))))
347347

@@ -357,7 +357,7 @@
357357
nil)
358358
(do
359359
(reset! closed true)
360-
(when (and buf (= (.Count puts) 0)) ;;; (.isEmpty puts)
360+
(when (and buf (= (.Count puts) 0)) ;;; (.isEmpty puts)
361361
(add! buf))
362362
;;; (let [iter (.iterator takes)]
363363
;;; (when (.hasNext iter)
@@ -374,7 +374,7 @@
374374
(when (.First takes)
375375
(loop [curr-node (.First takes)]
376376
(let [next-node (.Next curr-node)
377-
^ILock taker (.Value curr-node)] ;;; ^Lock
377+
^ILock taker (.Value curr-node)] ;;; ^Lock
378378
(.lock taker)
379379
(let [take-cb (and (impl/active? taker) (impl/commit taker))]
380380
(.unlock taker)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@
6767

6868
(defonce
6969
^{:doc "Number of processors reported by the JVM"}
70-
processors Environment/ProcessorCount) ;;; (.availableProcessors (Runtime/getRuntime))
70+
processors Environment/ProcessorCount) ;;; (.availableProcessors (Runtime/getRuntime))

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@
1616
;;;(defonce ^:private in-dispatch (ThreadLocal.))
1717

1818
(defonce executor
19-
(delay (tp/thread-pool-executor ))) ;;; #(.set ^ThreadLocal in-dispatch true) -- getting rid of this init-fn.
19+
(delay (tp/thread-pool-executor ))) ;;; #(.set ^ThreadLocal in-dispatch true) -- getting rid of this init-fn.
2020

2121
(defn in-dispatch-thread?
2222
"Returns true if the current thread is a go block dispatch pool thread"
2323
[]
24-
false) ;;; we have no way to detect (boolean (.get ^ThreadLocal in-dispatch))
24+
false) ;;; we have no way to detect (boolean (.get ^ThreadLocal in-dispatch))
2525

2626
(defn check-blocking-in-dispatch
2727
"If the current thread is a dispatch pool thread, throw an exception"
28-
[] ;;; making this a no-op
29-
) ;;; (when (.get ^ThreadLocal in-dispatch)
30-
;;; (throw (IllegalStateException. "Invalid blocking call in dispatch thread")))
28+
[] ;;; making this a no-op
29+
) ;;; (when (.get ^ThreadLocal in-dispatch)
30+
;;; (throw (IllegalStateException. "Invalid blocking call in dispatch thread")))
3131

3232
(defn run
3333
"Runs Runnable r in a thread pool thread"
34-
[r] ;;; ^Runnable -- we don't have this type. We are set up to take an IFn -- it will be called with no args
34+
[r] ;;; ^Runnable -- we don't have this type. We are set up to take an IFn -- it will be called with no args
3535
(impl/exec @executor r))

src/test/clojure/clojure/core/async/concurrent_test.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
(:require [clojure.test :refer :all]
1111
[clojure.core.async.impl.concurrent :as conc])
1212
(:import [System.Threading Thread]
13-
[clojure.core.async.impl.concurrent ThreadFactory])) ;;; [java.util.concurrent ThreadFactory]
13+
[clojure.core.async.impl.concurrent ThreadFactory])) ;;; [java.util.concurrent ThreadFactory]
1414

1515
(deftest test-counted-thread-factory
1616
(testing "Creates numbered threads"
1717
(let [^clojure.core.async.impl.concurrent.ThreadFactory factory (conc/counted-thread-factory "foo-%d" true)
1818
threads (repeatedly 3 #(.newThread factory (constantly nil)))]
19-
(is (= ["foo-1" "foo-2" "foo-3"] (map #(.Name ^Thread %) threads)))))) ;;; .getName
19+
(is (= ["foo-1" "foo-2" "foo-3"] (map #(.Name ^Thread %) threads)))))) ;;; .getName

src/test/clojure/clojure/core/async/ioc_macros_test.clj

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -65,26 +65,26 @@
6565
(try
6666
(throw (pause (Exception. "e")))
6767
(catch Exception e
68-
(pause (throw (Exception. (str (.Message e) "e")))))) ;;; .getMessage
68+
(pause (throw (Exception. (str (.Message e) "e")))))) ;;; .getMessage
6969
(catch Exception e
70-
(throw (throw (Exception. (str (.Message e) "e")))))) ;;; .getMessage
70+
(throw (throw (Exception. (str (.Message e) "e")))))) ;;; .getMessage
7171
(catch Exception e
72-
(.Message e))))))) ;;; .getMessage
72+
(.Message e))))))) ;;; .getMessage
7373
(testing "exception handlers and the class hierarchy"
7474
(is
7575
(runner
7676
(try
7777
(pause 10)
78-
(throw (ArgumentException.)) ;;; RuntimeException -- see above
79-
(catch SystemException _r ;;; RuntimeException
78+
(throw (ArgumentException.)) ;;; RuntimeException -- see above
79+
(catch SystemException _r ;;; RuntimeException
8080
(pause true))
8181
(catch Exception _e
8282
(pause false)))))
8383
(is
8484
(runner
8585
(try
8686
(pause 10)
87-
(throw (ArgumentException.)) ;;; RuntimeException
87+
(throw (ArgumentException.)) ;;; RuntimeException
8888
(catch Exception _e
8989
(pause true))))))
9090
(testing "don't explode trying to compile this"
@@ -261,7 +261,7 @@
261261
(is (= 42
262262
(runner
263263
(try 42
264-
(catch Exception ex ex))))) ;;; Throwable
264+
(catch Exception ex ex))))) ;;; Throwable
265265
(is (= 42
266266
(runner
267267
(try
@@ -272,7 +272,7 @@
272272
v (runner
273273
(try
274274
true
275-
(catch Exception _ex false) ;;; Throwable
275+
(catch Exception _ex false) ;;; Throwable
276276
(finally (pause (reset! a true)))))]
277277
(is (and @a v)))
278278

@@ -289,7 +289,7 @@
289289
(try
290290
(assert false)
291291
(finally (reset! a true))))
292-
(catch Exception ex ex))] ;;; Throwable
292+
(catch Exception ex ex))] ;;; Throwable
293293
(is (and @a v)))
294294

295295

@@ -306,34 +306,34 @@
306306
v (try (runner
307307
(try
308308
(try
309-
(throw (InvalidOperationException. "42")) ;;; AssertionError + stringify 42
309+
(throw (InvalidOperationException. "42")) ;;; AssertionError + stringify 42
310310
(finally (swap! a inc)))
311311
(finally (swap! a inc))))
312-
(catch InvalidOperationException ex ex))] ;;; AssertionError
312+
(catch InvalidOperationException ex ex))] ;;; AssertionError
313313
(is (= @a 2)))
314314

315315
(let [a (atom 0)
316316
v (try (runner
317317
(try
318318
(try
319-
(throw (InvalidOperationException. "42")) ;;; AssertionError + stringify 42
320-
(catch Exception ex (throw ex)) ;;; Throwable
319+
(throw (InvalidOperationException. "42")) ;;; AssertionError + stringify 42
320+
(catch Exception ex (throw ex)) ;;; Throwable
321321
(finally (swap! a inc)))
322-
(catch Exception ex (throw ex)) ;;; Throwable
322+
(catch Exception ex (throw ex)) ;;; Throwable
323323
(finally (swap! a inc))))
324-
(catch InvalidOperationException ex ex))] ;;; AssertionError
324+
(catch InvalidOperationException ex ex))] ;;; AssertionError
325325
(is (= @a 2)))
326326

327327
(let [a (atom 0)
328328
v (try (runner
329329
(try
330330
(try
331-
(throw (InvalidOperationException. (pause "42"))) ;;; AssertionError + stringify 42
332-
(catch Exception ex (pause (throw ex))) ;;; Throwable
331+
(throw (InvalidOperationException. (pause "42"))) ;;; AssertionError + stringify 42
332+
(catch Exception ex (pause (throw ex))) ;;; Throwable
333333
(finally (pause (swap! a inc))))
334-
(catch Exception ex (pause (throw ex))) ;;; Throwable
334+
(catch Exception ex (pause (throw ex))) ;;; Throwable
335335
(finally (pause (swap! a inc)))))
336-
(catch InvalidOperationException ex ex))] ;;; AssertionError
336+
(catch InvalidOperationException ex ex))] ;;; AssertionError
337337
(is (= @a 2)))))
338338

339339

@@ -564,13 +564,13 @@
564564
(ioc/run-state-machine state#)
565565
[state# (ioc/aget-object state# ioc/VALUE-IDX)])))
566566

567-
#_(deftest test-binding ;;;TODO
568-
(let [results (atom {})
569-
exception (atom nil)]
567+
#_(deftest test-binding ;;; This fails. I have no idea how it is supposed to work.
568+
(let [results (atom {}) ;;; I cannot even make sense of the output of the park-runner macro expansion.
569+
exception (atom nil)]
570570
;; run the machine on another thread without any existing binding frames.
571-
(doto (Thread.
572-
^Runnable
573-
(fn []
571+
(doto (System.Threading.Thread. ;;; Thread.
572+
^System.Threading.ThreadStart ;;; ^Runnable
573+
(gen-delegate System.Threading.ThreadStart [] (fn [] ;;; add gen-delegate call
574574
(try
575575
(let [[state result] (park-runner (binding [*1 2] (park 10) 100))]
576576
(ioc/run-state-machine state)
@@ -579,10 +579,12 @@
579579
;; environment on this thread, so use an atom to
580580
;; report results back to the main thread.
581581
(reset! results {:park-value result :final-value (ioc/aget-object state ioc/VALUE-IDX)}))
582-
(catch Throwable t
583-
(reset! exception t)))))
584-
(.start)
585-
(.join))
586-
(is (= 10 (:park-value @results)))
582+
(catch Exception t ;;; Throwable
583+
(reset! exception t))))))
584+
(.Start) ;;; .start
585+
(.Join)) ;;; .join
586+
(prn "results = " @results)
587+
(prn "exception = " @exception)
588+
(is (= 10 (:park-value @results)))
587589
(is (= 100 (:final-value @results)))
588590
(is (if @exception (throw @exception) true))))

src/test/clojure/clojure/core/async/timers_test.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
(swap! test-atom conj i))]
2323
(doto (System.Threading.Thread. ^System.Threading.ThreadStart (gen-delegate System.Threading.ThreadStart [] (f))) (.Start)))))] ;;; (Thread. ^Runnable f) (.start)
2424
(doseq [thread threads]
25-
(.Join ^System.Threading.Thread thread)) ;;; .join ^Thread
25+
(.Join ^System.Threading.Thread thread)) ;;; .join ^Thread
2626
(is (= @test-atom [3 1 2 0])
2727
"Timeouts close in order determined by their delays, not in order determined by their creation.")))

0 commit comments

Comments
 (0)