aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChouser <chouser@n01se.net>2009-07-02 22:44:26 -0400
committerChouser <chouser@n01se.net>2009-07-02 22:44:26 -0400
commite0080e640a2d9b79564a3fb6eb7ee36be1882901 (patch)
tree95cfc582007e757ba9acd34db8af16f854cbdda3
parent3073f0dc0614cb8c95f2debd0b7e6a75c1736ece (diff)
repl-utils: Fix init state for add-break-thread!
-rw-r--r--src/clojure/contrib/repl_utils.clj37
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