diff options
author | Chouser <chouser@n01se.net> | 2009-07-02 22:44:26 -0400 |
---|---|---|
committer | Chouser <chouser@n01se.net> | 2009-07-02 22:48:34 -0400 |
commit | f0f48b03c2704a9247ef462b9d009cb752b57649 (patch) | |
tree | ea882b4d8ca834f6138dc3158ee2d100350f83ab /src/clojure | |
parent | 82cf0409d0fcb71be477ebfc4da18ee2128a2ad1 (diff) |
repl-utils: Fix init state for add-break-thread!
Diffstat (limited to 'src/clojure')
-rw-r--r-- | src/clojure/contrib/repl_utils.clj | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/src/clojure/contrib/repl_utils.clj b/src/clojure/contrib/repl_utils.clj index 5ab4b450..af694898 100644 --- a/src/clojure/contrib/repl_utils.clj +++ b/src/clojure/contrib/repl_utils.clj @@ -128,24 +128,23 @@ ;; Handle Ctrl-C keystrokes (def #^{:doc "Threads to stop when Ctrl-C is pressed. See 'add-break-thread!'"} - break-threads (ref nil)) - -(defn start-handling-break - "Register INT signal handler. After calling this, Ctrl-C will cause - all break-threads to be stopped. See 'add-break-thread!'" - [] - (when-not - (dosync - (if-let [inited @break-threads] - inited - (ref-set break-threads {}))) - (sun.misc.Signal/handle - (sun.misc.Signal. "INT") - (proxy [sun.misc.SignalHandler] [] - (handle [sig] - (let [exc (Exception. (str sig))] - (doseq [tref (vals @break-threads) :when (.get tref)] - (.stop (.get tref) exc)))))))) + break-threads (atom {})) + +(let [first-time (atom true)] + (defn start-handling-break + "Register INT signal handler. After calling this, Ctrl-C will cause + all break-threads to be stopped. See 'add-break-thread!'" + [] + (when (= :need-init + (swap! first-time + {:need-init false, false false, true :need-init})) + (sun.misc.Signal/handle + (sun.misc.Signal. "INT") + (proxy [sun.misc.SignalHandler] [] + (handle [sig] + (let [exc (Exception. (str sig))] + (doseq [tref (vals @break-threads) :when (.get tref)] + (.stop (.get tref) exc))))))))) (defn add-break-thread! "Add the given thread to break-threads so that it will be stopped @@ -155,7 +154,7 @@ ([t] (start-handling-break) (let [tref (java.lang.ref.WeakReference. t)] - (dosync (commute break-threads assoc (.getId t) tref))))) + (swap! break-threads assoc (.getId t) tref)))) ;; ---------------------------------------------------------------------- ;; Compiler hooks |