summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-05 22:36:04 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-05 22:36:04 +0000
commite7af596810a247bcee52927d3e4c6a02d38e9459 (patch)
tree8b3d56e0d599daf88eaae67f0fac75781ba34768 /base
parentdf9e8cd83f062e899b2952a6fa5a47b28cd8169b (diff)
downloadchromium_src-e7af596810a247bcee52927d3e4c6a02d38e9459.zip
chromium_src-e7af596810a247bcee52927d3e4c6a02d38e9459.tar.gz
chromium_src-e7af596810a247bcee52927d3e4c6a02d38e9459.tar.bz2
FBTF: Move some inner classes out of their header files.
BUG=none TEST=none Review URL: http://codereview.chromium.org/3005047 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55145 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/message_pump_glib.cc16
-rw-r--r--base/message_pump_glib.h16
-rw-r--r--base/tracked_objects.cc102
-rw-r--r--base/tracked_objects.h41
4 files changed, 87 insertions, 88 deletions
diff --git a/base/message_pump_glib.cc b/base/message_pump_glib.cc
index f027fdc..e85a712 100644
--- a/base/message_pump_glib.cc
+++ b/base/message_pump_glib.cc
@@ -124,6 +124,22 @@ GSourceFuncs WorkSourceFuncs = {
namespace base {
+struct MessagePumpForUI::RunState {
+ Delegate* delegate;
+ Dispatcher* dispatcher;
+
+ // Used to flag that the current Run() invocation should return ASAP.
+ bool should_quit;
+
+ // Used to count how many Run() invocations are on the stack.
+ int run_depth;
+
+ // This keeps the state of whether the pump got signaled that there was new
+ // work to be done. Since we eat the message on the wake up pipe as soon as
+ // we get it, we keep that state here to stay consistent.
+ bool has_work;
+};
+
MessagePumpForUI::MessagePumpForUI()
: state_(NULL),
context_(g_main_context_default()),
diff --git a/base/message_pump_glib.h b/base/message_pump_glib.h
index ac9246d..f6d022a 100644
--- a/base/message_pump_glib.h
+++ b/base/message_pump_glib.h
@@ -82,21 +82,7 @@ class MessagePumpForUI : public MessagePump {
private:
// We may make recursive calls to Run, so we save state that needs to be
// separate between them in this structure type.
- struct RunState {
- Delegate* delegate;
- Dispatcher* dispatcher;
-
- // Used to flag that the current Run() invocation should return ASAP.
- bool should_quit;
-
- // Used to count how many Run() invocations are on the stack.
- int run_depth;
-
- // This keeps the state of whether the pump got signaled that there was new
- // work to be done. Since we eat the message on the wake up pipe as soon as
- // we get it, we keep that state here to stay consistent.
- bool has_work;
- };
+ struct RunState;
// Invoked from EventDispatcher. Notifies all observers we're about to
// process an event.
diff --git a/base/tracked_objects.cc b/base/tracked_objects.cc
index 3085816..cc2cae1 100644
--- a/base/tracked_objects.cc
+++ b/base/tracked_objects.cc
@@ -336,6 +336,73 @@ void ThreadData::Reset() {
}
#ifdef OS_WIN
+// A class used to count down which is accessed by several threads. This is
+// used to make sure RunOnAllThreads() actually runs a task on the expected
+// count of threads.
+class ThreadData::ThreadSafeDownCounter {
+ public:
+ // Constructor sets the count, once and for all.
+ explicit ThreadSafeDownCounter(size_t count);
+
+ // Decrement the count, and return true if we hit zero. Also delete this
+ // instance automatically when we hit zero.
+ bool LastCaller();
+
+ private:
+ size_t remaining_count_;
+ Lock lock_; // protect access to remaining_count_.
+};
+
+ThreadData::ThreadSafeDownCounter::ThreadSafeDownCounter(size_t count)
+ : remaining_count_(count) {
+ DCHECK_GT(remaining_count_, 0u);
+}
+
+bool ThreadData::ThreadSafeDownCounter::LastCaller() {
+ {
+ AutoLock lock(lock_);
+ if (--remaining_count_)
+ return false;
+ } // Release lock, so we can delete everything in this instance.
+ delete this;
+ return true;
+}
+
+// A Task class that runs a static method supplied, and checks to see if this
+// is the last tasks instance (on last thread) that will run the method.
+// IF this is the last run, then the supplied event is signalled.
+class ThreadData::RunTheStatic : public Task {
+ public:
+ typedef void (*FunctionPointer)();
+ RunTheStatic(FunctionPointer function,
+ HANDLE completion_handle,
+ ThreadSafeDownCounter* counter);
+ // Run the supplied static method, and optionally set the event.
+ void Run();
+
+ private:
+ FunctionPointer function_;
+ HANDLE completion_handle_;
+ // Make sure enough tasks are called before completion is signaled.
+ ThreadSafeDownCounter* counter_;
+
+ DISALLOW_COPY_AND_ASSIGN(RunTheStatic);
+};
+
+ThreadData::RunTheStatic::RunTheStatic(FunctionPointer function,
+ HANDLE completion_handle,
+ ThreadSafeDownCounter* counter)
+ : function_(function),
+ completion_handle_(completion_handle),
+ counter_(counter) {
+}
+
+void ThreadData::RunTheStatic::Run() {
+ function_();
+ if (counter_->LastCaller())
+ SetEvent(completion_handle_);
+}
+
// TODO(jar): This should use condition variables, and be cross platform.
void ThreadData::RunOnAllThreads(void (*function)()) {
ThreadData* list = first(); // Get existing list.
@@ -445,41 +512,6 @@ void ThreadData::ShutdownDisablingFurtherTracking() {
return;
}
-
-//------------------------------------------------------------------------------
-
-ThreadData::ThreadSafeDownCounter::ThreadSafeDownCounter(size_t count)
- : remaining_count_(count) {
- DCHECK_GT(remaining_count_, 0u);
-}
-
-bool ThreadData::ThreadSafeDownCounter::LastCaller() {
- {
- AutoLock lock(lock_);
- if (--remaining_count_)
- return false;
- } // Release lock, so we can delete everything in this instance.
- delete this;
- return true;
-}
-
-//------------------------------------------------------------------------------
-#ifdef OS_WIN
-ThreadData::RunTheStatic::RunTheStatic(FunctionPointer function,
- HANDLE completion_handle,
- ThreadSafeDownCounter* counter)
- : function_(function),
- completion_handle_(completion_handle),
- counter_(counter) {
-}
-
-void ThreadData::RunTheStatic::Run() {
- function_();
- if (counter_->LastCaller())
- SetEvent(completion_handle_);
-}
-#endif
-
//------------------------------------------------------------------------------
// Individual 3-tuple of birth (place and thread) along with death thread, and
// the accumulated stats for instances (DeathData).
diff --git a/base/tracked_objects.h b/base/tracked_objects.h
index 0b672ba..5392b9a 100644
--- a/base/tracked_objects.h
+++ b/base/tracked_objects.h
@@ -558,44 +558,9 @@ class ThreadData {
SHUTDOWN,
};
- // A class used to count down which is accessed by several threads. This is
- // used to make sure RunOnAllThreads() actually runs a task on the expected
- // count of threads.
- class ThreadSafeDownCounter {
- public:
- // Constructor sets the count, once and for all.
- explicit ThreadSafeDownCounter(size_t count);
-
- // Decrement the count, and return true if we hit zero. Also delete this
- // instance automatically when we hit zero.
- bool LastCaller();
-
- private:
- size_t remaining_count_;
- Lock lock_; // protect access to remaining_count_.
- };
-
-#ifdef OS_WIN
- // A Task class that runs a static method supplied, and checks to see if this
- // is the last tasks instance (on last thread) that will run the method.
- // IF this is the last run, then the supplied event is signalled.
- class RunTheStatic : public Task {
- public:
- typedef void (*FunctionPointer)();
- RunTheStatic(FunctionPointer function,
- HANDLE completion_handle,
- ThreadSafeDownCounter* counter);
- // Run the supplied static method, and optionally set the event.
- void Run();
-
- private:
- FunctionPointer function_;
- HANDLE completion_handle_;
- // Make sure enough tasks are called before completion is signaled.
- ThreadSafeDownCounter* counter_;
-
- DISALLOW_COPY_AND_ASSIGN(RunTheStatic);
- };
+#if defined(OS_WIN)
+ class ThreadSafeDownCounter;
+ class RunTheStatic;
#endif
// Each registered thread is called to set status_ to SHUTDOWN.