|
69 | 69 | (defn- get-metadata-if-changed?
|
70 | 70 | [^Var the-var, ^WeakHashMap real-metadata-ns-cache]
|
71 | 71 | (let [var-name (.sym the-var)
|
72 |
| - ;; WHM is not thread-safe but we should only access this from a single |
73 |
| - ;; (session) thread. |
74 | 72 | cached-meta (some-> real-metadata-ns-cache (.get var-name))
|
75 | 73 | current-meta (meta the-var)]
|
76 | 74 | (when-not (identical? cached-meta current-meta)
|
|
116 | 114 | [the-ns]
|
117 | 115 | (let [ns-sym (ns-name the-ns)
|
118 | 116 | old-project-ns-map (:interns (get *old-project-state* ns-sym))
|
119 |
| - real-metadata-whm (when *real-metadata-cache* |
| 117 | + real-metadata-whm (if *real-metadata-cache* |
120 | 118 | (or (@*real-metadata-cache* ns-sym)
|
121 | 119 | ((swap! *real-metadata-cache* assoc ns-sym
|
122 |
| - (WeakHashMap.)) ns-sym)))] |
123 |
| - (reduce-kv (fn [acc sym the-var] |
124 |
| - (if (and (var? the-var) |
125 |
| - (not (identical? (.ns ^Var the-var) |
126 |
| - clojure-core))) |
127 |
| - (let [old-meta (get old-project-ns-map sym) |
128 |
| - new-meta (compute-var-meta the-var real-metadata-whm |
129 |
| - old-project-ns-map)] |
130 |
| - (if (identical? old-meta new-meta) |
131 |
| - acc |
132 |
| - (assoc acc sym new-meta))) |
133 |
| - acc)) |
134 |
| - old-project-ns-map |
135 |
| - (ns-map the-ns)))) |
| 120 | + (WeakHashMap.)) ns-sym)) |
| 121 | + (WeakHashMap.))] |
| 122 | + ;; WHM is not thread-safe, so synchronize the access to it to avoid infinite |
| 123 | + ;; loops like https://github.com/clojure-emacs/cider-nrepl/issues/936. |
| 124 | + (locking real-metadata-whm |
| 125 | + (reduce-kv (fn [acc sym the-var] |
| 126 | + (if (and (var? the-var) |
| 127 | + (not (identical? (.ns ^Var the-var) |
| 128 | + clojure-core))) |
| 129 | + (let [old-meta (get old-project-ns-map sym) |
| 130 | + new-meta (compute-var-meta the-var real-metadata-whm |
| 131 | + old-project-ns-map)] |
| 132 | + (if (identical? old-meta new-meta) |
| 133 | + acc |
| 134 | + (assoc acc sym new-meta))) |
| 135 | + acc)) |
| 136 | + old-project-ns-map |
| 137 | + (ns-map the-ns))))) |
136 | 138 |
|
137 | 139 | (def clojure-core-map
|
138 | 140 | (when clojure-core
|
|
0 commit comments