summaryrefslogtreecommitdiff
path: root/ipc/chromium/src/base/condition_variable.h
diff options
context:
space:
mode:
Diffstat (limited to 'ipc/chromium/src/base/condition_variable.h')
-rw-r--r--ipc/chromium/src/base/condition_variable.h93
1 files changed, 17 insertions, 76 deletions
diff --git a/ipc/chromium/src/base/condition_variable.h b/ipc/chromium/src/base/condition_variable.h
index 63610e0e3b..f274c8eabe 100644
--- a/ipc/chromium/src/base/condition_variable.h
+++ b/ipc/chromium/src/base/condition_variable.h
@@ -1,5 +1,4 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -66,7 +65,17 @@
#ifndef BASE_CONDITION_VARIABLE_H_
#define BASE_CONDITION_VARIABLE_H_
+#include "base/basictypes.h"
#include "base/lock.h"
+#include "build/build_config.h"
+
+#if defined(OS_POSIX)
+#include <pthread.h>
+#endif
+
+#if defined(OS_WIN)
+#include <windows.h>
+#endif
namespace base {
class TimeDelta;
@@ -80,11 +89,13 @@ class ConditionVariable {
~ConditionVariable();
// Wait() releases the caller's critical section atomically as it starts to
- // sleep, and the reacquires it when it is signaled.
+ // sleep, and the reacquires it when it is signaled. The wait functions are
+ // susceptible to spurious wakeups. (See usage note 1 for more details.)
void Wait();
void TimedWait(const base::TimeDelta& max_time);
- // Broadcast() revives all waiting threads.
+ // Broadcast() revives all waiting threads. (See usage note 2 for more
+ // details.)
void Broadcast();
// Signal() revives one waiting thread.
void Signal();
@@ -92,81 +103,11 @@ class ConditionVariable {
private:
#if defined(OS_WIN)
-
- // Define Event class that is used to form circularly linked lists.
- // The list container is an element with NULL as its handle_ value.
- // The actual list elements have a non-zero handle_ value.
- // All calls to methods MUST be done under protection of a lock so that links
- // can be validated. Without the lock, some links might asynchronously
- // change, and the assertions would fail (as would list change operations).
- class Event {
- public:
- // Default constructor with no arguments creates a list container.
- Event();
- ~Event();
-
- // InitListElement transitions an instance from a container, to an element.
- void InitListElement();
-
- // Methods for use on lists.
- bool IsEmpty() const;
- void PushBack(Event* other);
- Event* PopFront();
- Event* PopBack();
-
- // Methods for use on list elements.
- // Accessor method.
- HANDLE handle() const;
- // Pull an element from a list (if it's in one).
- Event* Extract();
-
- // Method for use on a list element or on a list.
- bool IsSingleton() const;
-
- private:
- // Provide pre/post conditions to validate correct manipulations.
- bool ValidateAsDistinct(Event* other) const;
- bool ValidateAsItem() const;
- bool ValidateAsList() const;
- bool ValidateLinks() const;
-
- HANDLE handle_;
- Event* next_;
- Event* prev_;
- DISALLOW_COPY_AND_ASSIGN(Event);
- };
-
- // Note that RUNNING is an unlikely number to have in RAM by accident.
- // This helps with defensive destructor coding in the face of user error.
- enum RunState { SHUTDOWN = 0, RUNNING = 64213 };
-
- // Internal implementation methods supporting Wait().
- Event* GetEventForWaiting();
- void RecycleEvent(Event* used_event);
-
- RunState run_state_;
-
- // Private critical section for access to member data.
- Lock internal_lock_;
-
- // Lock that is acquired before calling Wait().
- Lock& user_lock_;
-
- // Events that threads are blocked on.
- Event waiting_list_;
-
- // Free list for old events.
- Event recycling_list_;
- int recycling_list_size_;
-
- // The number of allocated, but not yet deleted events.
- int allocation_counter_;
-
+ CONDITION_VARIABLE cv_;
+ SRWLOCK* const srwlock_;
#elif defined(OS_POSIX)
-
pthread_cond_t condition_;
pthread_mutex_t* user_mutex_;
-
#endif
DISALLOW_COPY_AND_ASSIGN(ConditionVariable);