Skip to content

Commit

Permalink
add navailable/capacity(RemoteRef{Channel}) + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alyst committed Sep 11, 2015
1 parent dfda59b commit 51217c7
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 @@ -517,15 +517,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 @@ -777,6 +768,15 @@ function call_on_owner(f, rr::RemoteRef, args...)
end
end

for f in (:isready, :navailable, :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 navailable(rr) == 0
@test capacity(rr) > 0
a = rand(5,5)
put!(rr, a)
@test isready(rr)
@test navailable(rr) == 1
@test rr[2,3] == a[2,3]
@test rr[] == a
take!(rr)
@test !isready(rr)
@test navailable(rr) == 0

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

dims = (20,20,20)

Expand Down

0 comments on commit 51217c7

Please sign in to comment.