Skip to content

Commit 832e2b8

Browse files
authored
Merge pull request #512 from mosullivan93/threadsafety
Use thread-safe conditions for connection pool
2 parents 37f6f8b + 7697a72 commit 832e2b8

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/connection.jl

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ are automatically removed from the pool.
2020
struct ConnectionPool
2121
outbox::Channel
2222
connections::Set{AbstractConnection}
23-
condition::Condition
23+
condition::Threads.Condition
2424
end
2525

2626
function ConnectionPool(
@@ -30,7 +30,7 @@ function ConnectionPool(
3030
pool = ConnectionPool(
3131
outbox,
3232
connections,
33-
Condition(),
33+
Threads.Condition(),
3434
)
3535

3636
# Catch errors here, otherwise they are lost to the void.
@@ -68,12 +68,24 @@ current task until that is the case. Also processes incoming connections.
6868
"""
6969
function ensure_connection(pool::ConnectionPool)
7070
if isempty(pool.connections)
71-
wait(pool.condition)
71+
lock(pool.condition)
72+
try
73+
wait(pool.condition)
74+
finally
75+
unlock(pool.condition)
76+
end
7277
end
7378
end
7479

7580
Base.wait(pool::ConnectionPool) = ensure_connection(pool)
76-
Base.notify(pool::ConnectionPool) = notify(pool.condition)
81+
function Base.notify(pool::ConnectionPool)
82+
lock(pool.condition)
83+
try
84+
notify(pool.condition)
85+
finally
86+
unlock(pool.condition)
87+
end
88+
end
7789

7890
"""
7991
process_messages(pool)

test/blink-tests.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ using Blink
33
using Observables
44
using Test
55

6-
notinstalled = !AtomShell.isinstalled()
7-
8-
notinstalled && AtomShell.install()
9-
106
"""
117
Execute function f() with a timeout of `timeout` seconds. Returns the
128
result of f() or `nothing` in the case of a timeout.
@@ -146,5 +142,3 @@ w = open_window()
146142
body!(w, ExampleRenderableType())
147143
@test example_renderable_was_rendered
148144
end
149-
150-
notinstalled && AtomShell.uninstall()

0 commit comments

Comments
 (0)