Skip to content

Commit 25a759c

Browse files
committed
1 parent 1423d96 commit 25a759c

8 files changed

Lines changed: 20 additions & 20 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ run(sim, datetime+Month(3))
7575
```
7676
- using a novel finite-statemachine approach:
7777
```
78-
@stateful function fibonnaci(sim::Simulation)
78+
@resumable function fibonnaci(sim::Simulation)
7979
a = 0.0
8080
b = 1.0
8181
while true

src/SimJulia.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module SimJulia
2424
export nowDatetime
2525
export Process, @process
2626
export yield, interrupt
27-
export FiniteStateMachine, @stateful, @yield
27+
export FiniteStateMachine, @resumable, @yield
2828
export Coroutine, @coroutine
2929
export Container, Resource, Store
3030
export Put, Get, Request, Release, cancel, capacity, request, @request

src/finitestatemachines/macros.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ abstract type FiniteStateMachine end
66

77
iscoroutinedone(fsm::FiniteStateMachine) = fsm._state == 0xff
88

9-
macro stateful(expr::Expr)
9+
macro resumable(expr::Expr)
1010
expr.head != :function && error("Expression is not a function definition!")
1111
args = getArguments(expr)
1212
func_name = shift!(args)

test/benchmarks/coroutines_MM1.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
using SimJulia, Distributions, BenchmarkTools
22

3-
@stateful function exp_source(sim::Simulation, lambd::Float64, server::Resource, mu::Float64)
3+
@resumable function exp_source(sim::Simulation, lambd::Float64, server::Resource, mu::Float64)
44
while true
55
dt = rand(Exponential(1/lambd))
66
@yield return Timeout(sim, dt)
77
@coroutine customer2(sim, server, mu)
88
end
99
end
1010

11-
@stateful function customer(sim::Simulation, server::Resource, mu::Float64)
11+
@resumable function customer(sim::Simulation, server::Resource, mu::Float64)
1212
@yield return Request(server)
1313
dt = rand(Exponential(1/mu))
1414
@yield return Timeout(sim, dt)
1515
@yield return Release(server)
1616
end
1717

18-
@stateful function customer2(sim::Simulation, server::Resource, mu::Float64)
18+
@resumable function customer2(sim::Simulation, server::Resource, mu::Float64)
1919
@request server req begin
2020
dt = rand(Exponential(1/mu))
2121
@yield return Timeout(sim, dt)

test/benchmarks/coroutines_fibonnaci.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using SimJulia, BenchmarkTools
22

3-
@stateful function fibonnaci(sim::Simulation)
3+
@resumable function fibonnaci(sim::Simulation)
44
a = 0.0
55
b = 1.0
66
while true

test/containers.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using SimJulia
22

3-
@stateful function client(sim::Simulation, res::Resource, i::Int, priority::Int)
3+
@resumable function client(sim::Simulation, res::Resource, i::Int, priority::Int)
44
println("$(now(sim)), client $i is waiting")
55
@yield return Request(res, priority=priority)
66
println("$(now(sim)), client $i is being served")
@@ -9,7 +9,7 @@ using SimJulia
99
@yield return Release(res)
1010
end
1111

12-
@stateful function generate(sim::Simulation, res::Resource)
12+
@resumable function generate(sim::Simulation, res::Resource)
1313
i = 1
1414
while true
1515
@coroutine client(sim, res, i, 10-i)
@@ -24,7 +24,7 @@ res = Resource(sim, 2; level=1)
2424
@coroutine generate(sim, res)
2525
run(sim)
2626

27-
@stateful function my_consumer(sim::Simulation, con::Container)
27+
@resumable function my_consumer(sim::Simulation, con::Container)
2828
i = 1
2929
while true
3030
amount = 3*rand()
@@ -45,7 +45,7 @@ run(sim)
4545
end
4646
end
4747

48-
@stateful function my_producer(sim::Simulation, con::Container)
48+
@resumable function my_producer(sim::Simulation, con::Container)
4949
i = 1
5050
while true
5151
amount = 2*rand()
@@ -66,7 +66,7 @@ con = Container(sim, 10.0; level=5.0)
6666
@coroutine my_producer(sim, con)
6767
run(sim)
6868

69-
@stateful function resource_user(sim::Simulation, res::Resource, i::Int)
69+
@resumable function resource_user(sim::Simulation, res::Resource, i::Int)
7070
@request res req begin
7171
println("Requested $i")
7272
val = @yield return req | Timeout(sim, rand())
@@ -80,7 +80,7 @@ run(sim)
8080
println("Released automatically $i")
8181
end
8282

83-
@stateful function create_users(sim::Simulation)
83+
@resumable function create_users(sim::Simulation)
8484
res = Resource(sim)
8585
i = 1
8686
while true

test/coroutines.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using SimJulia
22

3-
@stateful function fibonnaci(sim::Simulation)
3+
@resumable function fibonnaci(sim::Simulation)
44
a = 0
55
b = 1
66
while true
@@ -10,24 +10,24 @@ using SimJulia
1010
end
1111
end
1212

13-
@stateful function test_process(sim::Simulation, ev::AbstractEvent)
13+
@resumable function test_process(sim::Simulation, ev::AbstractEvent)
1414
@yield return ev
1515
end
1616

17-
@stateful function test_process_exception(sim::Simulation, ev::AbstractEvent)
17+
@resumable function test_process_exception(sim::Simulation, ev::AbstractEvent)
1818
try
1919
value = @yield return ev
2020
catch
2121
println("$value has been thrown")
2222
end
2323
end
2424

25-
@stateful function test_interrupter(sim::Simulation, proc::Coroutine)
25+
@resumable function test_interrupter(sim::Simulation, proc::Coroutine)
2626
@yield return Timeout(sim, 2)
2727
interrupt(proc)
2828
end
2929

30-
@stateful function test_interrupted(sim::Simulation)
30+
@resumable function test_interrupted(sim::Simulation)
3131
try
3232
exc = @yield return Timeout(sim, 10)
3333
catch

test/stores.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ struct StoreObject
44
i :: Int
55
end
66

7-
@stateful function my_consumer(sim::Simulation, sto::Store)
7+
@resumable function my_consumer(sim::Simulation, sto::Store)
88
i = 1
99
while true
1010
@yield return Timeout(sim, rand())
@@ -16,7 +16,7 @@ end
1616
end
1717
end
1818

19-
@stateful function my_producer(sim::Simulation, sto::Store)
19+
@resumable function my_producer(sim::Simulation, sto::Store)
2020
i = 1
2121
while true
2222
println("$(now(sim)), producer is offering object $i")

0 commit comments

Comments
 (0)