Commit 58f66ede authored by cpu@chromium.org's avatar cpu@chromium.org

Prep work for win7-specific condition variable

Move windows implementation to pimpl idiom
  http://c2.com/cgi/wiki?PimplIdiom

There should be no behavior change.

BUG=none
TEST=ConditionVariableTest in base_unittests suffice
Review URL: http://codereview.chromium.org/8823012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113439 0039d316-1c4b-4281-b951-d872f2087c98
parent 317c6415
...@@ -68,9 +68,7 @@ ...@@ -68,9 +68,7 @@
#include "build/build_config.h" #include "build/build_config.h"
#if defined(OS_WIN) #if defined(OS_POSIX)
#include <windows.h>
#elif defined(OS_POSIX)
#include <pthread.h> #include <pthread.h>
#endif #endif
...@@ -80,6 +78,7 @@ ...@@ -80,6 +78,7 @@
namespace base { namespace base {
class ConditionVarImpl;
class TimeDelta; class TimeDelta;
class BASE_EXPORT ConditionVariable { class BASE_EXPORT ConditionVariable {
...@@ -102,78 +101,8 @@ class BASE_EXPORT ConditionVariable { ...@@ -102,78 +101,8 @@ class BASE_EXPORT ConditionVariable {
private: private:
#if defined(OS_WIN) #if defined(OS_WIN)
ConditionVarImpl* impl_;
// 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.
base::Lock internal_lock_;
// Lock that is acquired before calling Wait().
base::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_;
#elif defined(OS_POSIX) #elif defined(OS_POSIX)
pthread_cond_t condition_; pthread_cond_t condition_;
pthread_mutex_t* user_mutex_; pthread_mutex_t* user_mutex_;
#if !defined(NDEBUG) #if !defined(NDEBUG)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment