1
// Copyright 2011 Google Inc.
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
7
// http://www.apache.org/licenses/LICENSE-2.0
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.
15
// Author: jmaessen@google.com (Jan Maessen)
17
#ifndef PAGESPEED_KERNEL_BASE_CONDVAR_H_
18
#define PAGESPEED_KERNEL_BASE_CONDVAR_H_
20
#include "pagespeed/kernel/base/basictypes.h"
21
#include "pagespeed/kernel/base/thread_system.h"
23
namespace net_instaweb {
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 {
32
// Return the mutex associated with this condition variable.
33
virtual CondvarCapableMutex* mutex() const = 0;
35
// Signal the condvar, waking a waiting thread if any. mutex() must be held
36
// by caller. Example:
38
// ScopedMutex lock(cv.mutex());
39
// make_resource_available();
42
virtual void Signal() = 0;
44
// Broadcast to all threads waiting on condvar. mutex() must be held as with
46
virtual void Broadcast() = 0;
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
54
// ScopedMutex lock(cv.mutex());
55
// while (status && !resource_available()) status = cv.wait();
60
virtual void Wait() = 0;
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;
67
DISALLOW_COPY_AND_ASSIGN(Condvar);
70
} // namespace net_instaweb
72
#endif // PAGESPEED_KERNEL_BASE_CONDVAR_H_