[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/xelb 846f4c0 33/42: Fix race conditions
From: |
Chris Feng |
Subject: |
[elpa] externals/xelb 846f4c0 33/42: Fix race conditions |
Date: |
Thu, 17 Sep 2015 23:16:49 +0000 |
branch: externals/xelb
commit 846f4c098b5545312ad3eec6ed3d8bce3152f88b
Author: Chris Feng <address@hidden>
Commit: Chris Feng <address@hidden>
Fix race conditions
* Ensure event handlers are running sequentially
* Only accept outputs from the current process when calling
`accept-process-output process` (close ch11ng/exwm#53)
---
xcb.el | 24 ++++++++++++++----------
1 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/xcb.el b/xcb.el
index 29475f8..c356c63 100644
--- a/xcb.el
+++ b/xcb.el
@@ -78,7 +78,7 @@
(setup-data :initform nil) ;X connection setup data
(request-cache :initform []) ;cache for outgoing requests
(message-cache :initform []) ;cache for incoming messages
- (event-lock :initform nil)
+ (event-lock :initform 0)
(event-queue :initform nil)
(error-plist :initform nil)
(reply-plist :initform nil)
@@ -186,7 +186,7 @@ SCREEN."
(with-timeout (xcb:connection-timeout (xcb:disconnect obj)
(error "[XELB] Connection timeout"))
(while (not (slot-value obj 'setup-data))
- (accept-process-output process 1)))))
+ (accept-process-output process 1 nil 1)))))
(defun xcb:-connection-filter (process message)
"Filter function for an X connection.
@@ -304,15 +304,15 @@ Concurrency is disabled as it breaks the orders of
errors, replies and events."
(when (/= current-cache-length cache-length)
(xcb:-connection-filter process []))))
(with-slots (event-lock event-queue) connection
- (unless event-lock
- (setf event-lock t)
+ (unless (< 0 event-lock)
+ (cl-incf event-lock)
(let (event data synthetic)
(while (setq event (pop event-queue))
(setq data (elt event 1)
synthetic (elt event 2))
(dolist (listener (elt event 0))
(funcall listener data synthetic))))
- (setf event-lock nil))))))
+ (cl-decf event-lock))))))
(cl-defmethod xcb:disconnect ((obj xcb:connection))
"Disconnect from X server."
@@ -441,10 +441,10 @@ classes of EVENT (since they have the same event number)."
(+ (length msg) (length cache))) ;flush on cache full
(xcb:flush obj)
(setq cache []))
- (xcb:-log "Cache request: %s" request)
(with-slots (request-cache request-sequence) obj
(setf request-cache (vconcat cache msg)
request-sequence (1+ request-sequence))
+ (xcb:-log "Cache request #%d: %s" request-sequence request)
request-sequence)))
(cl-defmethod xcb:-+request ((obj xcb:connection) request)
@@ -510,10 +510,12 @@ Otherwise no error will ever be reported."
;; Single reply
(let ((process (slot-value obj 'process)))
;; Wait until the request processed
- (with-timeout (xcb:connection-timeout (error "[XELB] Retrieve reply
timeout"))
+ (cl-incf (slot-value obj 'event-lock))
+ (with-timeout (xcb:connection-timeout (warn "[XELB] Retrieve reply
timeout"))
(while (and (> sequence (slot-value obj 'reply-sequence))
(> sequence (slot-value obj 'error-sequence)))
- (accept-process-output process 1)))))
+ (accept-process-output process 1 nil 1)))
+ (cl-decf (slot-value obj 'event-lock))))
(let* ((reply-plist (slot-value obj 'reply-plist))
(reply-data (plist-get reply-plist sequence))
(error-plist (slot-value obj 'error-plist))
@@ -622,9 +624,11 @@ Sync by sending a GetInputFocus request and waiting until
it's processed."
(process (slot-value obj 'process)))
(xcb:flush obj)
;; Wait until request processed
- (with-timeout (xcb:connection-timeout (error "[XELB] Sync timeout"))
+ (cl-incf (slot-value obj 'event-lock))
+ (with-timeout (xcb:connection-timeout (warn "[XELB] Sync timeout"))
(while (> sequence (slot-value obj 'reply-sequence))
- (accept-process-output process 1)))))
+ (accept-process-output process 1 nil 1)))
+ (cl-decf (slot-value obj 'event-lock))))
(cl-defmethod xcb:-error-or-event-class->number ((obj xcb:connection) class)
"Return the error/event number of a error/event class CLASS."
- [elpa] externals/xelb f465091 22/42: It's valid for WM_NORMAL_HINTS responses only to have 15 words., (continued)
- [elpa] externals/xelb f465091 22/42: It's valid for WM_NORMAL_HINTS responses only to have 15 words., Chris Feng, 2015/09/17
- [elpa] externals/xelb aaddcd9 18/42: Add implicit paddings after variable-length <list>, Chris Feng, 2015/09/17
- [elpa] externals/xelb e153829 23/42: Merge pull request #2 from pipcet/shift-keypad-fix, Chris Feng, 2015/09/17
- [elpa] externals/xelb 520120a 24/42: Merge pull request #3 from pipcet/ignore-missing-values, Chris Feng, 2015/09/17
- [elpa] externals/xelb 1e20b20 26/42: Adjust to unmarshalling API changes., Chris Feng, 2015/09/17
- [elpa] externals/xelb ad845df 28/42: Merge pull request #4 from pipcet/data-offset, Chris Feng, 2015/09/17
- [elpa] externals/xelb 1ab5bb9 29/42: Fix a typo in 32-bit version `xcb:-unpack-u4-lsb`, Chris Feng, 2015/09/17
- [elpa] externals/xelb 76ab2fb 25/42: Improve performance when unmarshalling long vectors., Chris Feng, 2015/09/17
- [elpa] externals/xelb f655ec9 27/42: Merge pull request #2 from pipcet/data-offset, Chris Feng, 2015/09/17
- [elpa] externals/xelb 4621160 30/42: Move generated libraries to lib/, Chris Feng, 2015/09/17
- [elpa] externals/xelb 846f4c0 33/42: Fix race conditions,
Chris Feng <=
- [elpa] externals/xelb 81c699f 37/42: Protect process-send-string, Chris Feng, 2015/09/17
- [elpa] externals/xelb 41cca58 35/42: Fix compiling issues, Chris Feng, 2015/09/17
- [elpa] externals/xelb 8215991 39/42: Add a missing function key, Chris Feng, 2015/09/17
- [elpa] externals/xelb f5a7ca9 42/42: Minor fix, Chris Feng, 2015/09/17
- [elpa] externals/xelb ae7da13 40/42: Add support for XF86 keysyms, Chris Feng, 2015/09/17
- [elpa] externals/xelb b8f3029 36/42: Flatten directory structure, Chris Feng, 2015/09/17
- [elpa] externals/xelb 5a74daa 32/42: Generate implicit paddings at compile time, Chris Feng, 2015/09/17
- [elpa] externals/xelb 9a0612c 41/42: Fix remaining compile warnings, Chris Feng, 2015/09/17
- [elpa] externals/xelb 2edbaa0 38/42: Code cleanups, Chris Feng, 2015/09/17
- [elpa] externals/xelb c99266a 31/42: Merge xelb-util into this repo, Chris Feng, 2015/09/17