Skip to content

Commit

Permalink
try once more to use atomic variables
Browse files Browse the repository at this point in the history
  • Loading branch information
rfourquet committed Sep 7, 2017
1 parent 74b8bb1 commit f31aac5
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions base/repl/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ complete_line(c::EmptyCompletionProvider, s) = [], true, true
terminal(s::IO) = s
terminal(s::PromptState) = s.terminal

# NOTE: this would better be Threads.Atomic(0.0), but not supported on some platforms
const beeping = Ref(0.0)
const beeping = Threads.Atomic{Float64}(0.0)

# these may be better stored in Prompt or PromptState
const BEEP_DURATION = Ref(0.2)
Expand All @@ -131,7 +130,8 @@ function beep(s::PromptState, duration::Real=BEEP_DURATION[], blink::Real=BEEP_B
maxduration::Real=BEEP_MAXDURATION[];
colors=BEEP_COLORS, use_current::Bool=BEEP_USE_CURRENT[])
isinteractive() || return # some tests fail on some platforms
beeping[] = min(beeping[] + duration, maxduration)
Threads.atomic_add!(beeping, duration)
Threads.atomic_min!(beeping, maxduration)
@async begin
trylock(BEEP_LOCK) || return
orig_prefix = s.p.prompt_prefix
Expand All @@ -143,19 +143,19 @@ function beep(s::PromptState, duration::Real=BEEP_DURATION[], blink::Real=BEEP_B
s.p.prompt_prefix = prefix
refresh_multi_line(s)
sleep(blink)
beeping[] -= blink
Threads.atomic_sub!(beeping, blink)
end
s.p.prompt_prefix = orig_prefix
refresh_multi_line(s)
beeping[] = 0.0
Threads.atomic_xchg!(beeping, 0.0)
unlock(BEEP_LOCK)
end
end

function cancel_beep(s::PromptState)
# wait till beeping finishes
while !trylock(BEEP_LOCK)
beeping[] = 0.0
Threads.atomic_xchg!(beeping, 0.0)
sleep(.05)
end
unlock(BEEP_LOCK)
Expand Down

0 comments on commit f31aac5

Please sign in to comment.