~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/pagespeed/kernel/base/condvar.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
 
// Copyright 2011 Google Inc.
2
 
//
3
 
// Licensed under the Apache License, Version 2.0 (the "License");
4
 
// you may not use this file except in compliance with the License.
5
 
// You may obtain a copy of the License at
6
 
//
7
 
//      http://www.apache.org/licenses/LICENSE-2.0
8
 
//
9
 
// Unless required by applicable law or agreed to in writing, software
10
 
// distributed under the License is distributed on an "AS IS" BASIS,
11
 
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
 
// See the License for the specific language governing permissions and
13
 
// limitations under the License.
14
 
//
15
 
// Author: jmaessen@google.com (Jan Maessen)
16
 
 
17
 
#ifndef PAGESPEED_KERNEL_BASE_CONDVAR_H_
18
 
#define PAGESPEED_KERNEL_BASE_CONDVAR_H_
19
 
 
20
 
#include "pagespeed/kernel/base/basictypes.h"
21
 
#include "pagespeed/kernel/base/thread_system.h"
22
 
 
23
 
namespace net_instaweb {
24
 
 
25
 
// Abstract interface for implementing a condition variable layered on top of a
26
 
// given mutex type, which ought to extend CondvarCapableMutex.
27
 
class ThreadSystem::Condvar {
28
 
 public:
29
 
  Condvar() { }
30
 
  virtual ~Condvar();
31
 
 
32
 
  // Return the mutex associated with this condition variable.
33
 
  virtual CondvarCapableMutex* mutex() const = 0;
34
 
 
35
 
  // Signal the condvar, waking a waiting thread if any.  mutex() must be held
36
 
  // by caller.  Example:
37
 
  // {
38
 
  //   ScopedMutex lock(cv.mutex());
39
 
  //   make_resource_available();
40
 
  //   cv.Signal();
41
 
  // }
42
 
  virtual void Signal() = 0;
43
 
 
44
 
  // Broadcast to all threads waiting on condvar.  mutex() must be held as with
45
 
  // Signal().
46
 
  virtual void Broadcast() = 0;
47
 
 
48
 
  // Wait for condition to be signaled.  mutex() must be held; it will
49
 
  // be released and then reclaimed when a signal is received.  Note
50
 
  // that a Wait() may be terminated based on a condition being true,
51
 
  // but the condition may no longer be true at the time the thread
52
 
  // wakes up.  Example:
53
 
  // {
54
 
  //   ScopedMutex lock(cv.mutex());
55
 
  //   while (status && !resource_available()) status = cv.wait();
56
 
  //   if (status) {
57
 
  //     use_resource();
58
 
  //   }
59
 
  // }
60
 
  virtual void Wait() = 0;
61
 
 
62
 
  // Wait for condition to be signaled, or timeout to occur.  Works like Wait(),
63
 
  // and cv.mutex() must be held on entry and re-taken on exit.
64
 
  virtual void TimedWait(int64 timeout_ms) = 0;
65
 
 
66
 
 private:
67
 
  DISALLOW_COPY_AND_ASSIGN(Condvar);
68
 
};
69
 
 
70
 
}  // namespace net_instaweb
71
 
 
72
 
#endif  // PAGESPEED_KERNEL_BASE_CONDVAR_H_