Move some misc thread-related stuff from base to base/thread and into the base
namespace. This does not move the "hard" thread stuff (thread.h). TEST=it compiles BUG=none Review URL: http://codereview.chromium.org/6079009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70315 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
base
base.gypbase.gypilazy_instance_unittest.cc
metrics
non_thread_safe_unittest.ccthread_checker_unittest.ccthread_collision_warner_unittest.ccthread_local_storage_unittest.ccthread_local_unittest.ccthreading
chrome
net
base
cert_verifier.ccdnsrr_resolver.ccfile_stream_posix.cchost_resolver_impl.cckeygen_handler_unittest.cctest_completion_callback_unittest.cc
disk_cache
proxy
tools
flip_server
url_request
ppapi
@ -125,7 +125,6 @@
|
||||
'sha1_unittest.cc',
|
||||
'sha2_unittest.cc',
|
||||
'shared_memory_unittest.cc',
|
||||
'simple_thread_unittest.cc',
|
||||
'singleton_unittest.cc',
|
||||
'stack_container_unittest.cc',
|
||||
'string16_unittest.cc',
|
||||
@ -141,6 +140,10 @@
|
||||
'sys_string_conversions_unittest.cc',
|
||||
'task_queue_unittest.cc',
|
||||
'task_unittest.cc',
|
||||
'threading/simple_thread_unittest.cc',
|
||||
'threading/watchdog_unittest.cc',
|
||||
'threading/worker_pool_posix_unittest.cc',
|
||||
'threading/worker_pool_unittest.cc',
|
||||
'thread_checker_unittest.cc',
|
||||
'thread_collision_warner_unittest.cc',
|
||||
'thread_local_storage_unittest.cc',
|
||||
@ -159,7 +162,6 @@
|
||||
'vlog_unittest.cc',
|
||||
'waitable_event_unittest.cc',
|
||||
'waitable_event_watcher_unittest.cc',
|
||||
'watchdog_unittest.cc',
|
||||
'weak_ptr_unittest.cc',
|
||||
'win_util_unittest.cc',
|
||||
'win/event_trace_consumer_unittest.cc',
|
||||
@ -171,8 +173,6 @@
|
||||
'win/scoped_bstr_unittest.cc',
|
||||
'win/scoped_comptr_unittest.cc',
|
||||
'win/scoped_variant_unittest.cc',
|
||||
'worker_pool_posix_unittest.cc',
|
||||
'worker_pool_unittest.cc',
|
||||
],
|
||||
'dependencies': [
|
||||
'base',
|
||||
|
@ -209,8 +209,6 @@
|
||||
'shared_memory.h',
|
||||
'shared_memory_posix.cc',
|
||||
'shared_memory_win.cc',
|
||||
'simple_thread.cc',
|
||||
'simple_thread.h',
|
||||
'singleton.h',
|
||||
'spin_wait.h',
|
||||
'stack_container.h',
|
||||
@ -245,6 +243,14 @@
|
||||
'task_queue.cc',
|
||||
'task_queue.h',
|
||||
'template_util.h',
|
||||
'threading/simple_thread.cc',
|
||||
'threading/simple_thread.h',
|
||||
'threading/watchdog.cc',
|
||||
'threading/watchdog.h',
|
||||
'threading/worker_pool.h',
|
||||
'threading/worker_pool_posix.cc',
|
||||
'threading/worker_pool_posix.h',
|
||||
'threading/worker_pool_win.cc',
|
||||
'thread.cc',
|
||||
'thread.h',
|
||||
'thread_checker.cc',
|
||||
@ -289,8 +295,6 @@
|
||||
'waitable_event_watcher_posix.cc',
|
||||
'waitable_event_watcher_win.cc',
|
||||
'waitable_event_win.cc',
|
||||
'watchdog.cc',
|
||||
'watchdog.h',
|
||||
'weak_ptr.cc',
|
||||
'weak_ptr.h',
|
||||
'win/i18n.cc',
|
||||
@ -317,10 +321,6 @@
|
||||
'win/windows_version.h',
|
||||
'win_util.cc',
|
||||
'win_util.h',
|
||||
'worker_pool.h',
|
||||
'worker_pool_posix.cc',
|
||||
'worker_pool_posix.h',
|
||||
'worker_pool_win.cc',
|
||||
'nix/xdg_util.h',
|
||||
'nix/xdg_util.cc',
|
||||
],
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include "base/at_exit.h"
|
||||
#include "base/atomic_sequence_num.h"
|
||||
#include "base/lazy_instance.h"
|
||||
#include "base/simple_thread.h"
|
||||
#include "base/threading/simple_thread.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
namespace {
|
||||
|
@ -2,14 +2,14 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "base/platform_thread.h"
|
||||
#include "base/simple_thread.h"
|
||||
#include "base/shared_memory.h"
|
||||
#include "base/metrics/stats_table.h"
|
||||
#include "base/metrics/stats_counters.h"
|
||||
#include "base/metrics/stats_table.h"
|
||||
#include "base/platform_thread.h"
|
||||
#include "base/shared_memory.h"
|
||||
#include "base/string_piece.h"
|
||||
#include "base/string_util.h"
|
||||
#include "base/test/multiprocess_test.h"
|
||||
#include "base/threading/simple_thread.h"
|
||||
#include "base/utf_string_conversions.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "testing/multiprocess_func_list.h"
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include "base/logging.h"
|
||||
#include "base/non_thread_safe.h"
|
||||
#include "base/scoped_ptr.h"
|
||||
#include "base/simple_thread.h"
|
||||
#include "base/threading/simple_thread.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
#ifndef NDEBUG
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include "base/logging.h"
|
||||
#include "base/thread_checker.h"
|
||||
#include "base/scoped_ptr.h"
|
||||
#include "base/simple_thread.h"
|
||||
#include "base/threading/simple_thread.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
#ifndef NDEBUG
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include "base/lock.h"
|
||||
#include "base/platform_thread.h"
|
||||
#include "base/scoped_ptr.h"
|
||||
#include "base/simple_thread.h"
|
||||
#include "base/threading/simple_thread.h"
|
||||
#include "base/thread_collision_warner.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <process.h>
|
||||
#endif
|
||||
|
||||
#include "base/simple_thread.h"
|
||||
#include "base/threading/simple_thread.h"
|
||||
#include "base/thread_local_storage.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
||||
// Copyright (c) 2010 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.
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/simple_thread.h"
|
||||
#include "base/threading/simple_thread.h"
|
||||
#include "base/thread_local.h"
|
||||
#include "base/waitable_event.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
@ -1,8 +1,8 @@
|
||||
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
||||
// Copyright (c) 2010 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.
|
||||
|
||||
#include "base/simple_thread.h"
|
||||
#include "base/threading/simple_thread.h"
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/platform_thread.h"
|
@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
||||
// Copyright (c) 2010 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.
|
||||
|
||||
@ -37,8 +37,8 @@
|
||||
// // The SimpleThread object is still valid, however you may not call Join
|
||||
// // or Start again.
|
||||
|
||||
#ifndef BASE_SIMPLE_THREAD_H_
|
||||
#define BASE_SIMPLE_THREAD_H_
|
||||
#ifndef BASE_THREADING_SIMPLE_THREAD_H_
|
||||
#define BASE_THREADING_SIMPLE_THREAD_H_
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
@ -179,4 +179,4 @@ class DelegateSimpleThreadPool : public DelegateSimpleThread::Delegate {
|
||||
|
||||
} // namespace base
|
||||
|
||||
#endif // BASE_SIMPLE_THREAD_H_
|
||||
#endif // BASE_THREADING_SIMPLE_THREAD_H_
|
@ -3,14 +3,16 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "base/atomic_sequence_num.h"
|
||||
#include "base/simple_thread.h"
|
||||
#include "base/string_number_conversions.h"
|
||||
#include "base/threading/simple_thread.h"
|
||||
#include "base/waitable_event.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
namespace base {
|
||||
|
||||
namespace {
|
||||
|
||||
class SetIntRunner : public base::DelegateSimpleThread::Delegate {
|
||||
class SetIntRunner : public DelegateSimpleThread::Delegate {
|
||||
public:
|
||||
SetIntRunner(int* ptr, int val) : ptr_(ptr), val_(val) { }
|
||||
~SetIntRunner() { }
|
||||
@ -24,9 +26,9 @@ class SetIntRunner : public base::DelegateSimpleThread::Delegate {
|
||||
int val_;
|
||||
};
|
||||
|
||||
class WaitEventRunner : public base::DelegateSimpleThread::Delegate {
|
||||
class WaitEventRunner : public DelegateSimpleThread::Delegate {
|
||||
public:
|
||||
explicit WaitEventRunner(base::WaitableEvent* event) : event_(event) { }
|
||||
explicit WaitEventRunner(WaitableEvent* event) : event_(event) { }
|
||||
~WaitEventRunner() { }
|
||||
|
||||
virtual void Run() {
|
||||
@ -35,27 +37,27 @@ class WaitEventRunner : public base::DelegateSimpleThread::Delegate {
|
||||
EXPECT_TRUE(event_->IsSignaled());
|
||||
}
|
||||
private:
|
||||
base::WaitableEvent* event_;
|
||||
WaitableEvent* event_;
|
||||
};
|
||||
|
||||
class SeqRunner : public base::DelegateSimpleThread::Delegate {
|
||||
class SeqRunner : public DelegateSimpleThread::Delegate {
|
||||
public:
|
||||
explicit SeqRunner(base::AtomicSequenceNumber* seq) : seq_(seq) { }
|
||||
explicit SeqRunner(AtomicSequenceNumber* seq) : seq_(seq) { }
|
||||
virtual void Run() {
|
||||
seq_->GetNext();
|
||||
}
|
||||
|
||||
private:
|
||||
base::AtomicSequenceNumber* seq_;
|
||||
AtomicSequenceNumber* seq_;
|
||||
};
|
||||
|
||||
// We count up on a sequence number, firing on the event when we've hit our
|
||||
// expected amount, otherwise we wait on the event. This will ensure that we
|
||||
// have all threads outstanding until we hit our expected thread pool size.
|
||||
class VerifyPoolRunner : public base::DelegateSimpleThread::Delegate {
|
||||
class VerifyPoolRunner : public DelegateSimpleThread::Delegate {
|
||||
public:
|
||||
VerifyPoolRunner(base::AtomicSequenceNumber* seq,
|
||||
int total, base::WaitableEvent* event)
|
||||
VerifyPoolRunner(AtomicSequenceNumber* seq,
|
||||
int total, WaitableEvent* event)
|
||||
: seq_(seq), total_(total), event_(event) { }
|
||||
|
||||
virtual void Run() {
|
||||
@ -67,9 +69,9 @@ class VerifyPoolRunner : public base::DelegateSimpleThread::Delegate {
|
||||
}
|
||||
|
||||
private:
|
||||
base::AtomicSequenceNumber* seq_;
|
||||
AtomicSequenceNumber* seq_;
|
||||
int total_;
|
||||
base::WaitableEvent* event_;
|
||||
WaitableEvent* event_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
@ -80,7 +82,7 @@ TEST(SimpleThreadTest, CreateAndJoin) {
|
||||
SetIntRunner runner(&stack_int, 7);
|
||||
EXPECT_EQ(0, stack_int);
|
||||
|
||||
base::DelegateSimpleThread thread(&runner, "int_setter");
|
||||
DelegateSimpleThread thread(&runner, "int_setter");
|
||||
EXPECT_FALSE(thread.HasBeenStarted());
|
||||
EXPECT_FALSE(thread.HasBeenJoined());
|
||||
EXPECT_EQ(0, stack_int);
|
||||
@ -97,10 +99,10 @@ TEST(SimpleThreadTest, CreateAndJoin) {
|
||||
|
||||
TEST(SimpleThreadTest, WaitForEvent) {
|
||||
// Create a thread, and wait for it to signal us.
|
||||
base::WaitableEvent event(true, false);
|
||||
WaitableEvent event(true, false);
|
||||
|
||||
WaitEventRunner runner(&event);
|
||||
base::DelegateSimpleThread thread(&runner, "event_waiter");
|
||||
DelegateSimpleThread thread(&runner, "event_waiter");
|
||||
|
||||
EXPECT_FALSE(event.IsSignaled());
|
||||
thread.Start();
|
||||
@ -110,18 +112,18 @@ TEST(SimpleThreadTest, WaitForEvent) {
|
||||
}
|
||||
|
||||
TEST(SimpleThreadTest, NamedWithOptions) {
|
||||
base::WaitableEvent event(true, false);
|
||||
WaitableEvent event(true, false);
|
||||
|
||||
WaitEventRunner runner(&event);
|
||||
base::SimpleThread::Options options;
|
||||
base::DelegateSimpleThread thread(&runner, "event_waiter", options);
|
||||
SimpleThread::Options options;
|
||||
DelegateSimpleThread thread(&runner, "event_waiter", options);
|
||||
EXPECT_EQ(thread.name_prefix(), "event_waiter");
|
||||
EXPECT_FALSE(event.IsSignaled());
|
||||
|
||||
thread.Start();
|
||||
EXPECT_EQ(thread.name_prefix(), "event_waiter");
|
||||
EXPECT_EQ(thread.name(),
|
||||
std::string("event_waiter/") + base::IntToString(thread.tid()));
|
||||
std::string("event_waiter/") + IntToString(thread.tid()));
|
||||
event.Wait();
|
||||
|
||||
EXPECT_TRUE(event.IsSignaled());
|
||||
@ -130,13 +132,13 @@ TEST(SimpleThreadTest, NamedWithOptions) {
|
||||
// We keep the name and tid, even after the thread is gone.
|
||||
EXPECT_EQ(thread.name_prefix(), "event_waiter");
|
||||
EXPECT_EQ(thread.name(),
|
||||
std::string("event_waiter/") + base::IntToString(thread.tid()));
|
||||
std::string("event_waiter/") + IntToString(thread.tid()));
|
||||
}
|
||||
|
||||
TEST(SimpleThreadTest, ThreadPool) {
|
||||
base::AtomicSequenceNumber seq;
|
||||
AtomicSequenceNumber seq;
|
||||
SeqRunner runner(&seq);
|
||||
base::DelegateSimpleThreadPool pool("seq_runner", 10);
|
||||
DelegateSimpleThreadPool pool("seq_runner", 10);
|
||||
|
||||
// Add work before we're running.
|
||||
pool.AddWork(&runner, 300);
|
||||
@ -153,8 +155,8 @@ TEST(SimpleThreadTest, ThreadPool) {
|
||||
|
||||
// We can reuse our pool. Verify that all 10 threads can actually run in
|
||||
// parallel, so this test will only pass if there are actually 10 threads.
|
||||
base::AtomicSequenceNumber seq2;
|
||||
base::WaitableEvent event(true, false);
|
||||
AtomicSequenceNumber seq2;
|
||||
WaitableEvent event(true, false);
|
||||
// Changing 9 to 10, for example, would cause us JoinAll() to never return.
|
||||
VerifyPoolRunner verifier(&seq2, 9, &event);
|
||||
pool.Start();
|
||||
@ -164,3 +166,5 @@ TEST(SimpleThreadTest, ThreadPool) {
|
||||
pool.JoinAll();
|
||||
EXPECT_EQ(seq2.GetNext(), 10);
|
||||
}
|
||||
|
||||
} // namespace base
|
@ -2,17 +2,13 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "base/watchdog.h"
|
||||
#include "base/threading/watchdog.h"
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/platform_thread.h"
|
||||
|
||||
using base::TimeDelta;
|
||||
using base::TimeTicks;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Public API methods.
|
||||
namespace base {
|
||||
|
||||
// Start thread running in a Disarmed state.
|
||||
Watchdog::Watchdog(const TimeDelta& duration,
|
||||
@ -144,3 +140,5 @@ Lock Watchdog::static_lock_; // Lock for access of static data...
|
||||
TimeTicks Watchdog::last_debugged_alarm_time_ = TimeTicks();
|
||||
// static
|
||||
TimeDelta Watchdog::last_debugged_alarm_delay_;
|
||||
|
||||
} // namespace base
|
@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
||||
// Copyright (c) 2010 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.
|
||||
|
||||
@ -15,8 +15,8 @@
|
||||
// a second thread, and their methods call (Arm() and Disarm()) return very
|
||||
// quickly.
|
||||
|
||||
#ifndef BASE_WATCHDOG_H__
|
||||
#define BASE_WATCHDOG_H__
|
||||
#ifndef BASE_THREADING_WATCHDOG_H_
|
||||
#define BASE_THREADING_WATCHDOG_H_
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
@ -26,6 +26,8 @@
|
||||
#include "base/platform_thread.h"
|
||||
#include "base/time.h"
|
||||
|
||||
namespace base {
|
||||
|
||||
class Watchdog {
|
||||
public:
|
||||
// Constructor specifies how long the Watchdog will wait before alarming.
|
||||
@ -91,4 +93,6 @@ class Watchdog {
|
||||
DISALLOW_COPY_AND_ASSIGN(Watchdog);
|
||||
};
|
||||
|
||||
#endif // BASE_WATCHDOG_H__
|
||||
} // namespace base
|
||||
|
||||
#endif // BASE_THREADING_WATCHDOG_H_
|
@ -2,9 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Tests for Watchdog class.
|
||||
|
||||
#include "base/watchdog.h"
|
||||
#include "base/threading/watchdog.h"
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/platform_thread.h"
|
||||
@ -12,8 +10,7 @@
|
||||
#include "base/time.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
using base::TimeDelta;
|
||||
using base::TimeTicks;
|
||||
namespace base {
|
||||
|
||||
namespace {
|
||||
|
||||
@ -50,6 +47,7 @@ class WatchdogTest : public testing::Test {
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Actual tests
|
||||
@ -139,4 +137,4 @@ TEST_F(WatchdogTest, DisarmTest) {
|
||||
EXPECT_EQ(1, watchdog.alarm_counter());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace base
|
@ -1,15 +1,17 @@
|
||||
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
||||
// Copyright (c) 2010 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.
|
||||
|
||||
#ifndef BASE_WORKER_POOL_H_
|
||||
#define BASE_WORKER_POOL_H_
|
||||
#ifndef BASE_THREADING_WORKER_POOL_H_
|
||||
#define BASE_THREADING_WORKER_POOL_H_
|
||||
#pragma once
|
||||
|
||||
#include "base/tracked.h"
|
||||
|
||||
class Task;
|
||||
|
||||
namespace base {
|
||||
|
||||
// This is a facility that runs tasks that don't require a specific thread or
|
||||
// a message loop.
|
||||
//
|
||||
@ -28,4 +30,6 @@ class WorkerPool {
|
||||
Task* task, bool task_is_slow);
|
||||
};
|
||||
|
||||
#endif // BASE_WORKER_POOL_H_
|
||||
} // namespace base
|
||||
|
||||
#endif // BASE_THREADING_WORKER_POOL_H_
|
@ -2,8 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "base/worker_pool.h"
|
||||
#include "base/worker_pool_posix.h"
|
||||
#include "base/threading/worker_pool_posix.h"
|
||||
|
||||
#include "base/lazy_instance.h"
|
||||
#include "base/logging.h"
|
||||
@ -11,6 +10,9 @@
|
||||
#include "base/ref_counted.h"
|
||||
#include "base/stringprintf.h"
|
||||
#include "base/task.h"
|
||||
#include "base/threading/worker_pool.h"
|
||||
|
||||
namespace base {
|
||||
|
||||
namespace {
|
||||
|
||||
@ -32,8 +34,9 @@ class WorkerPoolImpl {
|
||||
};
|
||||
|
||||
WorkerPoolImpl::WorkerPoolImpl()
|
||||
: pool_(new base::PosixDynamicThreadPool(
|
||||
"WorkerPool", kIdleSecondsBeforeExit)) {}
|
||||
: pool_(new base::PosixDynamicThreadPool("WorkerPool",
|
||||
kIdleSecondsBeforeExit)) {
|
||||
}
|
||||
|
||||
WorkerPoolImpl::~WorkerPoolImpl() {
|
||||
pool_->Terminate();
|
||||
@ -90,8 +93,6 @@ bool WorkerPool::PostTask(const tracked_objects::Location& from_here,
|
||||
return true;
|
||||
}
|
||||
|
||||
namespace base {
|
||||
|
||||
PosixDynamicThreadPool::PosixDynamicThreadPool(
|
||||
const std::string& name_prefix,
|
||||
int idle_seconds_before_exit)
|
@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
|
||||
// Copyright (c) 2010 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.
|
||||
//
|
||||
@ -21,8 +21,8 @@
|
||||
// implementation of WorkerPool. No one else should be using these classes.
|
||||
// These symbols are exported in a header purely for testing purposes.
|
||||
|
||||
#ifndef BASE_WORKER_POOL_POSIX_H_
|
||||
#define BASE_WORKER_POOL_POSIX_H_
|
||||
#ifndef BASE_THREADING_WORKER_POOL_POSIX_H_
|
||||
#define BASE_THREADING_WORKER_POOL_POSIX_H_
|
||||
#pragma once
|
||||
|
||||
#include <queue>
|
||||
@ -86,4 +86,4 @@ class PosixDynamicThreadPool
|
||||
|
||||
} // namespace base
|
||||
|
||||
#endif // BASE_WORKER_POOL_POSIX_H_
|
||||
#endif // BASE_THREADING_WORKER_POOL_POSIX_H_
|
@ -1,8 +1,8 @@
|
||||
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
|
||||
// Copyright (c) 2010 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.
|
||||
|
||||
#include "base/worker_pool_posix.h"
|
||||
#include "base/threading/worker_pool_posix.h"
|
||||
|
||||
#include <set>
|
||||
|
||||
@ -40,8 +40,6 @@ class PosixDynamicThreadPool::PosixDynamicThreadPoolPeer {
|
||||
DISALLOW_COPY_AND_ASSIGN(PosixDynamicThreadPoolPeer);
|
||||
};
|
||||
|
||||
} // namespace base
|
||||
|
||||
namespace {
|
||||
|
||||
// IncrementingTask's main purpose is to increment a counter. It also updates a
|
||||
@ -177,6 +175,8 @@ class PosixDynamicThreadPoolTest : public testing::Test {
|
||||
base::WaitableEvent start_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_F(PosixDynamicThreadPoolTest, Basic) {
|
||||
EXPECT_EQ(0, peer_.num_idle_threads());
|
||||
EXPECT_EQ(0U, unique_threads_.size());
|
||||
@ -265,4 +265,4 @@ TEST_F(PosixDynamicThreadPoolTest, Complex) {
|
||||
EXPECT_EQ(4, counter_);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace base
|
@ -4,14 +4,14 @@
|
||||
|
||||
#include "base/task.h"
|
||||
#include "base/waitable_event.h"
|
||||
#include "base/worker_pool.h"
|
||||
#include "base/threading/worker_pool.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "testing/platform_test.h"
|
||||
|
||||
using base::WaitableEvent;
|
||||
|
||||
typedef PlatformTest WorkerPoolTest;
|
||||
|
||||
namespace base {
|
||||
|
||||
namespace {
|
||||
|
||||
class PostTaskTestTask : public Task {
|
||||
@ -27,6 +27,8 @@ class PostTaskTestTask : public Task {
|
||||
WaitableEvent* event_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_F(WorkerPoolTest, PostTask) {
|
||||
WaitableEvent test_event(false, false);
|
||||
WaitableEvent long_test_event(false, false);
|
||||
@ -41,4 +43,4 @@ TEST_F(WorkerPoolTest, PostTask) {
|
||||
EXPECT_TRUE(signaled);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace base
|
@ -1,12 +1,14 @@
|
||||
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
||||
// Copyright (c) 2010 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.
|
||||
|
||||
#include "base/worker_pool.h"
|
||||
#include "base/threading/worker_pool.h"
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/task.h"
|
||||
|
||||
namespace base {
|
||||
|
||||
namespace {
|
||||
|
||||
DWORD CALLBACK WorkItemCallback(void* param) {
|
||||
@ -34,3 +36,5 @@ bool WorkerPool::PostTask(const tracked_objects::Location& from_here,
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace base
|
@ -13,9 +13,9 @@
|
||||
#include "base/metrics/stats_counters.h"
|
||||
#include "base/ref_counted.h"
|
||||
#include "base/string_util.h"
|
||||
#include "base/threading/watchdog.h"
|
||||
#include "base/thread.h"
|
||||
#include "base/time.h"
|
||||
#include "base/watchdog.h"
|
||||
#include "build/build_config.h"
|
||||
#include "chrome/browser/browser_process.h"
|
||||
#include "chrome/browser/browser_thread.h"
|
||||
@ -55,7 +55,7 @@ const bool kPlaySounds = false;
|
||||
//------------------------------------------------------------------------------
|
||||
// Provide a special watchdog to make it easy to set the breakpoint on this
|
||||
// class only.
|
||||
class JankWatchdog : public Watchdog {
|
||||
class JankWatchdog : public base::Watchdog {
|
||||
public:
|
||||
JankWatchdog(const TimeDelta& duration,
|
||||
const std::string& thread_watched_name,
|
||||
|
@ -4,8 +4,8 @@
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/file_util.h"
|
||||
#include "base/simple_thread.h"
|
||||
#include "base/test/test_file_util.h"
|
||||
#include "base/threading/simple_thread.h"
|
||||
#include "chrome/test/automation/tab_proxy.h"
|
||||
#include "chrome/test/ui/ui_test.h"
|
||||
#include "net/test/test_server.h"
|
||||
|
@ -12,9 +12,9 @@
|
||||
#include "base/process_util.h"
|
||||
#include "base/shared_memory.h"
|
||||
#include "base/sys_string_conversions.h"
|
||||
#include "base/threading/worker_pool.h"
|
||||
#include "base/thread.h"
|
||||
#include "base/utf_string_conversions.h"
|
||||
#include "base/worker_pool.h"
|
||||
#include "chrome/browser/automation/automation_resource_message_filter.h"
|
||||
#include "chrome/browser/browser_process.h"
|
||||
#include "chrome/browser/browser_thread.h"
|
||||
@ -1352,7 +1352,7 @@ void RenderMessageFilter::OnKeygen(uint32 key_size_index,
|
||||
|
||||
VLOG(1) << "Dispatching keygen task to worker pool.";
|
||||
// Dispatch to worker pool, so we do not block the IO thread.
|
||||
if (!WorkerPool::PostTask(
|
||||
if (!base::WorkerPool::PostTask(
|
||||
FROM_HERE,
|
||||
NewRunnableMethod(
|
||||
this, &RenderMessageFilter::OnKeygenOnWorkerThread,
|
||||
|
@ -17,7 +17,7 @@
|
||||
#include "base/sys_string_conversions.h"
|
||||
#include "base/ref_counted.h"
|
||||
#include "base/task.h"
|
||||
#include "base/worker_pool.h"
|
||||
#include "base/threading/worker_pool.h"
|
||||
#include "chrome/browser/ui/cocoa/authorization_util.h"
|
||||
#include "chrome/common/chrome_constants.h"
|
||||
#include "grit/chromium_strings.h"
|
||||
@ -104,7 +104,7 @@ class PerformBridge : public base::RefCountedThreadSafe<PerformBridge> {
|
||||
DCHECK(sel);
|
||||
|
||||
scoped_refptr<PerformBridge> op = new PerformBridge(target, sel, arg);
|
||||
WorkerPool::PostTask(
|
||||
base::WorkerPool::PostTask(
|
||||
FROM_HERE, NewRunnableMethod(op.get(), &PerformBridge::Run), true);
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
#include "app/gfx/gl/gl_context.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/worker_pool.h"
|
||||
#include "base/threading/worker_pool.h"
|
||||
#include "build/build_config.h"
|
||||
#include "chrome/common/child_process.h"
|
||||
#include "chrome/common/child_process_logging.h"
|
||||
@ -34,7 +34,7 @@ void GpuThread::Init(const base::Time& process_start_time) {
|
||||
#if defined(OS_WIN)
|
||||
// Asynchronously collect the DirectX diagnostics because this can take a
|
||||
// couple of seconds.
|
||||
if (!WorkerPool::PostTask(
|
||||
if (!base::WorkerPool::PostTask(
|
||||
FROM_HERE,
|
||||
NewRunnableFunction(&GpuThread::CollectDxDiagnostics, this),
|
||||
true)) {
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include "base/basictypes.h"
|
||||
#include "base/scoped_ptr.h"
|
||||
#include "base/shared_memory.h"
|
||||
#include "base/simple_thread.h"
|
||||
#include "base/threading/simple_thread.h"
|
||||
#include "chrome/common/render_messages.h"
|
||||
#include "chrome/renderer/audio_message_filter.h"
|
||||
#include "gfx/rect.h"
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include "base/lock.h"
|
||||
#include "base/message_loop.h"
|
||||
#include "base/stl_util-inl.h"
|
||||
#include "base/worker_pool.h"
|
||||
#include "base/threading/worker_pool.h"
|
||||
#include "net/base/net_errors.h"
|
||||
#include "net/base/x509_certificate.h"
|
||||
|
||||
@ -136,9 +136,9 @@ class CertVerifierWorker {
|
||||
bool Start() {
|
||||
DCHECK_EQ(MessageLoop::current(), origin_loop_);
|
||||
|
||||
return WorkerPool::PostTask(
|
||||
FROM_HERE, NewRunnableMethod(this, &CertVerifierWorker::Run),
|
||||
true /* task is slow */);
|
||||
return base::WorkerPool::PostTask(
|
||||
FROM_HERE, NewRunnableMethod(this, &CertVerifierWorker::Run),
|
||||
true /* task is slow */);
|
||||
}
|
||||
|
||||
// Cancel is called from the origin loop when the CertVerifier is getting
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include "base/stl_util-inl.h"
|
||||
#include "base/string_piece.h"
|
||||
#include "base/task.h"
|
||||
#include "base/worker_pool.h"
|
||||
#include "base/threading/worker_pool.h"
|
||||
#include "net/base/dns_reload_timer.h"
|
||||
#include "net/base/dns_util.h"
|
||||
#include "net/base/net_errors.h"
|
||||
@ -139,9 +139,9 @@ class RRResolverWorker {
|
||||
bool Start() {
|
||||
DCHECK_EQ(MessageLoop::current(), origin_loop_);
|
||||
|
||||
return WorkerPool::PostTask(
|
||||
FROM_HERE, NewRunnableMethod(this, &RRResolverWorker::Run),
|
||||
true /* task is slow */);
|
||||
return base::WorkerPool::PostTask(
|
||||
FROM_HERE, NewRunnableMethod(this, &RRResolverWorker::Run),
|
||||
true /* task is slow */);
|
||||
}
|
||||
|
||||
// Cancel is called from the origin loop when the DnsRRResolver is getting
|
||||
|
@ -21,8 +21,8 @@
|
||||
#include "base/message_loop.h"
|
||||
#include "base/metrics/histogram.h"
|
||||
#include "base/string_util.h"
|
||||
#include "base/threading/worker_pool.h"
|
||||
#include "base/waitable_event.h"
|
||||
#include "base/worker_pool.h"
|
||||
#include "net/base/net_errors.h"
|
||||
|
||||
// We cast back and forth, so make sure it's the size we're expecting.
|
||||
@ -250,11 +250,11 @@ void FileStream::AsyncContext::InitiateAsyncRead(
|
||||
DCHECK(!callback_);
|
||||
callback_ = callback;
|
||||
|
||||
WorkerPool::PostTask(FROM_HERE,
|
||||
new BackgroundReadTask(
|
||||
file, buf, buf_len,
|
||||
&background_io_completed_callback_),
|
||||
true /* task_is_slow */);
|
||||
base::WorkerPool::PostTask(FROM_HERE,
|
||||
new BackgroundReadTask(
|
||||
file, buf, buf_len,
|
||||
&background_io_completed_callback_),
|
||||
true /* task_is_slow */);
|
||||
}
|
||||
|
||||
void FileStream::AsyncContext::InitiateAsyncWrite(
|
||||
@ -263,11 +263,11 @@ void FileStream::AsyncContext::InitiateAsyncWrite(
|
||||
DCHECK(!callback_);
|
||||
callback_ = callback;
|
||||
|
||||
WorkerPool::PostTask(FROM_HERE,
|
||||
new BackgroundWriteTask(
|
||||
file, buf, buf_len,
|
||||
&background_io_completed_callback_),
|
||||
true /* task_is_slow */);
|
||||
base::WorkerPool::PostTask(FROM_HERE,
|
||||
new BackgroundWriteTask(
|
||||
file, buf, buf_len,
|
||||
&background_io_completed_callback_),
|
||||
true /* task_is_slow */);
|
||||
}
|
||||
|
||||
void FileStream::AsyncContext::OnBackgroundIOCompleted(int result) {
|
||||
|
@ -24,10 +24,10 @@
|
||||
#include "base/metrics/histogram.h"
|
||||
#include "base/stl_util-inl.h"
|
||||
#include "base/string_util.h"
|
||||
#include "base/threading/worker_pool.h"
|
||||
#include "base/time.h"
|
||||
#include "base/utf_string_conversions.h"
|
||||
#include "base/values.h"
|
||||
#include "base/worker_pool.h"
|
||||
#include "net/base/address_list.h"
|
||||
#include "net/base/address_list_net_log_param.h"
|
||||
#include "net/base/host_port_pair.h"
|
||||
@ -382,7 +382,7 @@ class HostResolverImpl::Job
|
||||
start_time_ = base::TimeTicks::Now();
|
||||
|
||||
// Dispatch the job to a worker thread.
|
||||
if (!WorkerPool::PostTask(FROM_HERE,
|
||||
if (!base::WorkerPool::PostTask(FROM_HERE,
|
||||
NewRunnableMethod(this, &Job::DoLookup), true)) {
|
||||
NOTREACHED();
|
||||
|
||||
@ -650,7 +650,7 @@ class HostResolverImpl::IPv6ProbeJob
|
||||
return;
|
||||
DCHECK(IsOnOriginThread());
|
||||
const bool kIsSlow = true;
|
||||
WorkerPool::PostTask(
|
||||
base::WorkerPool::PostTask(
|
||||
FROM_HERE, NewRunnableMethod(this, &IPv6ProbeJob::DoProbe), kIsSlow);
|
||||
}
|
||||
|
||||
|
@ -11,9 +11,9 @@
|
||||
#include "base/logging.h"
|
||||
#include "base/nss_util.h"
|
||||
#include "base/task.h"
|
||||
#include "base/threading/worker_pool.h"
|
||||
#include "base/thread_restrictions.h"
|
||||
#include "base/waitable_event.h"
|
||||
#include "base/worker_pool.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
#if defined(USE_NSS)
|
||||
@ -124,10 +124,10 @@ TEST_F(KeygenHandlerTest, ConcurrencyTest) {
|
||||
std::string results[NUM_HANDLERS];
|
||||
for (int i = 0; i < NUM_HANDLERS; i++) {
|
||||
events[i] = new base::WaitableEvent(false, false);
|
||||
WorkerPool::PostTask(FROM_HERE,
|
||||
new ConcurrencyTestTask(events[i], "some challenge",
|
||||
&results[i]),
|
||||
true);
|
||||
base::WorkerPool::PostTask(
|
||||
FROM_HERE,
|
||||
new ConcurrencyTestTask(events[i], "some challenge", &results[i]),
|
||||
true);
|
||||
}
|
||||
|
||||
for (int i = 0; i < NUM_HANDLERS; i++) {
|
||||
|
@ -1,13 +1,13 @@
|
||||
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
||||
// Copyright (c) 2010 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.
|
||||
|
||||
// Illustrates how to use worker threads that issue completion callbacks
|
||||
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "base/threading/worker_pool.h"
|
||||
#include "net/base/completion_callback.h"
|
||||
#include "net/base/test_completion_callback.h"
|
||||
#include "base/worker_pool.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "testing/platform_test.h"
|
||||
|
||||
typedef PlatformTest TestCompletionCallbackTest;
|
||||
@ -102,7 +102,7 @@ bool ExampleEmployer::DoSomething(CompletionCallback* callback) {
|
||||
request_ = new ExampleWorker(this, callback);
|
||||
|
||||
// Dispatch to worker thread...
|
||||
if (!WorkerPool::PostTask(FROM_HERE,
|
||||
if (!base::WorkerPool::PostTask(FROM_HERE,
|
||||
NewRunnableMethod(request_.get(), &ExampleWorker::DoWork), true)) {
|
||||
NOTREACHED();
|
||||
request_ = NULL;
|
||||
|
@ -13,10 +13,10 @@
|
||||
#include "base/string_util.h"
|
||||
#include "base/stringprintf.h"
|
||||
#include "base/sys_info.h"
|
||||
#include "base/threading/worker_pool.h"
|
||||
#include "base/thread_restrictions.h"
|
||||
#include "base/time.h"
|
||||
#include "base/timer.h"
|
||||
#include "base/worker_pool.h"
|
||||
#include "net/base/net_errors.h"
|
||||
#include "net/disk_cache/cache_util.h"
|
||||
#include "net/disk_cache/entry_impl.h"
|
||||
@ -142,7 +142,7 @@ bool DelayedCacheCleanup(const FilePath& full_path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
WorkerPool::PostTask(FROM_HERE, new CleanupTask(path, name_str), true);
|
||||
base::WorkerPool::PostTask(FROM_HERE, new CleanupTask(path, name_str), true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/worker_pool.h"
|
||||
#include "base/threading/worker_pool.h"
|
||||
#include "net/disk_cache/disk_cache.h"
|
||||
#include "net/disk_cache/in_flight_io.h"
|
||||
|
||||
@ -113,7 +113,7 @@ void FileInFlightIO::PostRead(disk_cache::File *file, void* buf, size_t buf_len,
|
||||
new FileBackgroundIO(file, buf, buf_len, offset, callback, this));
|
||||
file->AddRef(); // Balanced on OnOperationComplete()
|
||||
|
||||
WorkerPool::PostTask(FROM_HERE,
|
||||
base::WorkerPool::PostTask(FROM_HERE,
|
||||
NewRunnableMethod(operation.get(), &FileBackgroundIO::Read), true);
|
||||
OnOperationPosted(operation);
|
||||
}
|
||||
@ -125,7 +125,7 @@ void FileInFlightIO::PostWrite(disk_cache::File* file, const void* buf,
|
||||
new FileBackgroundIO(file, buf, buf_len, offset, callback, this));
|
||||
file->AddRef(); // Balanced on OnOperationComplete()
|
||||
|
||||
WorkerPool::PostTask(FROM_HERE,
|
||||
base::WorkerPool::PostTask(FROM_HERE,
|
||||
NewRunnableMethod(operation.get(), &FileBackgroundIO::Write), true);
|
||||
OnOperationPosted(operation);
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include "base/message_loop_proxy.h"
|
||||
#include "base/observer_list.h"
|
||||
#include "base/scoped_ptr.h"
|
||||
#include "base/worker_pool.h"
|
||||
#include "base/threading/worker_pool.h"
|
||||
#include "net/proxy/proxy_config.h"
|
||||
|
||||
namespace net {
|
||||
@ -88,10 +88,10 @@ class PollingProxyConfigService::Core
|
||||
last_poll_time_ = base::TimeTicks::Now();
|
||||
poll_task_outstanding_ = true;
|
||||
poll_task_queued_ = false;
|
||||
WorkerPool::PostTask(
|
||||
base::WorkerPool::PostTask(
|
||||
FROM_HERE,
|
||||
NewRunnableMethod(
|
||||
this, &Core::PollOnWorkerThread, get_config_func_), true);
|
||||
NewRunnableMethod(this, &Core::PollOnWorkerThread, get_config_func_),
|
||||
true);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/simple_thread.h"
|
||||
#include "base/threading/simple_thread.h"
|
||||
#include "base/timer.h"
|
||||
#include "base/lock.h"
|
||||
#include "net/spdy/spdy_frame_builder.h"
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "base/message_loop.h"
|
||||
#include "base/platform_file.h"
|
||||
#include "base/string_util.h"
|
||||
#include "base/threading/worker_pool.h"
|
||||
#include "base/thread_restrictions.h"
|
||||
#include "build/build_config.h"
|
||||
#include "googleurl/src/gurl.h"
|
||||
@ -36,10 +37,6 @@
|
||||
#include "net/url_request/url_request_error_job.h"
|
||||
#include "net/url_request/url_request_file_dir_job.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
#include "base/worker_pool.h"
|
||||
#endif
|
||||
|
||||
namespace net {
|
||||
|
||||
#if defined(OS_WIN)
|
||||
@ -136,7 +133,7 @@ void URLRequestFileJob::Start() {
|
||||
if (!file_path_.value().compare(0, 2, L"\\\\")) {
|
||||
DCHECK(!async_resolver_);
|
||||
async_resolver_ = new AsyncResolver(this);
|
||||
WorkerPool::PostTask(FROM_HERE, NewRunnableMethod(
|
||||
base::WorkerPool::PostTask(FROM_HERE, NewRunnableMethod(
|
||||
async_resolver_.get(), &AsyncResolver::Resolve, file_path_), true);
|
||||
return;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#include "ppapi/proxy/ppb_audio_proxy.h"
|
||||
|
||||
#include "base/simple_thread.h"
|
||||
#include "base/threading/simple_thread.h"
|
||||
#include "ppapi/c/dev/ppb_audio_dev.h"
|
||||
#include "ppapi/c/dev/ppb_audio_trusted_dev.h"
|
||||
#include "ppapi/c/pp_errors.h"
|
||||
|
@ -6,9 +6,9 @@
|
||||
#define PPAPI_SHARED_IMPL_AUDIO_IMPL_H_
|
||||
|
||||
#include "base/scoped_ptr.h"
|
||||
#include "base/simple_thread.h"
|
||||
#include "base/shared_memory.h"
|
||||
#include "base/sync_socket.h"
|
||||
#include "base/threading/simple_thread.h"
|
||||
#include "ppapi/c/dev/ppb_audio_dev.h"
|
||||
|
||||
namespace pp {
|
||||
|
Reference in New Issue
Block a user