~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/pagespeed/kernel/thread/queued_worker.h

  • Committer: Vivian
  • Date: 2015-12-04 18:20:11 UTC
  • Revision ID: git-v1:a36f2bc32e884f7473b3a47040e5411306144d7d
* Do not extract psol.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2011 Google Inc.
3
 
 *
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
7
 
 *
8
 
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 
 *
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.
15
 
 */
16
 
 
17
 
// Author: morlovich@google.com (Maksim Orlovich)
18
 
//
19
 
// This contains QueuedWorker, which runs tasks in a background thread
20
 
// in FIFO order.
21
 
 
22
 
#ifndef PAGESPEED_KERNEL_THREAD_QUEUED_WORKER_H_
23
 
#define PAGESPEED_KERNEL_THREAD_QUEUED_WORKER_H_
24
 
 
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"
29
 
 
30
 
namespace net_instaweb {
31
 
 
32
 
class Function;
33
 
 
34
 
// See file comment.
35
 
class QueuedWorker : public Worker {
36
 
 public:
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);
40
 
 
41
 
  // This waits for the running task to terminate.
42
 
  virtual ~QueuedWorker();
43
 
 
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
46
 
  // down.
47
 
  //
48
 
  // Takes ownership of the closure.
49
 
  void RunInWorkThread(Function* closure);
50
 
 
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);
55
 
 
56
 
 private:
57
 
  virtual bool IsPermitted(Function* closure);
58
 
 
59
 
  DISALLOW_COPY_AND_ASSIGN(QueuedWorker);
60
 
};
61
 
 
62
 
}  // namespace net_instaweb
63
 
 
64
 
#endif  // PAGESPEED_KERNEL_THREAD_QUEUED_WORKER_H_