mirror of
https://github.com/janet-lang/janet
synced 2024-11-27 18:49:54 +00:00
Add ev/with-*lock macros.
This commit is contained in:
parent
91a583db27
commit
ace60e1898
@ -2,6 +2,7 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## Unreleased - ???
|
||||
- Add macros `ev/with-lock`, `ev/with-rlock`, and `ev/with-wlock` for using mutexes and rwlocks.
|
||||
- Add `with-env`
|
||||
- Add *module-make-env* dynamic binding
|
||||
- Add buffer/format-at
|
||||
|
@ -3748,6 +3748,30 @@
|
||||
[& body]
|
||||
~(,ev/thread (fn _do-thread [&] ,;body)))
|
||||
|
||||
(defn- acquire-release
|
||||
[acq rel lock body]
|
||||
(def l (gensym))
|
||||
~(do
|
||||
(def ,l ,lock)
|
||||
(,acq ,l)
|
||||
(defer (,rel ,l)
|
||||
,;body)))
|
||||
|
||||
(defmacro ev/with-lock
|
||||
``Run a body of code after acquiring a lock. Will automatically release the lock when done.``
|
||||
[lock & body]
|
||||
(acquire-release ev/acquire-lock ev/release-lock lock body))
|
||||
|
||||
(defmacro ev/with-rlock
|
||||
``Run a body of code after acquiring read access to an rwlock. Will automatically release the lock when done.``
|
||||
[lock & body]
|
||||
(acquire-release ev/acquire-rlock ev/release-rlock lock body))
|
||||
|
||||
(defmacro ev/with-wlock
|
||||
``Run a body of code after acquiring read access to an rwlock. Will automatically release the lock when done.``
|
||||
[lock & body]
|
||||
(acquire-release ev/acquire-wlock ev/release-wlock lock body))
|
||||
|
||||
(defmacro ev/spawn-thread
|
||||
``Run some code in a new thread. Like `ev/do-thread`, but returns nil immediately.``
|
||||
[& body]
|
||||
|
Loading…
Reference in New Issue
Block a user