Skip to content

Commit

Permalink
locking
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Nov 23, 2024
1 parent a8ee100 commit 3746033
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
5 changes: 3 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{:paths ["resources" "src"]
:deps {borkdude/edamame {:mvn/version "1.4.27"}
borkdude/sci.impl.reflector {:mvn/version "0.0.3"}
org.babashka/sci.impl.types {:mvn/version "0.0.2"}}
org.babashka/sci.impl.types {:mvn/version "0.0.2"}
borkdude/graal.locking {:mvn/version "0.0.2"}}
:aliases
{:examples {:extra-paths ["examples"]}
:dev {:extra-deps {org.clojure/clojure {:mvn/version "1.12.0"}}
Expand All @@ -11,7 +12,7 @@
org.clojure/clojurescript {:mvn/version "1.11.132"}
clj-commons/conch {:mvn/version "0.9.2"}
funcool/promesa {:mvn/version "8.0.450"}}}
:shadow {:extra-deps {thheller/shadow-cljs {:mvn/version "2.28.16"}}}
:shadow {:extra-deps {thheller/shadow-cljs {:mvn/version "2.28b.16"}}}
:cljs {:extra-deps {org.clojure/clojurescript {:mvn/version "1.11.54"}}}
:clj-test-runner
{:extra-deps {com.cognitect/test-runner
Expand Down
3 changes: 2 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
:dependencies [[org.clojure/clojure "1.9.0"]
[borkdude/sci.impl.reflector "0.0.3"]
[borkdude/edamame "1.4.27"]
[org.babashka/sci.impl.types "0.0.2"]]
[org.babashka/sci.impl.types "0.0.2"]
[borkdude/graal.locking "0.0.2"]]
:plugins [[lein-codox "0.10.7"]]
:profiles {:clojure-1.9.0 {:dependencies [[org.clojure/clojure "1.9.0"]]}
:clojure-1.10.3 {:depdencies [[org.clojure/clojure "1.10.3"]]}
Expand Down
11 changes: 11 additions & 0 deletions src/sci/impl/namespaces.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
time
exists?])
(:require
#?(:clj [borkdude.graal.locking :as locking])
#?(:clj [clojure.edn :as edn]
:cljs [cljs.reader :as edn])
#?(:clj [clojure.java.io :as jio])
Expand Down Expand Up @@ -53,6 +54,14 @@

(def clojure-core-ns sci.impl.utils/clojure-core-ns)

#?(:clj (defn -locking-impl [lockee lock-fn]
(borkdude.graal.LockFix/lock lockee lock-fn)))

(defn locking* [_form _bindings
#?(:clj x :cljs _x) & body]
#?(:clj `(clojure.core/-locking-impl ~x (^{:once true} fn* [] ~@body))
:cljs `(do ~@body)))

(defn ->*
[_ _ x & forms]
(loop [x x, forms forms]
Expand Down Expand Up @@ -1419,6 +1428,8 @@
'lazy-cat (macrofy 'lazy-cat lazy-cat*)
'let (macrofy 'let let**)
'letfn (macrofy 'letfn letfn*)
'locking (macrofy 'locking locking*)
#?@(:clj ['-locking-impl (copy-var -locking-impl clojure-core-ns)])
'load-string (copy-var load-string clojure-core-ns {:copy-meta-from 'clojure.core/load-string :ctx true})
'loaded-libs (copy-var loaded-libs* clojure-core-ns {:name 'loaded-libs :ctx true})
'loop (macrofy 'loop loop**)
Expand Down

0 comments on commit 3746033

Please sign in to comment.