This repository was archived by the owner on Nov 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscheduler.lua
More file actions
53 lines (46 loc) · 1.48 KB
/
scheduler.lua
File metadata and controls
53 lines (46 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
-- Submodule for the scheduling of processes in a distributed node.
module('concurrent._distributed._scheduler', package.seeall)
require 'socket'
require 'copas'
require 'cltime'
-- The existing versions of these functions for then schedulers operation are
-- renamed.
_step = concurrent.step
_tick = concurrent.tick
_loop = concurrent.loop
-- In addition to the operations performed for local processes, the mailbox of
-- the node itself is checked and any handlers are called to take care of the
-- messages.
function step(timeout)
if #concurrent._message.mailboxes[-1] > 0 then
concurrent._distributed._network.controller()
end
return _step(timeout)
end
-- Instead of calling the system's old tick function, one that also considers
-- networking is called.
function tick()
copas.step(concurrent.getoption('tick') / 1000)
end
-- Infinite or finite loop for the scheduler of a node in distributed mode.
function loop(timeout)
if not concurrent.node() then
return _loop(timeout)
end
if timeout then
local timer = cltime.time() + timeout
while step(timeout) and concurrent.node() and
not concurrent._scheduler.stop and timer > cltime.time() do
tick()
end
else
while step(timeout) and concurrent.node() and
not concurrent._scheduler.stop do
tick()
end
end
concurrent._scheduler.stop = false
end
concurrent.step = step
concurrent.tick = tick
concurrent.loop = loop