17 #ifndef PAGESPEED_KERNEL_THREAD_SCHEDULER_H_
18 #define PAGESPEED_KERNEL_THREAD_SCHEDULER_H_
26 #include "pagespeed/kernel/base/thread_annotations.h"
34 #define SCHEDULER_CANCEL_OUTSTANDING_ALARMS_ON_DESTRUCTION 0
36 namespace net_instaweb {
61 bool operator()(
const Alarm* a,
const Alarm* b)
const;
73 mutex_->DCheckLocked();
82 BlockingTimedWaitUs(timeout_ms * Timer::kMsUs);
84 void BlockingTimedWaitUs(int64 timeout_us) EXCLUSIVE_LOCKS_REQUIRED(mutex());
92 EXCLUSIVE_LOCKS_REQUIRED(mutex());
99 void Signal() EXCLUSIVE_LOCKS_REQUIRED(mutex());
119 LOCKS_EXCLUDED(mutex());
124 EXCLUSIVE_LOCKS_REQUIRED(mutex());
138 bool CancelAlarm(Alarm* alarm) EXCLUSIVE_LOCKS_REQUIRED(mutex());
150 EXCLUSIVE_LOCKS_REQUIRED(mutex());
174 int64
RunAlarms(
bool* ran_alarms) EXCLUSIVE_LOCKS_REQUIRED(mutex());
187 bool running_waiting_alarms()
const {
return running_waiting_alarms_; }
190 class CondVarTimeout;
191 class CondVarCallbackTimeout;
192 friend class SchedulerTest;
194 typedef std::set<Alarm*, CompareAlarms> AlarmSet;
198 void InsertAlarmAtUsMutexHeld(int64 wakeup_time_us,
199 bool broadcast_on_wakeup_change,
201 void CancelWaiting(Alarm* alarm);
202 bool NoPendingAlarms();
204 ThreadSystem* thread_system_;
206 scoped_ptr<ThreadSystem::CondvarCapableMutex> mutex_;
209 scoped_ptr<ThreadSystem::Condvar> condvar_;
211 AlarmSet outstanding_alarms_;
215 AlarmSet waiting_alarms_;
216 bool running_waiting_alarms_;
Definition: scheduler_sequence.h:33
void DCheckLocked() EXCLUSIVE_LOCKS_REQUIRED(mutex())
Optionally check that mutex is locked for debugging purposes.
Definition: scheduler.h:72
virtual void AwaitWakeupUntilUs(int64 wakeup_time_us)
Timer * timer()
Definition: scheduler.h:154
Alarm * AddAlarmAtUsMutexHeld(int64 wakeup_time_us, Function *callback) EXCLUSIVE_LOCKS_REQUIRED(mutex())
Definition: sequence.h:33
Definition: scheduler.h:60
Definition: scheduler.h:227
Definition: thread_system.h:46
void BlockingTimedWaitMs(int64 timeout_ms) EXCLUSIVE_LOCKS_REQUIRED(mutex())
Wait at most timeout_ms, or until Signal() is called.
Definition: scheduler.h:81
int64 RunAlarms(bool *ran_alarms) EXCLUSIVE_LOCKS_REQUIRED(mutex())
Alarm * AddAlarmAtUs(int64 wakeup_time_us, Function *callback) LOCKS_EXCLUDED(mutex())
Definition: function.h:47
bool CancelAlarm(Alarm *alarm) EXCLUSIVE_LOCKS_REQUIRED(mutex())
Definition: queued_worker_pool.h:65
void Wakeup()
Definition: scheduler.h:162
void TimedWaitMs(int64 timeout_ms, Function *callback) EXCLUSIVE_LOCKS_REQUIRED(mutex())
Definition: thread_system.h:40
void Signal() EXCLUSIVE_LOCKS_REQUIRED(mutex())
Definition: scheduler.h:47
virtual void RegisterWorker(QueuedWorkerPool::Sequence *w)
Timer interface, made virtual so it can be mocked for tests.
Definition: timer.h:27
bool ProcessAlarmsOrWaitUs(int64 timeout_us) EXCLUSIVE_LOCKS_REQUIRED(mutex())
ThreadSystem * thread_system()
Obtain the thread system used by the scheduler.
Definition: scheduler.h:157
bool Block()
Block until called back, returning true for Run and false for Cancel.
Sequence * NewSequence()
Creates a new sequence, controlled by the scheduler.