2
* Copyright 2011 Google Inc.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
// Author: morlovich@google.com (Maksim Orlovich)
19
// This contains QueuedWorker, which runs tasks in a background thread
22
#ifndef PAGESPEED_KERNEL_THREAD_QUEUED_WORKER_H_
23
#define PAGESPEED_KERNEL_THREAD_QUEUED_WORKER_H_
25
#include "pagespeed/kernel/base/basictypes.h"
26
#include "pagespeed/kernel/base/string_util.h"
27
#include "pagespeed/kernel/base/thread_system.h"
28
#include "pagespeed/kernel/thread/worker.h"
30
namespace net_instaweb {
35
class QueuedWorker : public Worker {
37
// Initializes the worker. You still need to call ->Start to actually
38
// start the thread, however. (Note: start can return false on failure).
39
QueuedWorker(StringPiece thread_name, ThreadSystem* runtime);
41
// This waits for the running task to terminate.
42
virtual ~QueuedWorker();
44
// Runs the given closure in the work thread. Not that it's possible for the
45
// closure to be deleted without running in case where the system is shutting
48
// Takes ownership of the closure.
49
void RunInWorkThread(Function* closure);
51
// Issue a TimedWait on the specified condition variable. In a mock-time
52
// world, this queues a time-advancement closure on the worker, and then
53
// blocks waiting for the work-queue to be drained.
54
void TimedWait(ThreadSystem::Condvar* condvar, int64 timeout_ms);
57
virtual bool IsPermitted(Function* closure);
59
DISALLOW_COPY_AND_ASSIGN(QueuedWorker);
62
} // namespace net_instaweb
64
#endif // PAGESPEED_KERNEL_THREAD_QUEUED_WORKER_H_