Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REPL: add lock to orchestrate adding repl modes etc. #54890

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions stdlib/REPL/src/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2845,12 +2845,14 @@ keymap_data(s::PromptState, prompt::Prompt) = prompt.repl
keymap(ms::MIState, m::ModalInterface) = keymap(state(ms), mode(ms))
keymap_data(ms::MIState, m::ModalInterface) = keymap_data(state(ms), mode(ms))

# should be locked when adding/editing a repl mode etc.
const repl_mutate_lock = Base.ReentrantLock()

function prompt!(term::TextTerminal, prompt::ModalInterface, s::MIState = init_state(term, prompt))
Base.reseteof(term)
l = Base.ReentrantLock()
t1 = Threads.@spawn :interactive while true
wait(s.async_channel)
status = @lock l begin
status = @lock repl_mutate_lock begin
fcn = take!(s.async_channel)
fcn(s)
end
Expand All @@ -2865,7 +2867,7 @@ function prompt!(term::TextTerminal, prompt::ModalInterface, s::MIState = init_s
# and we want to not block typing when the repl task thread is busy
t2 = Threads.@spawn :interactive while true
eof(term) || peek(term) # wait before locking but don't consume
@lock l begin
@lock repl_mutate_lock begin
kmap = keymap(s, prompt)
fcn = match_input(kmap, s)
kdata = keymap_data(s, prompt)
Expand Down