[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] scratch/benchmarks ef44d4b 2/6: Add per-symbol mutexes
From: |
Gemini Lasswell |
Subject: |
[Emacs-diffs] scratch/benchmarks ef44d4b 2/6: Add per-symbol mutexes |
Date: |
Sun, 25 Nov 2018 20:11:15 -0500 (EST) |
branch: scratch/benchmarks
commit ef44d4b2f62d32bf032a26d10fe92fd743bbd89c
Author: Gemini Lasswell <address@hidden>
Commit: Gemini Lasswell <address@hidden>
Add per-symbol mutexes
* lisp/thread.el (make-symbol-mutex): New function.
(with-symbol-mutex): New macro.
---
lisp/thread.el | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/lisp/thread.el b/lisp/thread.el
index 6582510..838b8c2 100644
--- a/lisp/thread.el
+++ b/lisp/thread.el
@@ -310,6 +310,25 @@ If there are no items in QUEUE, block until one is added."
(condition-notify (thread--queue-not-full queue))
item)))
+;;; Mutexes for variables
+
+(defun make-symbol-mutex (symbol)
+ "Create a mutex associated with SYMBOL."
+ (unless (get symbol 'thread--mutex)
+ (put symbol 'thread--mutex (make-mutex (symbol-name symbol)))))
+
+(defmacro with-symbol-mutex (symbol &rest body)
+ "Run BODY while holding the mutex for SYMBOL.
+If another thread holds the mutex, block until it is released."
+ (declare (indent 1)
+ (debug (symbolp body)))
+ (let ((g-mutex (gensym)))
+ `(let ((,g-mutex (get ',symbol 'thread--mutex)))
+ (if ,g-mutex
+ (with-mutex ,g-mutex
+ ,@body)
+ (error "`%s' doesn't have a mutex" ',symbol)))))
+
(provide 'thread)
;;; thread.el ends here
- [Emacs-diffs] branch scratch/benchmarks created (now e2b5f51), Gemini Lasswell, 2018/11/25
- [Emacs-diffs] scratch/benchmarks ef44d4b 2/6: Add per-symbol mutexes,
Gemini Lasswell <=
- [Emacs-diffs] scratch/benchmarks b2f0a4e 4/6: Bug#31671 band-aid, Gemini Lasswell, 2018/11/25
- [Emacs-diffs] scratch/benchmarks 632a12d 1/6: Add thread-safe messages and thread-safe queues, Gemini Lasswell, 2018/11/25
- [Emacs-diffs] scratch/benchmarks 40f179e 3/6: Instrument file descriptor mask code (bug#33198), Gemini Lasswell, 2018/11/25
- [Emacs-diffs] scratch/benchmarks e2b5f51 6/6: Create benchmark directory and add some benchmark tasks, Gemini Lasswell, 2018/11/25
- [Emacs-diffs] scratch/benchmarks 52c7cc8 5/6: Add ERB, a tool for running historical benchmarks, Gemini Lasswell, 2018/11/25