Skip to content

Commit 209612d

Browse files
committed
Minor code cleanup
1 parent 34de931 commit 209612d

3 files changed

Lines changed: 13 additions & 29 deletions

File tree

src/cluster.jl

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -826,24 +826,19 @@ function cluster_cookie(cookie)
826826
cookie
827827
end
828828

829-
830-
let next_pid = 2 # 1 is reserved for the client (always)
831-
global get_next_pid
832-
function get_next_pid()
833-
retval = next_pid
834-
next_pid += 1
835-
retval
836-
end
837-
end
829+
# 1 is reserved for the client (always)
830+
const next_pid = Threads.Atomic{Int}(2)
831+
# Note that atomic_add!() returns the old value, which is what we want
832+
get_next_pid() = Threads.atomic_add!(next_pid, 1)
838833

839834
mutable struct ProcessGroup
840835
name::String
841-
workers::Array{Any,1}
836+
workers::Vector{Union{Worker, LocalProcess}}
842837
refs::Dict{RRID,Any} # global references
843838
topology::Symbol
844839
lazy::Union{Bool, Nothing}
845840

846-
ProcessGroup(w::Array{Any,1}) = new("pg-default", w, Dict(), :all_to_all, nothing)
841+
ProcessGroup(w::Vector) = new("pg-default", w, Dict(), :all_to_all, nothing)
847842
end
848843
const PGRP = ProcessGroup([])
849844

src/macros.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3-
let nextidx = Threads.Atomic{Int}(0)
4-
global nextproc
5-
function nextproc()
6-
idx = Threads.atomic_add!(nextidx, 1)
7-
return workers()[(idx % nworkers()) + 1]
8-
end
3+
const nextidx = Threads.Atomic{Int}(0)
4+
function nextproc()
5+
idx = Threads.atomic_add!(nextidx, 1)
6+
return workers()[(idx % nworkers()) + 1]
97
end
108

119
spawnat(p, thunk) = remotecall(thunk, p)

src/managers.jl

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -414,18 +414,9 @@ function manage(manager::SSHManager, id::Integer, config::WorkerConfig, op::Symb
414414
end
415415
end
416416

417-
let tunnel_port = 9201
418-
global next_tunnel_port
419-
function next_tunnel_port()
420-
retval = tunnel_port
421-
if tunnel_port > 32000
422-
tunnel_port = 9201
423-
else
424-
tunnel_port += 1
425-
end
426-
retval
427-
end
428-
end
417+
const tunnel_counter = Threads.Atomic{Int}(1)
418+
# This is defined such that the port numbers start at 9201 and wrap around at 32,000
419+
next_tunnel_port() = (Threads.atomic_add!(tunnel_counter, 1) % 22_800) + 9200
429420

430421

431422
"""

0 commit comments

Comments
 (0)