Skip to content

Commit 7167fc6

Browse files
committed
Priorities are now Int8 values.
Int8(0) is neutral, higher values have priority over lower values.
1 parent f3d04f4 commit 7167fc6

5 files changed

Lines changed: 11 additions & 11 deletions

File tree

src/coroutines.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ end
7878
function interrupt(proc::Coroutine, cause::Any=nothing)
7979
if !iscoroutinedone(proc.fsm)
8080
remove_callback(proc.resume, proc.target)
81-
proc.target = Timeout(environment(proc), priority=true, value=InterruptException(proc, cause))
81+
proc.target = Timeout(environment(proc), priority=typemax(Int8), value=InterruptException(proc, cause))
8282
proc.resume = append_callback(execute, proc.target, proc)
8383
end
8484
end

src/events.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function Event{E<:Environment}(env::E)
99
Event{E}(env)
1010
end
1111

12-
function succeed{E<:Environment}(ev::Event{E}; priority::Bool=false, value::Any=nothing) :: Event{E}
12+
function succeed{E<:Environment}(ev::Event{E}; priority::Int8=Int8(0), value::Any=nothing) :: Event{E}
1313
sta = state(ev)
1414
if sta == scheduled || sta == triggered
1515
throw(EventNotIdle(ev))
@@ -18,7 +18,7 @@ function succeed{E<:Environment}(ev::Event{E}; priority::Bool=false, value::Any=
1818
return ev
1919
end
2020

21-
function fail{E<:Environment}(ev::Event{E}, exc::Exception; priority::Bool=false) :: Event{E}
21+
function fail{E<:Environment}(ev::Event{E}, exc::Exception; priority::Int8=Int8(0)) :: Event{E}
2222
succeed(ev, priority=priority, value=exc)
2323
end
2424

@@ -43,17 +43,17 @@ Timeout{E<:Environment} <: AbstractEvent{E}
4343

4444
struct Timeout{E<:Environment} <: AbstractEvent{E}
4545
bev :: BaseEvent{E}
46-
function Timeout{E}(env::E, delay::Union{Period, Number}, priority::Bool, value::Any) where E<:Environment
46+
function Timeout{E}(env::E, delay::Union{Period, Number}, priority::Int8, value::Any) where E<:Environment
4747
ev = new(BaseEvent(env))
4848
schedule(ev.bev, delay, priority=priority, value=value)
4949
return ev
5050
end
5151
end
5252

53-
function Timeout{E<:Environment}(env::E, delay::Period; priority::Bool=false, value::Any=nothing) :: Timeout{E}
53+
function Timeout{E<:Environment}(env::E, delay::Period; priority::Int8=Int8(0), value::Any=nothing) :: Timeout{E}
5454
Timeout{E}(env, delay, priority, value)
5555
end
5656

57-
function Timeout{E<:Environment}(env::E, delay::Number=0; priority::Bool=false, value::Any=nothing) :: Timeout{E}
57+
function Timeout{E<:Environment}(env::E, delay::Number=0; priority::Int8=Int8(0), value::Any=nothing) :: Timeout{E}
5858
Timeout{E}(env, delay, priority, value)
5959
end

src/operators.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function check{E<:Environment}(ev::AbstractEvent{E}, op::Operator{E}, event_stat
3838
end
3939
elseif state(op) == scheduled
4040
if isa(val, Exception)
41-
schedule(op.bev, priority=true, value=val)
41+
schedule(op.bev, priority=typemax(Int8), value=val)
4242
else
4343
event_state_values[ev] = StateValue(state(ev), val)
4444
end

src/processes.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ end
8787
function interrupt(proc::Process, cause::Any=nothing)
8888
if !istaskdone(proc.task)
8989
remove_callback(proc.resume, proc.target)
90-
proc.target = Timeout(environment(proc), priority=true, value=InterruptException(proc, cause))
90+
proc.target = Timeout(environment(proc), priority=typemax(Int8), value=InterruptException(proc, cause))
9191
proc.resume = append_callback(execute, proc.target, proc)
9292
end
9393
end

src/simulation.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
struct EventKey{T<:TimeType}
22
time :: T
3-
priority :: Bool
3+
priority :: Int8
44
id :: UInt
55
end
66

@@ -154,13 +154,13 @@ function run(sim::Simulation) :: Any
154154
run(sim, typemax(sim.time)-sim.time)
155155
end
156156

157-
function schedule{T<:TimeType}(bev::BaseEvent{Simulation{T}}, delay::Period; priority::Bool=false, value::Any=nothing)
157+
function schedule{T<:TimeType}(bev::BaseEvent{Simulation{T}}, delay::Period; priority::Int8=Int8(0), value::Any=nothing)
158158
bev.value = value
159159
bev.env.heap[bev] = EventKey{T}(bev.env.time + delay, priority, bev.env.sid+=one(UInt))
160160
bev.state = scheduled
161161
end
162162

163-
function schedule{T<:TimeType}(bev::BaseEvent{Simulation{T}}, delay::Number=0; priority::Bool=false, value::Any=nothing)
163+
function schedule{T<:TimeType}(bev::BaseEvent{Simulation{T}}, delay::Number=0; priority::Int8=Int8(0), value::Any=nothing)
164164
P = typeof(eps(bev.env.time))
165165
schedule(bev, P(delay), priority=priority, value=value)
166166
end

0 commit comments

Comments
 (0)