[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode fff6affe6f 1/5: Race-condition seems to be re
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode fff6affe6f 1/5: Race-condition seems to be resolved now but cache is disabled |
Date: |
Fri, 18 Mar 2022 15:47:04 -0400 (EDT) |
branch: externals/phps-mode
commit fff6affe6fc81f5cbc096802339941b472ec9199
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Race-condition seems to be resolved now but cache is disabled
---
phps-mode-lex-analyzer.el | 80 +++++++++++++++++++++++++++++------------------
phps-mode-serial.el | 1 +
2 files changed, 51 insertions(+), 30 deletions(-)
diff --git a/phps-mode-lex-analyzer.el b/phps-mode-lex-analyzer.el
index b10b77fa93..c999cd1b81 100644
--- a/phps-mode-lex-analyzer.el
+++ b/phps-mode-lex-analyzer.el
@@ -91,6 +91,9 @@
(defvar-local phps-mode-lex-analyzer--lexer-max-index nil
"Max-index of lex-analyzer.")
+(defvar phps-mode-lex-analyzer--use-cache-p nil
+ "Whether to use cache or not.")
+
;; FUNCTIONS
@@ -114,10 +117,12 @@
(setq phps-mode-lex-analyzer--states nil)
(setq phps-mode-lex-analyzer--tokens nil)
(when clear-existing
- (phps-mode-serial--kill-active (buffer-name))
- (when buffer-file-name
- (phps-mode-cache-delete buffer-file-name)))
- )
+ (phps-mode-serial--kill-active
+ (buffer-name))
+ (when (and
+ buffer-file-name
+ phps-mode-lex-analyzer--use-cache-p)
+ (phps-mode-cache-delete buffer-file-name))))
(defun phps-mode-lex-analyzer--set-region-syntax-color (start end properties)
"Do syntax coloring for region START to END with PROPERTIES."
@@ -213,6 +218,8 @@
(when force-synchronous
(setq async nil))
+ (message "Starting new serial-command 1: %S" buffer-name)
+
(phps-mode-serial-commands
buffer-name
@@ -234,6 +241,8 @@
(when (get-buffer buffer-name)
(with-current-buffer buffer-name
+ (message "%S Serial command 1 step 2 start: %S" (current-thread)
buffer-name)
+
;; Move variables into this buffers local variables
(setq phps-mode-lex-analyzer--tokens (nth 0 lex-result))
(setq phps-mode-lex-analyzer--states (nth 1 lex-result))
@@ -249,8 +258,6 @@
(setq phps-mode-lex-analyzer--bookkeeping (nth 11 lex-result))
(setq phps-mode-lex-analyzer--processed-buffer-p t)
(phps-mode-lex-analyzer--reset-imenu)
- (when (fboundp 'thread-yield)
- (thread-yield))
;; Apply syntax color on tokens
(dolist (token phps-mode-lex-analyzer--tokens)
@@ -263,6 +270,11 @@
(phps-mode-lex-analyzer--clear-region-syntax-color
start end)))))
+ ;; Reset buffer changes minimum index
+ (phps-mode-lex-analyzer--reset-changes)
+
+ (message "%S Serial command 1 step 2 end: %S" (current-thread)
buffer-name)
+
;; Signal parser error (if any)
(when phps-mode-lex-analyzer--parse-error
@@ -343,6 +355,9 @@
phps-mode-async-process-using-async-el)))
(when force-synchronous
(setq async nil))
+
+ (message "Starting new serial-command 2: %S" buffer-name)
+
(phps-mode-serial-commands
buffer-name
@@ -365,6 +380,8 @@
(when (get-buffer buffer-name)
(with-current-buffer buffer-name
+ (message "%S Serial command 2 step 2 start: %S" (current-thread)
buffer-name)
+
(phps-mode-debug-message
(message "Incrementally-lexed-string: %s" result))
@@ -387,8 +404,6 @@
;; Save processed result
(setq phps-mode-lex-analyzer--processed-buffer-p t)
(phps-mode-lex-analyzer--reset-imenu)
- (when (fboundp 'thread-yield)
- (thread-yield))
;; Apply syntax color on tokens
(dolist (token phps-mode-lex-analyzer--tokens)
@@ -401,6 +416,11 @@
(phps-mode-lex-analyzer--set-region-syntax-color start
end (list 'font-lock-face token-syntax-color))
(phps-mode-lex-analyzer--clear-region-syntax-color start
end)))))
+ ;; Reset buffer changes minimum index
+ (phps-mode-lex-analyzer--reset-changes)
+
+ (message "%S Serial command 2 step 2 end: %S" (current-thread)
buffer-name)
+
;; Signal parser error (if any)
(when phps-mode-lex-analyzer--parse-error
@@ -521,7 +541,12 @@
(defun phps-mode-lex-analyzer--move-tokens (start diff)
"Update tokens with moved lexer tokens after or equal to START with
modification DIFF."
(when phps-mode-lex-analyzer--tokens
- (setq phps-mode-lex-analyzer--tokens
(phps-mode-lex-analyzer--get-moved-tokens phps-mode-lex-analyzer--tokens start
diff))))
+ (setq
+ phps-mode-lex-analyzer--tokens
+ (phps-mode-lex-analyzer--get-moved-tokens
+ phps-mode-lex-analyzer--tokens
+ start
+ diff))))
(defun phps-mode-lex-analyzer--get-moved-tokens (old-tokens start diff)
"Return moved lexer OLD-TOKENS positions after (or equal to) START with DIFF
points."
@@ -579,23 +604,6 @@
;; Reset idle timer
(phps-mode-lex-analyzer--cancel-idle-timer)
- ;; Reset buffer changes minimum index
- (phps-mode-lex-analyzer--reset-changes)
-
- ;; Reset tokens and states here
- (setq phps-mode-lex-analyzer--tokens nil)
- (setq phps-mode-lex-analyzer--states nil)
- (setq phps-mode-lex-analyzer--state nil)
- (setq phps-mode-lex-analyzer--state-stack nil)
- (setq phps-mode-lex-analyzer--heredoc-label nil)
- (setq phps-mode-lex-analyzer--heredoc-label-stack nil)
- (setq phps-mode-lex-analyzer--nest-location-stack nil)
- (setq phps-mode-lex-analyzer--parse-trail nil)
- (setq phps-mode-lex-analyzer--parse-error nil)
- (setq phps-mode-lex-analyzer--ast nil)
- (setq phps-mode-lex-analyzer--imenu nil)
- (setq phps-mode-lex-analyzer--bookkeeping nil)
-
;; NOTE Starts are inclusive while ends are exclusive buffer
locations
;; Some tokens have dynamic length and if a change occurs at
token-end
@@ -822,7 +830,11 @@
(progn
(phps-mode-debug-message
(message "After change registration is enabled"))
+
+ ;; Kill active thread (if any)
(phps-mode-serial--kill-active (buffer-name))
+
+ (message "Killing active thread (if any exists): %S" (buffer-name))
;; If we haven't scheduled incremental lexer before - do it
(when (and (boundp 'phps-mode-idle-interval)
@@ -830,15 +842,19 @@
(not phps-mode-lex-analyzer--idle-timer))
(phps-mode-lex-analyzer--start-idle-timer))
+ ;; When change position is before previous start position - update it
(when (or
(not phps-mode-lex-analyzer--change-min)
(< start phps-mode-lex-analyzer--change-min))
- (setq phps-mode-lex-analyzer--change-min start))
+ (setq
+ phps-mode-lex-analyzer--change-min
+ start))
(when (and
(boundp 'phps-mode-idle-interval)
(not phps-mode-idle-interval))
- (phps-mode-lex-analyzer--process-changes (current-buffer))))
+ (phps-mode-lex-analyzer--process-changes
+ (current-buffer))))
(phps-mode-debug-message
(message "After change registration is disabled"))))
@@ -1084,7 +1100,9 @@
(cache-key))
;; Load cache if possible
- (when filename
+ (when (and
+ filename
+ phps-mode-lex-analyzer--use-cache-p)
(setq
cache-key
filename)
@@ -1214,7 +1232,9 @@
bookkeeping-index)))
;; Save cache if possible
- (when cache-key
+ (when (and
+ cache-key
+ phps-mode-lex-analyzer--use-cache-p)
(phps-mode-cache-save
data
cache-key))
diff --git a/phps-mode-serial.el b/phps-mode-serial.el
index d359694277..1ab4a673d8 100644
--- a/phps-mode-serial.el
+++ b/phps-mode-serial.el
@@ -61,6 +61,7 @@
(when (and
(gethash key phps-mode-serial--async-threads)
(thread-live-p (gethash key phps-mode-serial--async-threads)))
+ (message "Killing thread: %S" (gethash key
phps-mode-serial--async-threads))
(thread-signal (gethash key phps-mode-serial--async-threads) 'quit nil)))
(defun phps-mode-serial-commands (key start end &optional start-error
end-error async async-by-process)