Skip to content

Commit

Permalink
add n_avail/capacity(RemoteRef{Channel}) + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alyst committed Aug 26, 2015
1 parent 7056337 commit b79fa22
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
18 changes: 9 additions & 9 deletions base/multi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -514,15 +514,6 @@ function lookup_ref(pg, id, f)
rv
end

function isready(rr::RemoteRef, args...)
rid = rr2id(rr)
if rr.where == myid()
isready(lookup_ref(rid).c, args...)
else
remotecall_fetch(rr.where, id->isready(lookup_ref(rid).c, args...), rid)
end
end

del_client(id, client) = del_client(PGRP, id, client)
function del_client(pg, id, client)
rv = lookup_ref(id)
Expand Down Expand Up @@ -774,6 +765,15 @@ function call_on_owner(f, rr::RemoteRef, args...)
end
end

for f in (:isready, :n_avail, :capacity)
f_ref = symbol(string(f, "_ref"))
@eval begin
($f)(rv::RemoteValue, args...) = ($f)(rv.c, args...)
($f_ref)(rid, args...) = ($f)(lookup_ref(rid).c, args...)
($f)(rr::RemoteRef, args...) = call_on_owner(($f_ref), rr, args...)
end
end

wait_ref(rid, args...) = (wait(lookup_ref(rid).c, args...); nothing)
wait(r::RemoteRef, args...) = (call_on_owner(wait_ref, r, args...); r)

Expand Down
16 changes: 16 additions & 0 deletions test/parallel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,33 @@ id_other = filter(x -> x != id_me, procs())[rand(1:(nprocs()-1))]

rr=RemoteRef()
@test typeof(rr) == RemoteRef{Channel{Any}}
@test !isready(rr)
@test Base.n_avail(rr) == 0
@test Base.capacity(rr) > 0
a = rand(5,5)
put!(rr, a)
@test isready(rr)
@test Base.n_avail(rr) == 1
@test rr[2,3] == a[2,3]
@test rr[] == a
take!(rr)
@test !isready(rr)
@test Base.n_avail(rr) == 0

rr=RemoteRef(workers()[1])
@test typeof(rr) == RemoteRef{Channel{Any}}
@test !isready(rr)
@test Base.n_avail(rr) == 0
@test Base.capacity(rr) > 0
a = rand(5,5)
put!(rr, a)
@test isready(rr)
@test Base.n_avail(rr) == 1
@test rr[1,5] == a[1,5]
@test rr[] == a
take!(rr)
@test !isready(rr)
@test Base.n_avail(rr) == 0

dims = (20,20,20)

Expand Down

0 comments on commit b79fa22

Please sign in to comment.