Click
Loading...
Searching...
No Matches
idletask.hh
1// -*- c-basic-offset: 4 -*-
2#ifndef CLICK_IDLETASK_HH
3#define CLICK_IDLETASK_HH
4#include <click/element.hh>
5#include <click/router.hh>
6#include <click/master.hh>
7#include <click/sync.hh>
8#if HAVE_MULTITHREAD
9# include <click/atomic.hh>
10# include <click/ewma.hh>
11#endif
12CLICK_DECLS
13
14class IdleTask {
15 Element* _e;
16 IdleTask* _next;
17 bool _active = true;
18 Timestamp _due;
19 int _min_interval;
20
21
22public:
23
24 IdleTask(Element* e) : _e(e), _next(0), _active(false), _due(0),_min_interval(0) {
25 }
26
27 inline bool is_due(Timestamp& now) {
28 return likely(_active && (!_min_interval || now >= _due));
29
30 }
31
32 inline bool fire(Timestamp& now) {
33 if (_min_interval)
34 _due = now + Timestamp::make_msec(_min_interval);
35 return _e->run_idle_task(this);
36 }
37
38 void initialize(Element *owner, int tid, int min_msec = 0)
39 {
40 Router *router = owner->router();
41 RouterThread *thread = router->master()->thread(tid);
42 _min_interval = min_msec;
43 _active = true;
44 _next = thread->_idletask;
45 thread->_idletask = this;
46 thread->_idle_dorun = 0;
47 thread->wake();
48 }
49
50 friend class RouterThread;
51};
52
53CLICK_ENDDECLS
54#endif
An atomic 32-bit integer.
Base class for Click elements.
Definition element.hh:42
Router * router() const
Return the element's router.
Definition element.hh:515
A router configuration.
Definition router.hh:28
Master * master() const
Return the Master object for this router.
Definition router.hh:591
A set of Tasks scheduled on the same CPU.
Definition routerthread.hh:32
Represents a moment or interval in time.
Definition timestamp.hh:125
static Timestamp make_msec(seconds_type sec, uint32_t msec)
Return a timestamp representing sec seconds plus msec milliseconds.
Definition timestamp.hh:332
Click's Element class.
Click's classes for supporting exponentially weighted moving averages.
The Router class implementing a router configuration.
Classes for synchronizing among multiple CPUs, particularly in the Linux kernel.