blob: 088cadf17aaed236c6df2bb4c4f7302e0d92766e (
plain) (
blame)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include <cstdint>
class FNET_Scheduler;
/**
* This class represent a task that may be scheduled to be performed
* by an instance of the @ref FNET_Scheduler class.
**/
class FNET_Task
{
friend class FNET_Scheduler;
private:
FNET_Scheduler *_task_scheduler;
uint32_t _task_slot;
uint32_t _task_iter;
FNET_Task *_task_next;
FNET_Task *_task_prev;
bool _killed;
public:
FNET_Task(const FNET_Task &) = delete;
FNET_Task &operator=(const FNET_Task &) = delete;
/**
* Construct a task that may be scheduled by the given scheduler.
*
* @param scheduler the scheduler that will be used to schedule this
* task.
**/
FNET_Task(FNET_Scheduler *scheduler);
virtual ~FNET_Task();
/**
* Schedule this task to be performed in the given amount of
* seconds.
*
* @param seconds the number of seconds until this task
* should be performed.
**/
void Schedule(double seconds);
/**
* Schedule this task to be performed as soon as possible.
**/
void ScheduleNow();
/**
* Unschedule this task. If the scheduler is currently performing
* this task, this method will block until the task is
* completed.
**/
void Unschedule();
/**
* This method does the same as the @ref Unschedule method, but also
* makes sure that this task may not be scheduled in the future.
**/
void Kill();
/**
* This method will be invoked by the scheduler to perform this
* task. Note that since the scheduling is one-shot, it is legal for
* a task to re-schedule itself in this method.
**/
virtual void PerformTask();
};
|