(ns michael.ds.monitor (:import [java.util.concurrent.locks ReentrantLock Condition ]))
(def locks (atom { :monitors {} :conds {} })) (defn create-monitor[] (ReentrantLock.)) (defn create-cond[m] (.newCondition m)) (defmacro lock-monitor[ lck & body ] `(let [z# ~lck] (try (.lock z#) ~...@body (finally (.unlock z#))))) (defn signal-cond[ c ] (.signal c)) (defn wait-cond[c] (.await c)) (defmacro my-locking[ [ m & biding ] & body ] `(let [a# '~m] (let [b# (get-in @locks [ :monitors a#]) c# (if-not b# (let [mm# (java.util.concurrent.locks.ReentrantLock.)] (swap! locks (fn [d#] (assoc-in d# [ :monitors a#] mm#))) mm#) b# )] (lock-monitor c# ~...@body)))) ;(macroexpand '(my-locking [kozak] (println "abc"))) (my-locking [kozak] (println "abc")) (println locks) I have written first part. Locking which can dynamicly create monitors. Now I need condition creation, but tired already with first part :-) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en