1function [q, mode, budget] = pollingNext(pinfo, pos, nbuf, R, arrived)
2% [Q, MODE, BUDGET] = POLLINGNEXT(PINFO, POS, NBUF, R, ARRIVED)
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).
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.
14% MODE = 1 start a visit to buffer q: q has work and
is reached in zero time.
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.
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.
32% Copyright (c) 2012-2026, Imperial College London
35if nargin < 5 || isempty(arrived)
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));
46for step = 1:R % a full lap, so that
the last buffer examined
is pos itself
52 q = p; mode = 2; budget = 0;
56 q = p; mode = 1; budget = State.pollingBudget(pinfo, nbuf(p));
61q = pos; mode = 0; budget = 0;