LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
pollingNext.m
1function [q, mode, budget] = pollingNext(pinfo, pos, nbuf, R, arrived)
2% [Q, MODE, BUDGET] = POLLINGNEXT(PINFO, POS, NBUF, R, ARRIVED)
3%
4% Resolve the tangible controller state a polling server reaches once it stops
5% serving buffer POS. NBUF(r) is the number of class-r jobs waiting in the
6% buffer (the service facility is empty at this point).
7%
8% ARRIVED (default false) selects where the cyclic walk starts. When false the
9% server is LEAVING pos, so the walk starts at pos+1; when true the server has
10% just ARRIVED at pos (a switchover into pos has completed, or the server is
11% parked at pos) and pos itself is examined first, without charging its
12% switchover a second time.
13%
14% MODE = 1 start a visit to buffer q: q has work and is reached in zero time.
15% BUDGET is the initial value of the ctr column for that visit.
16% MODE = 2 enter the switchover into buffer q: a strictly positive timer, so
17% this is where the server dwells. BUDGET is 0 (the visit budget is
18% only set once the server arrives at q).
19% MODE = 0 park at q: the walk completed a full lap without finding work and
20% without meeting a timed switchover, which can only happen when the
21% station is empty and every switchover is immediate. The server
22% would otherwise cycle in zero time forever, so it is held here
23% until the next arrival. q is canonical and unobservable.
24%
25% The walk is what makes an Immediate() switchover a zero-time leg rather than
26% a state: the server passes straight through such a buffer when it has no
27% work, and only stops at a buffer that either has work or costs time to reach.
28% This is the classical cyclic-polling discipline, in which the server visits
29% the buffers in strict cyclic order and pays the switchover of every buffer it
30% moves to, whether or not that buffer turns out to have work.
31
32% Copyright (c) 2012-2026, Imperial College London
33% All rights reserved.
34
35if nargin < 5 || isempty(arrived)
36 arrived = false;
37end
38
39if arrived && pinfo.polled(pos) && nbuf(pos) > 0
40 % the switchover into pos has already been paid, so a visit starts here
41 q = pos; mode = 1; budget = State.pollingBudget(pinfo, nbuf(pos));
42 return
43end
44
45p = pos;
46for step = 1:R % a full lap, so that the last buffer examined is pos itself
47 p = mod(p, R) + 1;
48 if ~pinfo.polled(p)
49 continue
50 end
51 if pinfo.hasSw(p)
52 q = p; mode = 2; budget = 0;
53 return
54 end
55 if nbuf(p) > 0
56 q = p; mode = 1; budget = State.pollingBudget(pinfo, nbuf(p));
57 return
58 end
59end
60
61q = pos; mode = 0; budget = 0;
62end
Definition Station.m:245