-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuf_professor.h
More file actions
44 lines (36 loc) · 1.41 KB
/
Copy pathuf_professor.h
File metadata and controls
44 lines (36 loc) · 1.41 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
// uf_professor.h - "spawner" module that pushes assignment Messages into the
// shared mailbox at random intervals, then ends after its preset list drains.
// After each push it wakes the student if the student parked.
//
// CURRENT API: a module is a uniflow::Uniflow<Flow_X> that owns one or more
// Task structs (each a uniflow::Task<Flow_X>). Declarations only live here;
// every definition - including the step bodies - is in the .cpp.
#pragma once
#include "globals.h"
#include "uniflow.hpp"
#include <random>
#include <vector>
class Flow_Professor : public uniflow::Uniflow<Flow_Professor>
{
public:
explicit Flow_Professor(uniflow::Runtime& rt);
int Emitted() const { return emitted_; }
int Total() const { return static_cast<int>(tasks_.size()); }
const std::vector<Message>& Tasks() const { return tasks_; }
// The single emitting task. Public so App::Start() launches it with
// task_emit_.StartFlow().
struct Task_Emit : uniflow::Task<Flow_Professor>
{
StepResult Entry() override { return Step1_Arm(); }
private:
StepResult Step1_Arm(); // schedule the first emission
StepResult Step2_Tick(); // poll the gap; emit when due; Done when drained
} task_emit_;
private:
void ScheduleNext();
void EmitOne();
std::vector<Message> tasks_;
int emitted_ = 0;
uniflow::TimePoint next_at_;
std::mt19937 rng_;
};