25 #ifndef PAGESPEED_KERNEL_THREAD_QUEUED_WORKER_POOL_H_
26 #define PAGESPEED_KERNEL_THREAD_QUEUED_WORKER_POOL_H_
39 #include "pagespeed/kernel/base/thread_annotations.h"
43 namespace net_instaweb {
52 static const int kNoLoadShedding = -1;
74 : sequence_(sequence), callback_(callback) { }
79 sequence_->
Add(callback_);
103 void Add(
Function*
function) LOCKS_EXCLUDED(sequence_mutex_);
105 void set_queue_size_stat(
Waveform* x) { queue_size_ = x; }
131 void WaitForShutDown() LOCKS_EXCLUDED(sequence_mutex_);
136 bool InitiateShutDown() LOCKS_EXCLUDED(sequence_mutex_);
140 Function* NextFunction() LOCKS_EXCLUDED(sequence_mutex_);
142 bool IsBusy() EXCLUSIVE_LOCKS_REQUIRED(sequence_mutex_);
145 int CancelTasksOnWorkQueue() EXCLUSIVE_LOCKS_REQUIRED(sequence_mutex_);
148 void Cancel() LOCKS_EXCLUDED(sequence_mutex_);
151 std::deque<
Function*> work_queue_ GUARDED_BY(sequence_mutex_);
153 QueuedWorkerPool* pool_;
154 bool shutdown_ GUARDED_BY(sequence_mutex_);
155 bool active_ GUARDED_BY(sequence_mutex_);
157 GUARDED_BY(sequence_mutex_);
159 size_t max_queue_size_;
164 typedef std::set<
Sequence*> SequenceSet;
186 void InitiateShutDown();
206 static
bool AreBusy(const SequenceSet& sequences);
222 void set_queue_size_stat(
Waveform* x) { queue_size_ = x; }
227 void QueueSequence(
Sequence* sequence);
229 void SequenceNoLongerActive(
Sequence* sequence);
235 std::set<QueuedWorker*> active_workers_;
236 std::vector<QueuedWorker*> available_workers_;
240 std::vector<Sequence*> all_sequences_;
241 std::deque<Sequence*> queued_sequences_;
242 std::vector<Sequence*> free_sequences_;
250 int load_shedding_threshold_;
Function * MakeFunction(C *object, void(C::*run)())
Makes a Function* that calls a 0-arg class method.
Definition: function.h:291
void WaitForShutDownComplete()
virtual void Cancel()
Definition: queued_worker_pool.h:81
Definition: sequence.h:33
Sequence * NewSequence()
Returns NULL if shutting down.
Definition: scoped_ptr.h:30
Definition: function.h:47
Definition: queued_worker_pool.h:71
static bool AreBusy(const SequenceSet &sequences)
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
See file comment.
Definition: queued_worker.h:35
Definition: queued_worker_pool.h:50
virtual void Run()
Definition: queued_worker_pool.h:78
virtual void Add(Function *function)=0
Definition: queued_worker_pool.h:65
void set_max_queue_size(size_t x)
Definition: queued_worker_pool.h:110
Definition: thread_system.h:40
void Add(Function *function) LOCKS_EXCLUDED(sequence_mutex_)
void FreeSequence(Sequence *sequence)
void CancelPendingFunctions() LOCKS_EXCLUDED(sequence_mutex_)
Calls Cancel on all pending functions in the queue.
void SetLoadSheddingThreshold(int x)