summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/resource_bundle.h6
-rw-r--r--base/base.gyp6
-rw-r--r--base/base.gypi17
-rw-r--r--base/crypto/cssm_init.cc8
-rw-r--r--base/crypto/cssm_init.h4
-rw-r--r--base/lock.h125
-rw-r--r--base/logging.cc8
-rw-r--r--base/metrics/histogram.cc20
-rw-r--r--base/metrics/histogram.h5
-rw-r--r--base/nss_util.h2
-rw-r--r--base/synchronization/condition_variable.h (renamed from base/condition_variable.h)16
-rw-r--r--base/synchronization/condition_variable_posix.cc (renamed from base/condition_variable_posix.cc)15
-rw-r--r--base/synchronization/condition_variable_unittest.cc (renamed from base/condition_variable_unittest.cc)31
-rw-r--r--base/synchronization/condition_variable_win.cc (renamed from base/condition_variable_win.cc)18
-rw-r--r--base/synchronization/lock.cc (renamed from base/lock.cc)9
-rw-r--r--base/synchronization/lock.h131
-rw-r--r--base/synchronization/lock_impl.h (renamed from base/lock_impl.h)13
-rw-r--r--base/synchronization/lock_impl_posix.cc (renamed from base/lock_impl_posix.cc)10
-rw-r--r--base/synchronization/lock_impl_win.cc (renamed from base/lock_impl_win.cc)10
-rw-r--r--base/synchronization/lock_unittest.cc (renamed from base/lock_unittest.cc)21
-rw-r--r--base/threading/watchdog.h18
-rw-r--r--base/threading/worker_pool_posix.h4
-rw-r--r--base/threading/worker_pool_posix_unittest.cc2
-rw-r--r--base/waitable_event_posix.cc22
-rw-r--r--base/waitable_event_watcher_posix.cc5
-rw-r--r--chrome/browser/chromeos/login/google_authenticator.cc8
-rw-r--r--chrome/browser/chromeos/login/google_authenticator.h9
-rw-r--r--chrome/browser/chromeos/login/parallel_authenticator.cc12
-rw-r--r--chrome/browser/chromeos/login/parallel_authenticator.h11
-rw-r--r--chrome/browser/metrics/histogram_synchronizer.cc10
-rw-r--r--chrome/browser/metrics/histogram_synchronizer.h8
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_test.cc25
-rw-r--r--chrome/browser/sync/engine/syncer_thread.cc22
-rw-r--r--chrome/browser/sync/engine/syncer_thread.h13
-rw-r--r--chrome/browser/sync/glue/ui_model_worker.cc6
-rw-r--r--chrome/browser/sync/glue/ui_model_worker.h8
-rw-r--r--chrome/browser/sync/syncable/syncable_unittest.cc18
-rw-r--r--chrome/common/deprecated/event_sys-inl.h22
-rw-r--r--chrome/common/deprecated/event_sys.h6
-rw-r--r--chrome/common/deprecated/event_sys_unittest.cc14
-rw-r--r--media/base/pipeline_impl.cc2
-rw-r--r--media/filters/video_renderer_base.h8
-rw-r--r--net/base/dnsrr_resolver_unittest.cc3
-rw-r--r--net/base/listen_socket_unittest.h8
-rw-r--r--net/ocsp/nss_ocsp.cc36
-rw-r--r--net/tools/hresolv/hresolv.cc1
-rw-r--r--o3d/core/cross/message_queue_test.cc12
-rw-r--r--remoting/base/tracer.cc16
48 files changed, 427 insertions, 377 deletions
diff --git a/app/resource_bundle.h b/app/resource_bundle.h
index d2c2d59..abe7205 100644
--- a/app/resource_bundle.h
+++ b/app/resource_bundle.h
@@ -26,13 +26,15 @@
namespace app {
class DataPack;
}
+namespace base {
+class Lock;
+}
#if defined(USE_X11)
typedef struct _GdkPixbuf GdkPixbuf;
#endif
namespace gfx {
class Font;
}
-class Lock;
class SkBitmap;
typedef uint32 SkColor;
namespace base {
@@ -244,7 +246,7 @@ class ResourceBundle {
// Class level lock. Used to protect internal data structures that may be
// accessed from other threads (e.g., skia_images_).
- scoped_ptr<Lock> lock_;
+ scoped_ptr<base::Lock> lock_;
// Handles for data sources.
DataHandle resources_data_;
diff --git a/base/base.gyp b/base/base.gyp
index a86bca0..50a19ee 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -1,4 +1,4 @@
-# Copyright (c) 2010 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.
@@ -67,7 +67,6 @@
'callback_unittest.cc',
'cancellation_flag_unittest.cc',
'command_line_unittest.cc',
- 'condition_variable_unittest.cc',
'crypto/encryptor_unittest.cc',
'crypto/rsa_private_key_unittest.cc',
'crypto/rsa_private_key_nss_unittest.cc',
@@ -97,7 +96,6 @@
'lazy_instance_unittest.cc',
'linked_list_unittest.cc',
'linked_ptr_unittest.cc',
- 'lock_unittest.cc',
'logging_unittest.cc',
'mac/mac_util_unittest.mm',
'message_loop_proxy_impl_unittest.cc',
@@ -132,6 +130,8 @@
'string_util_unittest.cc',
'stringize_macros_unittest.cc',
'stringprintf_unittest.cc',
+ 'synchronization/condition_variable_unittest.cc',
+ 'synchronization/lock_unittest.cc',
'sys_info_unittest.cc',
'sys_string_conversions_mac_unittest.mm',
'sys_string_conversions_unittest.cc',
diff --git a/base/base.gypi b/base/base.gypi
index 53ca3c9..4147e68 100644
--- a/base/base.gypi
+++ b/base/base.gypi
@@ -1,4 +1,4 @@
-# Copyright (c) 2010 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.
@@ -44,9 +44,6 @@
'command_line.cc',
'command_line.h',
'compiler_specific.h',
- 'condition_variable.h',
- 'condition_variable_posix.cc',
- 'condition_variable_win.cc',
'cpu.cc',
'cpu.h',
'debug/debug_on_start_win.cc',
@@ -103,11 +100,7 @@
'lazy_instance.h',
'linked_list.h',
'linked_ptr.h',
- 'lock.cc',
'lock.h',
- 'lock_impl.h',
- 'lock_impl_posix.cc',
- 'lock_impl_win.cc',
'logging.cc',
'logging.h',
'logging_win.cc',
@@ -216,6 +209,14 @@
'stringize_macros.h',
'stringprintf.cc',
'stringprintf.h',
+ 'synchronization/condition_variable.h',
+ 'synchronization/condition_variable_posix.cc',
+ 'synchronization/condition_variable_win.cc',
+ 'synchronization/lock.cc',
+ 'synchronization/lock.h',
+ 'synchronization/lock_impl.h',
+ 'synchronization/lock_impl_posix.cc',
+ 'synchronization/lock_impl_win.cc',
'sys_info.h',
'sys_info_chromeos.cc',
'sys_info_freebsd.cc',
diff --git a/base/crypto/cssm_init.cc b/base/crypto/cssm_init.cc
index 46a6ffe..f588f30 100644
--- a/base/crypto/cssm_init.cc
+++ b/base/crypto/cssm_init.cc
@@ -6,9 +6,9 @@
#include <Security/SecBase.h>
-#include "base/lock.h"
#include "base/logging.h"
#include "base/singleton.h"
+#include "base/synchronization/lock.h"
#include "base/sys_string_conversions.h"
// When writing crypto code for Mac OS X, you may find the following
@@ -92,7 +92,7 @@ class SecurityServicesSingleton {
~SecurityServicesSingleton() {}
- Lock& lock() { return lock_; }
+ base::Lock& lock() { return lock_; }
private:
friend class Singleton<SecurityServicesSingleton>;
@@ -100,7 +100,7 @@ class SecurityServicesSingleton {
SecurityServicesSingleton() {}
- Lock lock_;
+ base::Lock lock_;
DISALLOW_COPY_AND_ASSIGN(SecurityServicesSingleton);
};
@@ -154,7 +154,7 @@ void LogCSSMError(const char *fn_name, CSSM_RETURN err) {
}
}
-Lock& GetMacSecurityServicesLock() {
+base::Lock& GetMacSecurityServicesLock() {
return SecurityServicesSingleton::GetInstance()->lock();
}
diff --git a/base/crypto/cssm_init.h b/base/crypto/cssm_init.h
index e457083..5644d7e 100644
--- a/base/crypto/cssm_init.h
+++ b/base/crypto/cssm_init.h
@@ -10,10 +10,10 @@
#include "base/scoped_ptr.h"
-class Lock;
-
namespace base {
+class Lock;
+
// Initialize CSSM if it isn't already initialized. This must be called before
// any other CSSM functions. This function is thread-safe, and CSSM will only
// ever be initialized once. CSSM will be properly shut down on program exit.
diff --git a/base/lock.h b/base/lock.h
index 672e3fb..7c90d86 100644
--- a/base/lock.h
+++ b/base/lock.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 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.
@@ -6,122 +6,13 @@
#define BASE_LOCK_H_
#pragma once
-#include "base/lock_impl.h"
-#include "base/threading/platform_thread.h"
+// This is a temporary forwarding file so not every user of lock needs to
+// be updated at once.
+// TODO(brettw) remove this and fix everybody up to using the new location.
+#include "base/synchronization/lock.h"
-// A convenient wrapper for an OS specific critical section. The only real
-// intelligence in this class is in debug mode for the support for the
-// AssertAcquired() method.
-
-class Lock {
- public:
-#if defined(NDEBUG) // Optimized wrapper implementation
- Lock() : lock_() {}
- ~Lock() {}
- void Acquire() { lock_.Lock(); }
- void Release() { lock_.Unlock(); }
-
- // If the lock is not held, take it and return true. If the lock is already
- // held by another thread, immediately return false. This must not be called
- // by a thread already holding the lock (what happens is undefined and an
- // assertion may fail).
- bool Try() { return lock_.Try(); }
-
- // Null implementation if not debug.
- void AssertAcquired() const {}
-#else
- Lock();
- ~Lock() {}
-
- // NOTE: Although windows critical sections support recursive locks, we do not
- // allow this, and we will commonly fire a DCHECK() if a thread attempts to
- // acquire the lock a second time (while already holding it).
- void Acquire() {
- lock_.Lock();
- CheckUnheldAndMark();
- }
- void Release() {
- CheckHeldAndUnmark();
- lock_.Unlock();
- }
-
- bool Try() {
- bool rv = lock_.Try();
- if (rv) {
- CheckUnheldAndMark();
- }
- return rv;
- }
-
- void AssertAcquired() const;
-#endif // NDEBUG
-
-#if defined(OS_POSIX)
- // The posix implementation of ConditionVariable needs to be able
- // to see our lock and tweak our debugging counters, as it releases
- // and acquires locks inside of pthread_cond_{timed,}wait.
- // Windows doesn't need to do this as it calls the Lock::* methods.
- friend class ConditionVariable;
-#endif
-
- private:
-#if !defined(NDEBUG)
- // Members and routines taking care of locks assertions.
- // Note that this checks for recursive locks and allows them
- // if the variable is set. This is allowed by the underlying implementation
- // on windows but not on Posix, so we're doing unneeded checks on Posix.
- // It's worth it to share the code.
- void CheckHeldAndUnmark();
- void CheckUnheldAndMark();
-
- // All private data is implicitly protected by lock_.
- // Be VERY careful to only access members under that lock.
-
- // Determines validity of owning_thread_id_. Needed as we don't have
- // a null owning_thread_id_ value.
- bool owned_by_thread_;
- base::PlatformThreadId owning_thread_id_;
-#endif // NDEBUG
-
- LockImpl lock_; // Platform specific underlying lock implementation.
-
- DISALLOW_COPY_AND_ASSIGN(Lock);
-};
-
-// A helper class that acquires the given Lock while the AutoLock is in scope.
-class AutoLock {
- public:
- explicit AutoLock(Lock& lock) : lock_(lock) {
- lock_.Acquire();
- }
-
- ~AutoLock() {
- lock_.AssertAcquired();
- lock_.Release();
- }
-
- private:
- Lock& lock_;
- DISALLOW_COPY_AND_ASSIGN(AutoLock);
-};
-
-// AutoUnlock is a helper that will Release() the |lock| argument in the
-// constructor, and re-Acquire() it in the destructor.
-class AutoUnlock {
- public:
- explicit AutoUnlock(Lock& lock) : lock_(lock) {
- // We require our caller to have the lock.
- lock_.AssertAcquired();
- lock_.Release();
- }
-
- ~AutoUnlock() {
- lock_.Acquire();
- }
-
- private:
- Lock& lock_;
- DISALLOW_COPY_AND_ASSIGN(AutoUnlock);
-};
+using base::AutoLock;
+using base::AutoUnlock;
+using base::Lock;
#endif // BASE_LOCK_H_
diff --git a/base/logging.cc b/base/logging.cc
index 0a8931a..cfb1065 100644
--- a/base/logging.cc
+++ b/base/logging.cc
@@ -50,8 +50,8 @@ typedef pthread_mutex_t* MutexHandle;
#include "base/debug/debugger.h"
#include "base/debug/stack_trace.h"
#include "base/eintr_wrapper.h"
-#include "base/lock_impl.h"
#include "base/string_piece.h"
+#include "base/synchronization/lock_impl.h"
#include "base/utf_string_conversions.h"
#include "base/vlog.h"
#if defined(OS_POSIX)
@@ -243,7 +243,7 @@ class LoggingLock {
}
#endif
} else {
- log_lock = new LockImpl();
+ log_lock = new base::internal::LockImpl();
}
initialized = true;
}
@@ -282,7 +282,7 @@ class LoggingLock {
// The lock is used if log file locking is false. It helps us avoid problems
// with multiple threads writing to the log file at the same time. Use
// LockImpl directly instead of using Lock, because Lock makes logging calls.
- static LockImpl* log_lock;
+ static base::internal::LockImpl* log_lock;
// When we don't use a lock, we are using a global mutex. We need to do this
// because LockFileEx is not thread safe.
@@ -299,7 +299,7 @@ class LoggingLock {
// static
bool LoggingLock::initialized = false;
// static
-LockImpl* LoggingLock::log_lock = NULL;
+base::internal::LockImpl* LoggingLock::log_lock = NULL;
// static
LogLockingState LoggingLock::lock_log_file = LOCK_LOG_FILE;
diff --git a/base/metrics/histogram.cc b/base/metrics/histogram.cc
index 75df12e..1526cd8 100644
--- a/base/metrics/histogram.cc
+++ b/base/metrics/histogram.cc
@@ -14,10 +14,10 @@
#include <algorithm>
#include <string>
-#include "base/lock.h"
#include "base/logging.h"
#include "base/pickle.h"
#include "base/stringprintf.h"
+#include "base/synchronization/lock.h"
namespace base {
@@ -911,9 +911,9 @@ StatisticsRecorder::StatisticsRecorder() {
// during the termination phase. Since it's a static data member, we will
// leak one per process, which would be similar to the instance allocated
// during static initialization and released only on process termination.
- lock_ = new Lock;
+ lock_ = new base::Lock;
}
- AutoLock auto_lock(*lock_);
+ base::AutoLock auto_lock(*lock_);
histograms_ = new HistogramMap;
}
@@ -928,7 +928,7 @@ StatisticsRecorder::~StatisticsRecorder() {
// Clean up.
HistogramMap* histograms = NULL;
{
- AutoLock auto_lock(*lock_);
+ base::AutoLock auto_lock(*lock_);
histograms = histograms_;
histograms_ = NULL;
}
@@ -941,7 +941,7 @@ StatisticsRecorder::~StatisticsRecorder() {
bool StatisticsRecorder::IsActive() {
if (lock_ == NULL)
return false;
- AutoLock auto_lock(*lock_);
+ base::AutoLock auto_lock(*lock_);
return NULL != histograms_;
}
@@ -954,7 +954,7 @@ bool StatisticsRecorder::IsActive() {
void StatisticsRecorder::Register(Histogram* histogram) {
if (lock_ == NULL)
return;
- AutoLock auto_lock(*lock_);
+ base::AutoLock auto_lock(*lock_);
if (!histograms_)
return;
const std::string name = histogram->histogram_name();
@@ -1011,7 +1011,7 @@ void StatisticsRecorder::WriteGraph(const std::string& query,
void StatisticsRecorder::GetHistograms(Histograms* output) {
if (lock_ == NULL)
return;
- AutoLock auto_lock(*lock_);
+ base::AutoLock auto_lock(*lock_);
if (!histograms_)
return;
for (HistogramMap::iterator it = histograms_->begin();
@@ -1026,7 +1026,7 @@ bool StatisticsRecorder::FindHistogram(const std::string& name,
scoped_refptr<Histogram>* histogram) {
if (lock_ == NULL)
return false;
- AutoLock auto_lock(*lock_);
+ base::AutoLock auto_lock(*lock_);
if (!histograms_)
return false;
HistogramMap::iterator it = histograms_->find(name);
@@ -1041,7 +1041,7 @@ void StatisticsRecorder::GetSnapshot(const std::string& query,
Histograms* snapshot) {
if (lock_ == NULL)
return;
- AutoLock auto_lock(*lock_);
+ base::AutoLock auto_lock(*lock_);
if (!histograms_)
return;
for (HistogramMap::iterator it = histograms_->begin();
@@ -1055,7 +1055,7 @@ void StatisticsRecorder::GetSnapshot(const std::string& query,
// static
StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL;
// static
-Lock* StatisticsRecorder::lock_ = NULL;
+base::Lock* StatisticsRecorder::lock_ = NULL;
// static
bool StatisticsRecorder::dump_on_exit_ = false;
diff --git a/base/metrics/histogram.h b/base/metrics/histogram.h
index 6b09aa3..7ab5a77 100644
--- a/base/metrics/histogram.h
+++ b/base/metrics/histogram.h
@@ -41,11 +41,12 @@
#include "base/logging.h"
#include "base/time.h"
-class Lock;
class Pickle;
namespace base {
+class Lock;
+
//------------------------------------------------------------------------------
// Provide easy general purpose histogram in a macro, just like stats counters.
// The first four macros use 50 buckets.
@@ -681,7 +682,7 @@ class StatisticsRecorder {
static HistogramMap* histograms_;
// lock protects access to the above map.
- static Lock* lock_;
+ static base::Lock* lock_;
// Dump all known histograms to log.
static bool dump_on_exit_;
diff --git a/base/nss_util.h b/base/nss_util.h
index d1e36ac..2b0139e 100644
--- a/base/nss_util.h
+++ b/base/nss_util.h
@@ -10,7 +10,6 @@
#if defined(USE_NSS)
class FilePath;
-class Lock;
#endif // defined(USE_NSS)
// This file specifically doesn't depend on any NSS or NSPR headers because it
@@ -18,6 +17,7 @@ class Lock;
// initialization functions.
namespace base {
+class Lock;
class Time;
// Initialize NRPR if it isn't already initialized. This function is
diff --git a/base/condition_variable.h b/base/synchronization/condition_variable.h
index 4fe1892..3acd0ac 100644
--- a/base/condition_variable.h
+++ b/base/synchronization/condition_variable.h
@@ -1,4 +1,4 @@
-// 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.
@@ -62,8 +62,8 @@
// For a discussion of the many very subtle implementation details, see the FAQ
// at the end of condition_variable_win.cc.
-#ifndef BASE_CONDITION_VARIABLE_H_
-#define BASE_CONDITION_VARIABLE_H_
+#ifndef BASE_SYNCHRONIZATION_CONDITION_VARIABLE_H_
+#define BASE_SYNCHRONIZATION_CONDITION_VARIABLE_H_
#pragma once
#include "build/build_config.h"
@@ -78,8 +78,8 @@
#include "base/lock.h"
namespace base {
- class TimeDelta;
-}
+
+class TimeDelta;
class ConditionVariable {
public:
@@ -91,7 +91,7 @@ class ConditionVariable {
// Wait() releases the caller's critical section atomically as it starts to
// sleep, and the reacquires it when it is signaled.
void Wait();
- void TimedWait(const base::TimeDelta& max_time);
+ void TimedWait(const TimeDelta& max_time);
// Broadcast() revives all waiting threads.
void Broadcast();
@@ -184,4 +184,6 @@ class ConditionVariable {
DISALLOW_COPY_AND_ASSIGN(ConditionVariable);
};
-#endif // BASE_CONDITION_VARIABLE_H_
+} // namespace base
+
+#endif // BASE_SYNCHRONIZATION_CONDITION_VARIABLE_H_
diff --git a/base/condition_variable_posix.cc b/base/synchronization/condition_variable_posix.cc
index 5d9ccb4..eff7053 100644
--- a/base/condition_variable_posix.cc
+++ b/base/synchronization/condition_variable_posix.cc
@@ -1,23 +1,22 @@
-// 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.
-#include "base/condition_variable.h"
+#include "base/synchronization/condition_variable.h"
#include <errno.h>
#include <sys/time.h>
-#include "base/lock.h"
#include "base/logging.h"
+#include "base/synchronization/lock.h"
#include "base/time.h"
-using base::Time;
-using base::TimeDelta;
+namespace base {
ConditionVariable::ConditionVariable(Lock* user_lock)
- : user_mutex_(user_lock->lock_.os_lock())
+ : user_mutex_(user_lock->lock_.os_lock())
#if !defined(NDEBUG)
- , user_lock_(user_lock)
+ , user_lock_(user_lock)
#endif
{
int rv = pthread_cond_init(&condition_, NULL);
@@ -74,3 +73,5 @@ void ConditionVariable::Signal() {
int rv = pthread_cond_signal(&condition_);
DCHECK(rv == 0);
}
+
+} // namespace base
diff --git a/base/condition_variable_unittest.cc b/base/synchronization/condition_variable_unittest.cc
index 18c9f2d19..8cfe4fe 100644
--- a/base/condition_variable_unittest.cc
+++ b/base/synchronization/condition_variable_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 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.
@@ -8,7 +8,7 @@
#include <algorithm>
#include <vector>
-#include "base/condition_variable.h"
+#include "base/synchronization/condition_variable.h"
#include "base/lock.h"
#include "base/logging.h"
#include "base/scoped_ptr.h"
@@ -19,10 +19,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
-using base::PlatformThread;
-using base::PlatformThreadHandle;
-using base::TimeDelta;
-using base::TimeTicks;
+namespace base {
namespace {
//------------------------------------------------------------------------------
@@ -39,12 +36,12 @@ class ConditionVariableTest : public PlatformTest {
const TimeDelta kOneHundredMs;
explicit ConditionVariableTest()
- : kZeroMs(TimeDelta::FromMilliseconds(0)),
- kTenMs(TimeDelta::FromMilliseconds(10)),
- kThirtyMs(TimeDelta::FromMilliseconds(30)),
- kFortyFiveMs(TimeDelta::FromMilliseconds(45)),
- kSixtyMs(TimeDelta::FromMilliseconds(60)),
- kOneHundredMs(TimeDelta::FromMilliseconds(100)) {
+ : kZeroMs(TimeDelta::FromMilliseconds(0)),
+ kTenMs(TimeDelta::FromMilliseconds(10)),
+ kThirtyMs(TimeDelta::FromMilliseconds(30)),
+ kFortyFiveMs(TimeDelta::FromMilliseconds(45)),
+ kSixtyMs(TimeDelta::FromMilliseconds(60)),
+ kOneHundredMs(TimeDelta::FromMilliseconds(100)) {
}
};
@@ -198,7 +195,7 @@ TEST_F(ConditionVariableTest, MultiThreadConsumerTest) {
const int kTaskCount = 10; // Number of tasks in each mini-test here.
- base::Time start_time; // Used to time task processing.
+ Time start_time; // Used to time task processing.
{
AutoLock auto_lock(*queue.lock());
@@ -226,7 +223,7 @@ TEST_F(ConditionVariableTest, MultiThreadConsumerTest) {
queue.SetWorkTime(kThirtyMs);
queue.SetAllowHelp(false);
- start_time = base::Time::Now();
+ start_time = Time::Now();
}
queue.work_is_available()->Signal(); // Start up one thread.
@@ -241,7 +238,7 @@ TEST_F(ConditionVariableTest, MultiThreadConsumerTest) {
// The last of the tasks *might* still be running, but... all but one should
// be done by now, since tasks are being done serially.
EXPECT_LE(queue.GetWorkTime().InMilliseconds() * (kTaskCount - 1),
- (base::Time::Now() - start_time).InMilliseconds());
+ (Time::Now() - start_time).InMilliseconds());
EXPECT_EQ(1, queue.GetNumThreadsTakingAssignments());
EXPECT_EQ(1, queue.GetNumThreadsCompletingTasks());
@@ -270,7 +267,7 @@ TEST_F(ConditionVariableTest, MultiThreadConsumerTest) {
queue.SetWorkTime(kThirtyMs);
queue.SetAllowHelp(true);
- start_time = base::Time::Now();
+ start_time = Time::Now();
}
queue.work_is_available()->Signal(); // But each worker can signal another.
@@ -749,3 +746,5 @@ void WorkQueue::ThreadMain() {
}
} // namespace
+
+} // namespace base
diff --git a/base/condition_variable_win.cc b/base/synchronization/condition_variable_win.cc
index 5150c23..3030178 100644
--- a/base/condition_variable_win.cc
+++ b/base/synchronization/condition_variable_win.cc
@@ -1,22 +1,22 @@
-// 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.
-#include "base/condition_variable.h"
+#include "base/synchronization/condition_variable.h"
#include <stack>
-#include "base/lock.h"
#include "base/logging.h"
+#include "base/synchronization/lock.h"
#include "base/time.h"
-using base::TimeDelta;
+namespace base {
ConditionVariable::ConditionVariable(Lock* user_lock)
- : user_lock_(*user_lock),
- run_state_(RUNNING),
- allocation_counter_(0),
- recycling_list_size_(0) {
+ : user_lock_(*user_lock),
+ run_state_(RUNNING),
+ allocation_counter_(0),
+ recycling_list_size_(0) {
DCHECK(user_lock);
}
@@ -443,3 +443,5 @@ put so many assertions (DCHECKs) into the container class that it is trivial to
code review and validate its correctness.
*/
+
+} // namespace base
diff --git a/base/lock.cc b/base/synchronization/lock.cc
index dc21271..6445ce8 100644
--- a/base/lock.cc
+++ b/base/synchronization/lock.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 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.
@@ -8,11 +8,10 @@
#if !defined(NDEBUG)
-#include "base/lock.h"
+#include "base/synchronization/lock.h"
#include "base/logging.h"
-using base::PlatformThread;
-using base::PlatformThreadId;
+namespace base {
Lock::Lock() : lock_() {
owned_by_thread_ = false;
@@ -37,4 +36,6 @@ void Lock::CheckUnheldAndMark() {
owning_thread_id_ = PlatformThread::CurrentId();
}
+} // namespace base
+
#endif // NDEBUG
diff --git a/base/synchronization/lock.h b/base/synchronization/lock.h
new file mode 100644
index 0000000..f7c9c49
--- /dev/null
+++ b/base/synchronization/lock.h
@@ -0,0 +1,131 @@
+// 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.
+
+#ifndef BASE_SYNCHRONIZATION_LOCK_H_
+#define BASE_SYNCHRONIZATION_LOCK_H_
+#pragma once
+
+#include "base/synchronization/lock_impl.h"
+#include "base/threading/platform_thread.h"
+
+namespace base {
+
+// A convenient wrapper for an OS specific critical section. The only real
+// intelligence in this class is in debug mode for the support for the
+// AssertAcquired() method.
+class Lock {
+ public:
+#if defined(NDEBUG) // Optimized wrapper implementation
+ Lock() : lock_() {}
+ ~Lock() {}
+ void Acquire() { lock_.Lock(); }
+ void Release() { lock_.Unlock(); }
+
+ // If the lock is not held, take it and return true. If the lock is already
+ // held by another thread, immediately return false. This must not be called
+ // by a thread already holding the lock (what happens is undefined and an
+ // assertion may fail).
+ bool Try() { return lock_.Try(); }
+
+ // Null implementation if not debug.
+ void AssertAcquired() const {}
+#else
+ Lock();
+ ~Lock() {}
+
+ // NOTE: Although windows critical sections support recursive locks, we do not
+ // allow this, and we will commonly fire a DCHECK() if a thread attempts to
+ // acquire the lock a second time (while already holding it).
+ void Acquire() {
+ lock_.Lock();
+ CheckUnheldAndMark();
+ }
+ void Release() {
+ CheckHeldAndUnmark();
+ lock_.Unlock();
+ }
+
+ bool Try() {
+ bool rv = lock_.Try();
+ if (rv) {
+ CheckUnheldAndMark();
+ }
+ return rv;
+ }
+
+ void AssertAcquired() const;
+#endif // NDEBUG
+
+#if defined(OS_POSIX)
+ // The posix implementation of ConditionVariable needs to be able
+ // to see our lock and tweak our debugging counters, as it releases
+ // and acquires locks inside of pthread_cond_{timed,}wait.
+ // Windows doesn't need to do this as it calls the Lock::* methods.
+ friend class ConditionVariable;
+#endif
+
+ private:
+#if !defined(NDEBUG)
+ // Members and routines taking care of locks assertions.
+ // Note that this checks for recursive locks and allows them
+ // if the variable is set. This is allowed by the underlying implementation
+ // on windows but not on Posix, so we're doing unneeded checks on Posix.
+ // It's worth it to share the code.
+ void CheckHeldAndUnmark();
+ void CheckUnheldAndMark();
+
+ // All private data is implicitly protected by lock_.
+ // Be VERY careful to only access members under that lock.
+
+ // Determines validity of owning_thread_id_. Needed as we don't have
+ // a null owning_thread_id_ value.
+ bool owned_by_thread_;
+ base::PlatformThreadId owning_thread_id_;
+#endif // NDEBUG
+
+ // Platform specific underlying lock implementation.
+ internal::LockImpl lock_;
+
+ DISALLOW_COPY_AND_ASSIGN(Lock);
+};
+
+// A helper class that acquires the given Lock while the AutoLock is in scope.
+class AutoLock {
+ public:
+ explicit AutoLock(Lock& lock) : lock_(lock) {
+ lock_.Acquire();
+ }
+
+ ~AutoLock() {
+ lock_.AssertAcquired();
+ lock_.Release();
+ }
+
+ private:
+ Lock& lock_;
+ DISALLOW_COPY_AND_ASSIGN(AutoLock);
+};
+
+// AutoUnlock is a helper that will Release() the |lock| argument in the
+// constructor, and re-Acquire() it in the destructor.
+class AutoUnlock {
+ public:
+ explicit AutoUnlock(Lock& lock) : lock_(lock) {
+ // We require our caller to have the lock.
+ lock_.AssertAcquired();
+ lock_.Release();
+ }
+
+ ~AutoUnlock() {
+ lock_.Acquire();
+ }
+
+ private:
+ Lock& lock_;
+ DISALLOW_COPY_AND_ASSIGN(AutoUnlock);
+};
+
+} // namespace base
+
+#endif // BASE_SYNCHRONIZATION_LOCK_H_
diff --git a/base/lock_impl.h b/base/synchronization/lock_impl.h
index 6066495..2994610 100644
--- a/base/lock_impl.h
+++ b/base/synchronization/lock_impl.h
@@ -1,9 +1,9 @@
-// Copyright (c) 2010 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.
-#ifndef BASE_LOCK_IMPL_H_
-#define BASE_LOCK_IMPL_H_
+#ifndef BASE_SYNCHRONIZATION_LOCK_IMPL_H_
+#define BASE_SYNCHRONIZATION_LOCK_IMPL_H_
#pragma once
#include "build/build_config.h"
@@ -16,6 +16,9 @@
#include "base/basictypes.h"
+namespace base {
+namespace internal {
+
// This class implements the underlying platform-specific spin-lock mechanism
// used for the Lock class. Most users should not use LockImpl directly, but
// should instead use Lock.
@@ -54,5 +57,7 @@ class LockImpl {
DISALLOW_COPY_AND_ASSIGN(LockImpl);
};
+} // namespace internal
+} // namespace base
-#endif // BASE_LOCK_IMPL_H_
+#endif // BASE_SYNCHRONIZATION_LOCK_IMPL_H_
diff --git a/base/lock_impl_posix.cc b/base/synchronization/lock_impl_posix.cc
index 355149f..f638fcd 100644
--- a/base/lock_impl_posix.cc
+++ b/base/synchronization/lock_impl_posix.cc
@@ -1,13 +1,16 @@
-// 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.
-#include "base/lock_impl.h"
+#include "base/synchronization/lock_impl.h"
#include <errno.h>
#include "base/logging.h"
+namespace base {
+namespace internal {
+
LockImpl::LockImpl() {
#ifndef NDEBUG
// In debug, setup attributes for lock error checking.
@@ -46,3 +49,6 @@ void LockImpl::Unlock() {
int rv = pthread_mutex_unlock(&os_lock_);
DCHECK_EQ(rv, 0);
}
+
+} // namespace internal
+} // namespace base
diff --git a/base/lock_impl_win.cc b/base/synchronization/lock_impl_win.cc
index 8c03b61..bb8a23d 100644
--- a/base/lock_impl_win.cc
+++ b/base/synchronization/lock_impl_win.cc
@@ -1,8 +1,11 @@
-// Copyright (c) 2010 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.
-#include "base/lock_impl.h"
+#include "base/synchronization/lock_impl.h"
+
+namespace base {
+namespace internal {
LockImpl::LockImpl() {
// The second parameter is the spin count, for short-held locks it avoid the
@@ -28,3 +31,6 @@ void LockImpl::Lock() {
void LockImpl::Unlock() {
::LeaveCriticalSection(&os_lock_);
}
+
+} // namespace internal
+} // namespace base
diff --git a/base/lock_unittest.cc b/base/synchronization/lock_unittest.cc
index a0a8d48..5ac3e6b 100644
--- a/base/lock_unittest.cc
+++ b/base/synchronization/lock_unittest.cc
@@ -1,19 +1,14 @@
-// Copyright (c) 2010 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.
-#include "base/lock.h"
-
#include <stdlib.h>
+#include "base/synchronization/lock.h"
#include "base/threading/platform_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
-using base::kNullThreadHandle;
-using base::PlatformThread;
-using base::PlatformThreadHandle;
-
-typedef testing::Test LockTest;
+namespace base {
// Basic test to make sure that Acquire()/Release()/Try() don't crash ----------
@@ -51,7 +46,7 @@ class BasicLockTestThread : public PlatformThread::Delegate {
DISALLOW_COPY_AND_ASSIGN(BasicLockTestThread);
};
-TEST_F(LockTest, Basic) {
+TEST(LockTest, Basic) {
Lock lock;
BasicLockTestThread thread(&lock);
PlatformThreadHandle handle = kNullThreadHandle;
@@ -111,7 +106,7 @@ class TryLockTestThread : public PlatformThread::Delegate {
DISALLOW_COPY_AND_ASSIGN(TryLockTestThread);
};
-TEST_F(LockTest, TryLock) {
+TEST(LockTest, TryLock) {
Lock lock;
ASSERT_TRUE(lock.Try());
@@ -176,7 +171,7 @@ class MutexLockTestThread : public PlatformThread::Delegate {
DISALLOW_COPY_AND_ASSIGN(MutexLockTestThread);
};
-TEST_F(LockTest, MutexTwoThreads) {
+TEST(LockTest, MutexTwoThreads) {
Lock lock;
int value = 0;
@@ -192,7 +187,7 @@ TEST_F(LockTest, MutexTwoThreads) {
EXPECT_EQ(2 * 40, value);
}
-TEST_F(LockTest, MutexFourThreads) {
+TEST(LockTest, MutexFourThreads) {
Lock lock;
int value = 0;
@@ -215,3 +210,5 @@ TEST_F(LockTest, MutexFourThreads) {
EXPECT_EQ(4 * 40, value);
}
+
+} // namespace base
diff --git a/base/threading/watchdog.h b/base/threading/watchdog.h
index 8641f04..bf95639 100644
--- a/base/threading/watchdog.h
+++ b/base/threading/watchdog.h
@@ -21,8 +21,8 @@
#include <string>
-#include "base/condition_variable.h"
-#include "base/lock.h"
+#include "base/synchronization/condition_variable.h"
+#include "base/synchronization/lock.h"
#include "base/threading/platform_thread.h"
#include "base/time.h"
@@ -31,15 +31,15 @@ namespace base {
class Watchdog {
public:
// Constructor specifies how long the Watchdog will wait before alarming.
- Watchdog(const base::TimeDelta& duration,
+ Watchdog(const TimeDelta& duration,
const std::string& thread_watched_name,
bool enabled);
virtual ~Watchdog();
// Start timing, and alarm when time expires (unless we're disarm()ed.)
void Arm(); // Arm starting now.
- void ArmSomeTimeDeltaAgo(const base::TimeDelta& time_delta);
- void ArmAtStartTime(const base::TimeTicks start_time);
+ void ArmSomeTimeDeltaAgo(const TimeDelta& time_delta);
+ void ArmAtStartTime(const TimeTicks start_time);
// Reset time, and do not set off the alarm.
void Disarm();
@@ -71,12 +71,12 @@ class Watchdog {
Lock lock_; // Mutex for state_.
ConditionVariable condition_variable_;
State state_;
- const base::TimeDelta duration_; // How long after start_time_ do we alarm?
+ const TimeDelta duration_; // How long after start_time_ do we alarm?
const std::string thread_watched_name_;
PlatformThreadHandle handle_;
ThreadDelegate delegate_; // Store it, because it must outlive the thread.
- base::TimeTicks start_time_; // Start of epoch, and alarm after duration_.
+ TimeTicks start_time_; // Start of epoch, and alarm after duration_.
// When the debugger breaks (when we alarm), all the other alarms that are
// armed will expire (also alarm). To diminish this effect, we track any
@@ -86,9 +86,9 @@ class Watchdog {
// on alarms from callers that specify old times.
static Lock static_lock_; // Lock for access of static data...
// When did we last alarm and get stuck (for a while) in a debugger?
- static base::TimeTicks last_debugged_alarm_time_;
+ static TimeTicks last_debugged_alarm_time_;
// How long did we sit on a break in the debugger?
- static base::TimeDelta last_debugged_alarm_delay_;
+ static TimeDelta last_debugged_alarm_delay_;
DISALLOW_COPY_AND_ASSIGN(Watchdog);
};
diff --git a/base/threading/worker_pool_posix.h b/base/threading/worker_pool_posix.h
index 44f0208..1b68aef 100644
--- a/base/threading/worker_pool_posix.h
+++ b/base/threading/worker_pool_posix.h
@@ -29,10 +29,10 @@
#include <string>
#include "base/basictypes.h"
-#include "base/condition_variable.h"
-#include "base/lock.h"
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
+#include "base/synchronization/condition_variable.h"
+#include "base/synchronization/lock.h"
#include "base/threading/platform_thread.h"
class Task;
diff --git a/base/threading/worker_pool_posix_unittest.cc b/base/threading/worker_pool_posix_unittest.cc
index 25509bf..9be82c0 100644
--- a/base/threading/worker_pool_posix_unittest.cc
+++ b/base/threading/worker_pool_posix_unittest.cc
@@ -6,8 +6,8 @@
#include <set>
-#include "base/condition_variable.h"
#include "base/lock.h"
+#include "base/synchronization/condition_variable.h"
#include "base/task.h"
#include "base/threading/platform_thread.h"
#include "base/waitable_event.h"
diff --git a/base/waitable_event_posix.cc b/base/waitable_event_posix.cc
index adc521e..f6a6aab 100644
--- a/base/waitable_event_posix.cc
+++ b/base/waitable_event_posix.cc
@@ -1,11 +1,11 @@
-// 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.
#include "base/waitable_event.h"
-#include "base/condition_variable.h"
-#include "base/lock.h"
+#include "base/synchronization/condition_variable.h"
+#include "base/synchronization/lock.h"
#include "base/message_loop.h"
// -----------------------------------------------------------------------------
@@ -42,12 +42,12 @@ WaitableEvent::~WaitableEvent() {
}
void WaitableEvent::Reset() {
- AutoLock locked(kernel_->lock_);
+ base::AutoLock locked(kernel_->lock_);
kernel_->signaled_ = false;
}
void WaitableEvent::Signal() {
- AutoLock locked(kernel_->lock_);
+ base::AutoLock locked(kernel_->lock_);
if (kernel_->signaled_)
return;
@@ -64,7 +64,7 @@ void WaitableEvent::Signal() {
}
bool WaitableEvent::IsSignaled() {
- AutoLock locked(kernel_->lock_);
+ base::AutoLock locked(kernel_->lock_);
const bool result = kernel_->signaled_;
if (result && !kernel_->manual_reset_)
@@ -89,7 +89,7 @@ class SyncWaiter : public WaitableEvent::Waiter {
}
bool Fire(WaitableEvent* signaling_event) {
- AutoLock locked(lock_);
+ base::AutoLock locked(lock_);
if (fired_)
return false;
@@ -134,19 +134,19 @@ class SyncWaiter : public WaitableEvent::Waiter {
fired_ = true;
}
- Lock* lock() {
+ base::Lock* lock() {
return &lock_;
}
- ConditionVariable* cv() {
+ base::ConditionVariable* cv() {
return &cv_;
}
private:
bool fired_;
WaitableEvent* signaling_event_; // The WaitableEvent which woke us
- Lock lock_;
- ConditionVariable cv_;
+ base::Lock lock_;
+ base::ConditionVariable cv_;
};
bool WaitableEvent::TimedWait(const TimeDelta& max_time) {
diff --git a/base/waitable_event_watcher_posix.cc b/base/waitable_event_watcher_posix.cc
index 07ae694..148caaa 100644
--- a/base/waitable_event_watcher_posix.cc
+++ b/base/waitable_event_watcher_posix.cc
@@ -1,12 +1,11 @@
-// 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.
#include "base/waitable_event_watcher.h"
-#include "base/condition_variable.h"
-#include "base/lock.h"
#include "base/message_loop.h"
+#include "base/synchronization/lock.h"
#include "base/waitable_event.h"
namespace base {
diff --git a/chrome/browser/chromeos/login/google_authenticator.cc b/chrome/browser/chromeos/login/google_authenticator.cc
index 4fa405d..b3d6311 100644
--- a/chrome/browser/chromeos/login/google_authenticator.cc
+++ b/chrome/browser/chromeos/login/google_authenticator.cc
@@ -9,11 +9,11 @@
#include "base/file_path.h"
#include "base/file_util.h"
-#include "base/lock.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/sha2.h"
#include "base/string_util.h"
+#include "base/synchronization/lock.h"
#include "base/third_party/nss/blapi.h"
#include "base/third_party/nss/sha256.h"
#include "chrome/browser/browser_thread.h"
@@ -315,7 +315,7 @@ void GoogleAuthenticator::CheckOffline(const LoginFailure& error) {
void GoogleAuthenticator::CheckLocalaccount(const LoginFailure& error) {
{
- AutoLock for_this_block(localaccount_lock_);
+ base::AutoLock for_this_block(localaccount_lock_);
VLOG(1) << "Checking localaccount";
if (!checked_for_localaccount_) {
BrowserThread::PostDelayedTask(
@@ -401,7 +401,7 @@ void GoogleAuthenticator::LoadSystemSalt() {
void GoogleAuthenticator::LoadLocalaccount(const std::string& filename) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
{
- AutoLock for_this_block(localaccount_lock_);
+ base::AutoLock for_this_block(localaccount_lock_);
if (checked_for_localaccount_)
return;
}
@@ -423,7 +423,7 @@ void GoogleAuthenticator::LoadLocalaccount(const std::string& filename) {
void GoogleAuthenticator::SetLocalaccount(const std::string& new_name) {
localaccount_ = new_name;
{ // extra braces for clarity about AutoLock scope.
- AutoLock for_this_block(localaccount_lock_);
+ base::AutoLock for_this_block(localaccount_lock_);
checked_for_localaccount_ = true;
}
}
diff --git a/chrome/browser/chromeos/login/google_authenticator.h b/chrome/browser/chromeos/login/google_authenticator.h
index d0651fa..a91c73c 100644
--- a/chrome/browser/chromeos/login/google_authenticator.h
+++ b/chrome/browser/chromeos/login/google_authenticator.h
@@ -20,11 +20,14 @@
// Authenticates a Chromium OS user against the Google Accounts ClientLogin API.
-class Lock;
class Profile;
class GoogleServiceAuthError;
class LoginFailure;
+namespace base {
+class Lock;
+}
+
namespace chromeos {
class GoogleAuthenticatorTest;
@@ -194,8 +197,8 @@ class GoogleAuthenticator : public Authenticator, public GaiaAuthConsumer {
bool try_again_; // True if we're willing to retry the login attempt.
std::string localaccount_;
- bool checked_for_localaccount_; // needed because empty localaccount_ is ok.
- Lock localaccount_lock_; // a lock around checked_for_localaccount_.
+ bool checked_for_localaccount_; // Needed because empty localaccount_ is ok.
+ base::Lock localaccount_lock_; // A lock around checked_for_localaccount_.
friend class GoogleAuthenticatorTest;
FRIEND_TEST_ALL_PREFIXES(GoogleAuthenticatorTest, SaltToAscii);
diff --git a/chrome/browser/chromeos/login/parallel_authenticator.cc b/chrome/browser/chromeos/login/parallel_authenticator.cc
index 9cb025c..e8bd65a 100644
--- a/chrome/browser/chromeos/login/parallel_authenticator.cc
+++ b/chrome/browser/chromeos/login/parallel_authenticator.cc
@@ -9,11 +9,11 @@
#include "base/file_path.h"
#include "base/file_util.h"
-#include "base/lock.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/sha2.h"
#include "base/string_util.h"
+#include "base/synchronization/lock.h"
#include "base/third_party/nss/blapi.h"
#include "base/third_party/nss/sha256.h"
#include "chrome/browser/browser_thread.h"
@@ -139,7 +139,7 @@ void ParallelAuthenticator::OnLoginSuccess(
NotificationService::AllSources(),
Details<AuthenticationNotificationDetails>(&details));
{
- AutoLock for_this_block(success_lock_);
+ base::AutoLock for_this_block(success_lock_);
already_reported_success_ = true;
}
consumer_->OnLoginSuccess(current_state_->username,
@@ -167,7 +167,7 @@ void ParallelAuthenticator::OnPasswordChangeDetected(
void ParallelAuthenticator::CheckLocalaccount(const LoginFailure& error) {
{
- AutoLock for_this_block(localaccount_lock_);
+ base::AutoLock for_this_block(localaccount_lock_);
VLOG(2) << "Checking localaccount";
if (!checked_for_localaccount_) {
BrowserThread::PostDelayedTask(
@@ -335,7 +335,7 @@ void ParallelAuthenticator::Resolve() {
// the 'changed password' path when we know doing so won't succeed.
case NEED_NEW_PW:
{
- AutoLock for_this_block(success_lock_);
+ base::AutoLock for_this_block(success_lock_);
if (!already_reported_success_) {
// This allows us to present the same behavior for "online:
// fail, offline: ok", regardless of the order in which we
@@ -548,7 +548,7 @@ void ParallelAuthenticator::LoadSystemSalt() {
void ParallelAuthenticator::LoadLocalaccount(const std::string& filename) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
{
- AutoLock for_this_block(localaccount_lock_);
+ base::AutoLock for_this_block(localaccount_lock_);
if (checked_for_localaccount_)
return;
}
@@ -570,7 +570,7 @@ void ParallelAuthenticator::LoadLocalaccount(const std::string& filename) {
void ParallelAuthenticator::SetLocalaccount(const std::string& new_name) {
localaccount_ = new_name;
{ // extra braces for clarity about AutoLock scope.
- AutoLock for_this_block(localaccount_lock_);
+ base::AutoLock for_this_block(localaccount_lock_);
checked_for_localaccount_ = true;
}
}
diff --git a/chrome/browser/chromeos/login/parallel_authenticator.h b/chrome/browser/chromeos/login/parallel_authenticator.h
index 997f252..4db578f 100644
--- a/chrome/browser/chromeos/login/parallel_authenticator.h
+++ b/chrome/browser/chromeos/login/parallel_authenticator.h
@@ -24,10 +24,13 @@
#include "chrome/common/net/gaia/gaia_auth_consumer.h"
class GaiaAuthFetcher;
-class Lock;
class LoginFailure;
class Profile;
+namespace base {
+class Lock;
+}
+
namespace chromeos {
class LoginStatusConsumer;
@@ -256,12 +259,12 @@ class ParallelAuthenticator : public Authenticator,
// This allows us to present the same behavior to the caller, regardless
// of the order in which we receive these results.
bool already_reported_success_;
- Lock success_lock_; // a lock around already_reported_success_.
+ base::Lock success_lock_; // A lock around already_reported_success_.
// Status relating to the local "backdoor" account.
std::string localaccount_;
- bool checked_for_localaccount_; // needed because empty localaccount_ is ok.
- Lock localaccount_lock_; // a lock around checked_for_localaccount_.
+ bool checked_for_localaccount_; // Needed because empty localaccount_ is ok.
+ base::Lock localaccount_lock_; // A lock around checked_for_localaccount_.
friend class ResolveChecker;
friend class ParallelAuthenticatorTest;
diff --git a/chrome/browser/metrics/histogram_synchronizer.cc b/chrome/browser/metrics/histogram_synchronizer.cc
index a44b738..c383594 100644
--- a/chrome/browser/metrics/histogram_synchronizer.cc
+++ b/chrome/browser/metrics/histogram_synchronizer.cc
@@ -57,7 +57,7 @@ void HistogramSynchronizer::FetchRendererHistogramsSynchronously(
TimeTicks end_time = start + wait_time;
int unresponsive_renderer_count;
{
- AutoLock auto_lock(lock_);
+ base::AutoLock auto_lock(lock_);
while (synchronous_renderers_pending_ > 0 && TimeTicks::Now() < end_time) {
wait_time = end_time - TimeTicks::Now();
received_all_renderer_histograms_.TimedWait(wait_time);
@@ -154,7 +154,7 @@ void HistogramSynchronizer::DecrementPendingRenderers(int sequence_number) {
bool asynchronous_completed = false;
{
- AutoLock auto_lock(lock_);
+ base::AutoLock auto_lock(lock_);
if (sequence_number == async_sequence_number_) {
if (--async_renderers_pending_ <= 0)
asynchronous_completed = true;
@@ -179,7 +179,7 @@ void HistogramSynchronizer::SetCallbackTaskAndThread(
int unresponsive_renderers;
const TimeTicks now = TimeTicks::Now();
{
- AutoLock auto_lock(lock_);
+ base::AutoLock auto_lock(lock_);
old_task = callback_task_;
callback_task_ = callback_task;
old_thread = callback_thread_;
@@ -202,7 +202,7 @@ void HistogramSynchronizer::ForceHistogramSynchronizationDoneCallback(
TimeTicks started;
int unresponsive_renderers;
{
- AutoLock lock(lock_);
+ base::AutoLock lock(lock_);
if (sequence_number != async_sequence_number_)
return;
task = callback_task_;
@@ -233,7 +233,7 @@ void HistogramSynchronizer::InternalPostTask(MessageLoop* thread, Task* task,
int HistogramSynchronizer::GetNextAvailableSequenceNumber(
RendererHistogramRequester requester,
int renderer_count) {
- AutoLock auto_lock(lock_);
+ base::AutoLock auto_lock(lock_);
++last_used_sequence_number_;
// Watch out for wrapping to a negative number.
if (last_used_sequence_number_ < 0) {
diff --git a/chrome/browser/metrics/histogram_synchronizer.h b/chrome/browser/metrics/histogram_synchronizer.h
index 2f75a63..222a403 100644
--- a/chrome/browser/metrics/histogram_synchronizer.h
+++ b/chrome/browser/metrics/histogram_synchronizer.h
@@ -10,9 +10,9 @@
#include <vector>
#include "base/basictypes.h"
-#include "base/condition_variable.h"
-#include "base/lock.h"
#include "base/ref_counted.h"
+#include "base/synchronization/condition_variable.h"
+#include "base/synchronization/lock.h"
#include "base/time.h"
class MessageLoop;
@@ -120,11 +120,11 @@ class HistogramSynchronizer : public
int unresponsive_renderers, const base::TimeTicks& started);
// This lock_ protects access to all members.
- Lock lock_;
+ base::Lock lock_;
// This condition variable is used to block caller of the synchronous request
// to update histograms, and to signal that thread when updates are completed.
- ConditionVariable received_all_renderer_histograms_;
+ base::ConditionVariable received_all_renderer_histograms_;
// When a request is made to asynchronously update the histograms, we store
// the task and thread we use to post a completion notification in
diff --git a/chrome/browser/safe_browsing/safe_browsing_test.cc b/chrome/browser/safe_browsing/safe_browsing_test.cc
index 662eb5d..7cc8f86e 100644
--- a/chrome/browser/safe_browsing/safe_browsing_test.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_test.cc
@@ -17,14 +17,13 @@
#include <vector>
#include "base/command_line.h"
-#include "base/condition_variable.h"
#include "base/environment.h"
-#include "base/lock.h"
#include "base/path_service.h"
#include "base/process_util.h"
#include "base/string_number_conversions.h"
#include "base/string_util.h"
#include "base/string_split.h"
+#include "base/synchronization/lock.h"
#include "base/threading/platform_thread.h"
#include "base/time.h"
#include "base/utf_string_conversions.h"
@@ -207,7 +206,7 @@ class SafeBrowsingServiceTest : public InProcessBrowserTest {
void UpdateSafeBrowsingStatus() {
ASSERT_TRUE(safe_browsing_service_);
- AutoLock lock(update_status_mutex_);
+ base::AutoLock lock(update_status_mutex_);
is_initial_request_ =
safe_browsing_service_->protocol_manager_->is_initial_request();
last_update_ = safe_browsing_service_->protocol_manager_->last_update();
@@ -221,14 +220,14 @@ class SafeBrowsingServiceTest : public InProcessBrowserTest {
}
void CheckIsDatabaseReady() {
- AutoLock lock(update_status_mutex_);
+ base::AutoLock lock(update_status_mutex_);
is_database_ready_ =
!safe_browsing_service_->database_update_in_progress_;
}
void CheckUrl(SafeBrowsingService::Client* helper, const GURL& url) {
ASSERT_TRUE(safe_browsing_service_);
- AutoLock lock(update_status_mutex_);
+ base::AutoLock lock(update_status_mutex_);
if (safe_browsing_service_->CheckBrowseUrl(url, helper)) {
is_checked_url_in_db_ = false;
is_checked_url_safe_ = true;
@@ -241,37 +240,37 @@ class SafeBrowsingServiceTest : public InProcessBrowserTest {
}
bool is_checked_url_in_db() {
- AutoLock l(update_status_mutex_);
+ base::AutoLock l(update_status_mutex_);
return is_checked_url_in_db_;
}
void set_is_checked_url_safe(bool safe) {
- AutoLock l(update_status_mutex_);
+ base::AutoLock l(update_status_mutex_);
is_checked_url_safe_ = safe;
}
bool is_checked_url_safe() {
- AutoLock l(update_status_mutex_);
+ base::AutoLock l(update_status_mutex_);
return is_checked_url_safe_;
}
bool is_database_ready() {
- AutoLock l(update_status_mutex_);
+ base::AutoLock l(update_status_mutex_);
return is_database_ready_;
}
bool is_initial_request() {
- AutoLock l(update_status_mutex_);
+ base::AutoLock l(update_status_mutex_);
return is_initial_request_;
}
base::Time last_update() {
- AutoLock l(update_status_mutex_);
+ base::AutoLock l(update_status_mutex_);
return last_update_;
}
bool is_update_scheduled() {
- AutoLock l(update_status_mutex_);
+ base::AutoLock l(update_status_mutex_);
return is_update_scheduled_;
}
@@ -316,7 +315,7 @@ class SafeBrowsingServiceTest : public InProcessBrowserTest {
// Protects all variables below since they are read on UI thread
// but updated on IO thread or safebrowsing thread.
- Lock update_status_mutex_;
+ base::Lock update_status_mutex_;
// States associated with safebrowsing service updates.
bool is_database_ready_;
diff --git a/chrome/browser/sync/engine/syncer_thread.cc b/chrome/browser/sync/engine/syncer_thread.cc
index 501577dd..3c0cd06 100644
--- a/chrome/browser/sync/engine/syncer_thread.cc
+++ b/chrome/browser/sync/engine/syncer_thread.cc
@@ -59,7 +59,7 @@ void SyncerThread::NudgeSyncerWithDataTypes(
int milliseconds_from_now,
NudgeSource source,
const syncable::ModelTypeBitSet& model_types) {
- AutoLock lock(lock_);
+ base::AutoLock lock(lock_);
if (vault_.syncer_ == NULL) {
return;
}
@@ -70,7 +70,7 @@ void SyncerThread::NudgeSyncerWithDataTypes(
void SyncerThread::NudgeSyncer(
int milliseconds_from_now,
NudgeSource source) {
- AutoLock lock(lock_);
+ base::AutoLock lock(lock_);
if (vault_.syncer_ == NULL) {
return;
}
@@ -107,7 +107,7 @@ SyncerThread::~SyncerThread() {
// and false otherwise.
bool SyncerThread::Start() {
{
- AutoLock lock(lock_);
+ base::AutoLock lock(lock_);
if (thread_.IsRunning()) {
return true;
}
@@ -141,7 +141,7 @@ bool SyncerThread::Stop(int max_wait) {
void SyncerThread::RequestSyncerExitAndSetThreadStopConditions() {
{
- AutoLock lock(lock_);
+ base::AutoLock lock(lock_);
// If the thread has been started, then we either already have or are about
// to enter ThreadMainLoop so we have to proceed with shutdown and wait for
// it to finish. If the thread has not been started --and we now own the
@@ -170,7 +170,7 @@ void SyncerThread::RequestSyncerExitAndSetThreadStopConditions() {
}
bool SyncerThread::RequestPause() {
- AutoLock lock(lock_);
+ base::AutoLock lock(lock_);
if (vault_.pause_requested_ || vault_.paused_)
return false;
@@ -195,7 +195,7 @@ void SyncerThread::Notify(SyncEngineEvent::EventCause cause) {
}
bool SyncerThread::RequestResume() {
- AutoLock lock(lock_);
+ base::AutoLock lock(lock_);
// Only valid to request a resume when we are already paused or we
// have a pause pending.
if (!(vault_.paused_ || vault_.pause_requested_))
@@ -530,7 +530,7 @@ SyncerThread::WaitInterval SyncerThread::CalculatePollingWaitTime(
}
void SyncerThread::ThreadMain() {
- AutoLock lock(lock_);
+ base::AutoLock lock(lock_);
// Signal Start() to let it know we've made it safely onto the message loop,
// and unblock it's caller.
thread_main_started_.Signal();
@@ -637,7 +637,7 @@ SyncSourceInfo SyncerThread::MakeSyncSourceInfo(bool nudged,
}
void SyncerThread::CreateSyncer(const std::string& dirname) {
- AutoLock lock(lock_);
+ base::AutoLock lock(lock_);
VLOG(1) << "Creating syncer up for: " << dirname;
// The underlying database structure is ready, and we should create
// the syncer.
@@ -655,7 +655,7 @@ void SyncerThread::CreateSyncer(const std::string& dirname) {
// server.
static inline void CheckConnected(bool* connected,
HttpResponse::ServerConnectionCode code,
- ConditionVariable* condvar) {
+ base::ConditionVariable* condvar) {
if (*connected) {
// Note, be careful when adding cases here because if the SyncerThread
// thinks there is no valid connection as determined by this method, it
@@ -686,7 +686,7 @@ void SyncerThread::WatchConnectionManager(ServerConnectionManager* conn_mgr) {
void SyncerThread::HandleServerConnectionEvent(
const ServerConnectionEvent& event) {
if (ServerConnectionEvent::STATUS_CHANGED == event.what_happened) {
- AutoLock lock(lock_);
+ base::AutoLock lock(lock_);
CheckConnected(&vault_.connected_, event.connection_code,
&vault_field_changed_);
}
@@ -771,7 +771,7 @@ void SyncerThread::NudgeSyncImpl(int milliseconds_from_now,
}
void SyncerThread::SetNotificationsEnabled(bool notifications_enabled) {
- AutoLock lock(lock_);
+ base::AutoLock lock(lock_);
session_context_->set_notifications_enabled(notifications_enabled);
}
diff --git a/chrome/browser/sync/engine/syncer_thread.h b/chrome/browser/sync/engine/syncer_thread.h
index bba7d29..09b55df 100644
--- a/chrome/browser/sync/engine/syncer_thread.h
+++ b/chrome/browser/sync/engine/syncer_thread.h
@@ -14,21 +14,22 @@
#include <vector>
#include "base/basictypes.h"
-#include "base/condition_variable.h"
#include "base/gtest_prod_util.h"
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
+#include "base/synchronization/condition_variable.h"
#include "base/threading/thread.h"
#include "base/time.h"
#include "base/waitable_event.h"
-#if defined(OS_LINUX)
-#include "chrome/browser/sync/engine/idle_query_linux.h"
-#endif
#include "chrome/browser/sync/engine/syncer_types.h"
#include "chrome/browser/sync/sessions/sync_session.h"
#include "chrome/browser/sync/syncable/model_type.h"
#include "chrome/common/deprecated/event_sys-inl.h"
+#if defined(OS_LINUX)
+#include "chrome/browser/sync/engine/idle_query_linux.h"
+#endif
+
class EventListenerHookup;
namespace browser_sync {
@@ -213,10 +214,10 @@ class SyncerThread : public base::RefCountedThreadSafe<SyncerThread>,
// Gets signaled whenever a thread outside of the syncer thread changes a
// protected field in the vault_.
- ConditionVariable vault_field_changed_;
+ base::ConditionVariable vault_field_changed_;
// Used to lock everything in |vault_|.
- Lock lock_;
+ base::Lock lock_;
private:
// Threshold multipler for how long before user should be considered idle.
diff --git a/chrome/browser/sync/glue/ui_model_worker.cc b/chrome/browser/sync/glue/ui_model_worker.cc
index 24622ae..9ba5cdd 100644
--- a/chrome/browser/sync/glue/ui_model_worker.cc
+++ b/chrome/browser/sync/glue/ui_model_worker.cc
@@ -32,7 +32,7 @@ void UIModelWorker::DoWorkAndWaitUntilDone(Callback0::Type* work) {
// We lock only to avoid PostTask'ing a NULL pending_work_ (because it
// could get Run() in Stop() and call OnTaskCompleted before we post).
// The task is owned by the message loop as per usual.
- AutoLock lock(lock_);
+ base::AutoLock lock(lock_);
DCHECK(!pending_work_);
pending_work_ = new CallDoWorkAndSignalTask(work, &work_done, this);
ui_loop_->PostTask(FROM_HERE, pending_work_);
@@ -54,7 +54,7 @@ UIModelWorker::~UIModelWorker() {
}
void UIModelWorker::OnSyncerShutdownComplete() {
- AutoLock lock(lock_);
+ base::AutoLock lock(lock_);
// The SyncerThread has terminated and we are no longer needed by syncapi.
// The UI loop initiated shutdown and is (or will be) waiting in Stop().
// We could either be WORKING or RUNNING_MANUAL_SHUTDOWN_PUMP, depending
@@ -69,7 +69,7 @@ void UIModelWorker::OnSyncerShutdownComplete() {
void UIModelWorker::Stop() {
DCHECK_EQ(MessageLoop::current(), ui_loop_);
- AutoLock lock(lock_);
+ base::AutoLock lock(lock_);
DCHECK_EQ(state_, WORKING);
// We're on our own now, the beloved UI MessageLoop is no longer running.
diff --git a/chrome/browser/sync/glue/ui_model_worker.h b/chrome/browser/sync/glue/ui_model_worker.h
index f3a988b..503d8cb 100644
--- a/chrome/browser/sync/glue/ui_model_worker.h
+++ b/chrome/browser/sync/glue/ui_model_worker.h
@@ -7,8 +7,8 @@
#pragma once
#include "base/callback.h"
-#include "base/condition_variable.h"
-#include "base/lock.h"
+#include "base/synchronization/lock.h"
+#include "base/synchronization/condition_variable.h"
#include "base/task.h"
#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/engine/model_safe_worker.h"
@@ -119,14 +119,14 @@ class UIModelWorker : public browser_sync::ModelSafeWorker {
// barrier permits instructions to be reordered by compiler optimizations.
// Possible or not, that route makes for very fragile code due to existence
// of theoretical races.
- Lock lock_;
+ base::Lock lock_;
// Used as a barrier at shutdown to ensure the SyncerThread terminates before
// we allow the UI thread to return from Stop(). This gets signalled whenever
// one of two events occur: a new pending_work_ task was scheduled, or the
// SyncerThread has terminated. We only care about (1) when we are in Stop(),
// because we have to manually Run() the task.
- ConditionVariable syncapi_event_;
+ base::ConditionVariable syncapi_event_;
DISALLOW_COPY_AND_ASSIGN(UIModelWorker);
};
diff --git a/chrome/browser/sync/syncable/syncable_unittest.cc b/chrome/browser/sync/syncable/syncable_unittest.cc
index 1bf4587..6c887b2 100644
--- a/chrome/browser/sync/syncable/syncable_unittest.cc
+++ b/chrome/browser/sync/syncable/syncable_unittest.cc
@@ -386,7 +386,7 @@ TEST_F(SyncableDirectoryTest, TakeSnapshotGetsMetahandlesToPurge) {
dir_->PurgeEntriesWithTypeIn(to_purge);
Directory::SaveChangesSnapshot snapshot1;
- AutoLock scoped_lock(dir_->kernel_->save_changes_mutex);
+ base::AutoLock scoped_lock(dir_->kernel_->save_changes_mutex);
dir_->TakeSnapshotForSaveChanges(&snapshot1);
EXPECT_TRUE(expected_purges == snapshot1.metahandles_to_purge);
@@ -415,7 +415,7 @@ TEST_F(SyncableDirectoryTest, TakeSnapshotGetsAllDirtyHandlesTest) {
// Fake SaveChanges() and make sure we got what we expected.
{
Directory::SaveChangesSnapshot snapshot;
- AutoLock scoped_lock(dir_->kernel_->save_changes_mutex);
+ base::AutoLock scoped_lock(dir_->kernel_->save_changes_mutex);
dir_->TakeSnapshotForSaveChanges(&snapshot);
// Make sure there's an entry for each new metahandle. Make sure all
// entries are marked dirty.
@@ -448,7 +448,7 @@ TEST_F(SyncableDirectoryTest, TakeSnapshotGetsAllDirtyHandlesTest) {
// Fake SaveChanges() and make sure we got what we expected.
{
Directory::SaveChangesSnapshot snapshot;
- AutoLock scoped_lock(dir_->kernel_->save_changes_mutex);
+ base::AutoLock scoped_lock(dir_->kernel_->save_changes_mutex);
dir_->TakeSnapshotForSaveChanges(&snapshot);
// Make sure there's an entry for each new metahandle. Make sure all
// entries are marked dirty.
@@ -588,7 +588,7 @@ TEST_F(SyncableDirectoryTest, TakeSnapshotGetsOnlyDirtyHandlesTest) {
// Fake SaveChanges() and make sure we got what we expected.
{
Directory::SaveChangesSnapshot snapshot;
- AutoLock scoped_lock(dir_->kernel_->save_changes_mutex);
+ base::AutoLock scoped_lock(dir_->kernel_->save_changes_mutex);
dir_->TakeSnapshotForSaveChanges(&snapshot);
// Make sure there are no dirty_metahandles.
EXPECT_EQ(0u, snapshot.dirty_metas.size());
@@ -614,7 +614,7 @@ TEST_F(SyncableDirectoryTest, TakeSnapshotGetsOnlyDirtyHandlesTest) {
// Fake SaveChanges() and make sure we got what we expected.
{
Directory::SaveChangesSnapshot snapshot;
- AutoLock scoped_lock(dir_->kernel_->save_changes_mutex);
+ base::AutoLock scoped_lock(dir_->kernel_->save_changes_mutex);
dir_->TakeSnapshotForSaveChanges(&snapshot);
// Make sure there's an entry for each changed metahandle. Make sure all
// entries are marked dirty.
@@ -1389,8 +1389,8 @@ TEST(SyncableDirectoryManager, ThreadOpenTest) {
struct Step {
Step() : condvar(&mutex), number(0) {}
- Lock mutex;
- ConditionVariable condvar;
+ base::Lock mutex;
+ base::ConditionVariable condvar;
int number;
int64 metahandle;
};
@@ -1409,7 +1409,7 @@ class ThreadBugDelegate : public base::PlatformThread::Delegate {
// PlatformThread::Delegate methods:
virtual void ThreadMain() {
const std::string dirname = "ThreadBug1";
- AutoLock scoped_lock(step_->mutex);
+ base::AutoLock scoped_lock(step_->mutex);
while (step_->number < 3) {
while (step_->number % 2 != role_) {
@@ -1482,7 +1482,7 @@ class DirectoryKernelStalenessBugDelegate : public ThreadBugDelegate {
virtual void ThreadMain() {
const char test_bytes[] = "test data";
const std::string dirname = "DirectoryKernelStalenessBug";
- AutoLock scoped_lock(step_->mutex);
+ base::AutoLock scoped_lock(step_->mutex);
const Id jeff_id = TestIdFactory::FromNumber(100);
while (step_->number < 4) {
diff --git a/chrome/common/deprecated/event_sys-inl.h b/chrome/common/deprecated/event_sys-inl.h
index 835eabe..c92de62 100644
--- a/chrome/common/deprecated/event_sys-inl.h
+++ b/chrome/common/deprecated/event_sys-inl.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 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.
@@ -9,11 +9,11 @@
#include <map>
#include "base/basictypes.h"
-#include "base/condition_variable.h"
-#include "base/lock.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/port.h"
+#include "base/synchronization/condition_variable.h"
+#include "base/synchronization/lock.h"
#include "chrome/common/deprecated/event_sys.h"
// How to use Channels:
@@ -65,9 +65,9 @@ class CallbackWaiters {
~CallbackWaiters() {
DCHECK_EQ(0, waiter_count_);
}
- void WaitForCallbackToComplete(Lock* listeners_mutex) {
+ void WaitForCallbackToComplete(base::Lock* listeners_mutex) {
{
- AutoLock lock(mutex_);
+ base::AutoLock lock(mutex_);
waiter_count_ += 1;
listeners_mutex->Release();
while (!callback_done_)
@@ -80,7 +80,7 @@ class CallbackWaiters {
}
void Signal() {
- AutoLock lock(mutex_);
+ base::AutoLock lock(mutex_);
callback_done_ = true;
condvar_.Broadcast();
}
@@ -88,8 +88,8 @@ class CallbackWaiters {
protected:
int waiter_count_;
bool callback_done_;
- Lock mutex_;
- ConditionVariable condvar_;
+ base::Lock mutex_;
+ base::ConditionVariable condvar_;
};
template <typename EventTraitsType, typename NotifyLock,
@@ -119,7 +119,7 @@ class EventChannel {
// Make sure all the listeners have been disconnected. Otherwise, they
// will try to call RemoveListener() at a later date.
#if defined(DEBUG)
- AutoLock lock(listeners_mutex_);
+ base::AutoLock lock(listeners_mutex_);
for (typename Listeners::iterator i = listeners_.begin();
i != listeners_.end(); ++i) {
DCHECK(i->second) << "Listener not disconnected";
@@ -131,7 +131,7 @@ class EventChannel {
//
// Thread safe.
void AddListener(Listener* listener) {
- AutoLock lock(listeners_mutex_);
+ base::AutoLock lock(listeners_mutex_);
typename Listeners::iterator found = listeners_.find(listener);
if (found == listeners_.end()) {
listeners_.insert(std::make_pair(listener,
@@ -209,7 +209,7 @@ class EventChannel {
// Remove while in callback. Owned and closed by the thread calling Remove().
CallbackWaiters* callback_waiters_;
- Lock listeners_mutex_; // Protects all members above.
+ base::Lock listeners_mutex_; // Protects all members above.
const EventType shutdown_event_;
NotifyLock notify_lock_;
diff --git a/chrome/common/deprecated/event_sys.h b/chrome/common/deprecated/event_sys.h
index 6e34eb7..944ef1f 100644
--- a/chrome/common/deprecated/event_sys.h
+++ b/chrome/common/deprecated/event_sys.h
@@ -9,8 +9,10 @@
// TODO: This class should be removed or moved to Notifier code.
// See Bug 42450 (http://code.google.com/p/chromium/issues/detail?id=42450).
+namespace base {
class AutoLock;
class Lock;
+}
// An abstract base class for listening to events.
//
@@ -27,8 +29,8 @@ class EventListener {
// See the -inl.h for details about the following.
-template <typename EventTraits, typename NotifyLock = Lock,
- typename ScopedNotifyLocker = AutoLock>
+template <typename EventTraits, typename NotifyLock = base::Lock,
+ typename ScopedNotifyLocker = base::AutoLock>
class EventChannel;
class EventListenerHookup;
diff --git a/chrome/common/deprecated/event_sys_unittest.cc b/chrome/common/deprecated/event_sys_unittest.cc
index 1d35d5f..941543a 100644
--- a/chrome/common/deprecated/event_sys_unittest.cc
+++ b/chrome/common/deprecated/event_sys_unittest.cc
@@ -159,14 +159,14 @@ class ThreadTester : public EventListener<TestEvent>,
};
struct ThreadArgs {
- ConditionVariable* thread_running_cond;
- Lock* thread_running_mutex;
+ base::ConditionVariable* thread_running_cond;
+ base::Lock* thread_running_mutex;
bool thread_running;
};
void Go() {
- Lock thread_running_mutex;
- ConditionVariable thread_running_cond(&thread_running_mutex);
+ base::Lock thread_running_mutex;
+ base::ConditionVariable thread_running_cond(&thread_running_mutex);
ThreadArgs args;
ThreadInfo info;
args.thread_running_cond = &(thread_running_cond);
@@ -225,10 +225,10 @@ class ThreadTester : public EventListener<TestEvent>,
}
Pair* pair_;
- ConditionVariable remove_event_;
- Lock remove_event_mutex_;
+ base::ConditionVariable remove_event_;
+ base::Lock remove_event_mutex_;
bool remove_event_bool_;
- Lock completed_mutex_;
+ base::Lock completed_mutex_;
bool completed_;
std::vector<ThreadInfo> threads_;
ThreadArgs args_;
diff --git a/media/base/pipeline_impl.cc b/media/base/pipeline_impl.cc
index 3b27943..d295d6b 100644
--- a/media/base/pipeline_impl.cc
+++ b/media/base/pipeline_impl.cc
@@ -7,8 +7,8 @@
#include "base/callback.h"
#include "base/compiler_specific.h"
-#include "base/condition_variable.h"
#include "base/stl_util-inl.h"
+#include "base/synchronization/condition_variable.h"
#include "media/base/clock_impl.h"
#include "media/base/filter_collection.h"
#include "media/base/media_format.h"
diff --git a/media/filters/video_renderer_base.h b/media/filters/video_renderer_base.h
index 8868521..1e1c4fe 100644
--- a/media/filters/video_renderer_base.h
+++ b/media/filters/video_renderer_base.h
@@ -17,9 +17,9 @@
#include <deque>
-#include "base/condition_variable.h"
-#include "base/lock.h"
#include "base/scoped_ptr.h"
+#include "base/synchronization/condition_variable.h"
+#include "base/synchronization/lock.h"
#include "base/threading/platform_thread.h"
#include "media/base/filters.h"
#include "media/base/video_frame.h"
@@ -129,7 +129,7 @@ class VideoRendererBase : public VideoRenderer,
float playback_rate);
// Used for accessing data members.
- Lock lock_;
+ base::Lock lock_;
scoped_refptr<VideoDecoder> decoder_;
@@ -148,7 +148,7 @@ class VideoRendererBase : public VideoRenderer,
// Used to signal |thread_| as frames are added to |frames_|. Rule of thumb:
// always check |state_| to see if it was set to STOPPED after waking up!
- ConditionVariable frame_available_;
+ base::ConditionVariable frame_available_;
// State transition Diagram of this class:
// [kUninitialized] -------> [kError]
diff --git a/net/base/dnsrr_resolver_unittest.cc b/net/base/dnsrr_resolver_unittest.cc
index f5b545b..dfa904a 100644
--- a/net/base/dnsrr_resolver_unittest.cc
+++ b/net/base/dnsrr_resolver_unittest.cc
@@ -5,8 +5,7 @@
#include "net/base/dnsrr_resolver.h"
#include "base/callback.h"
-#include "base/condition_variable.h"
-#include "base/lock.h"
+#include "base/synchronization/lock.h"
#include "net/base/dns_util.h"
#include "net/base/net_errors.h"
#include "net/base/net_log.h"
diff --git a/net/base/listen_socket_unittest.h b/net/base/listen_socket_unittest.h
index 176dfcb..f283cb0 100644
--- a/net/base/listen_socket_unittest.h
+++ b/net/base/listen_socket_unittest.h
@@ -17,11 +17,11 @@
#endif
#include "base/basictypes.h"
-#include "base/condition_variable.h"
-#include "base/lock.h"
#include "base/message_loop.h"
#include "base/scoped_ptr.h"
#include "base/string_util.h"
+#include "base/synchronization/condition_variable.h"
+#include "base/synchronization/lock.h"
#include "base/threading/thread.h"
#include "net/base/listen_socket.h"
#include "net/base/net_util.h"
@@ -116,8 +116,8 @@ class ListenSocketTester :
SOCKET test_socket_;
static const int kTestPort;
- Lock lock_; // protects |queue_| and wraps |cv_|
- ConditionVariable cv_;
+ base::Lock lock_; // protects |queue_| and wraps |cv_|
+ base::ConditionVariable cv_;
std::deque<ListenSocketTestAction> queue_;
};
diff --git a/net/ocsp/nss_ocsp.cc b/net/ocsp/nss_ocsp.cc
index c35c572..78eb7f5 100644
--- a/net/ocsp/nss_ocsp.cc
+++ b/net/ocsp/nss_ocsp.cc
@@ -16,7 +16,6 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
-#include "base/condition_variable.h"
#include "base/lazy_instance.h"
#include "base/lock.h"
#include "base/logging.h"
@@ -25,6 +24,7 @@
#include "base/stl_util-inl.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
+#include "base/synchronization/condition_variable.h"
#include "base/threading/thread_checker.h"
#include "base/time.h"
#include "googleurl/src/gurl.h"
@@ -46,7 +46,7 @@ class OCSPRequestSession;
class OCSPIOLoop {
public:
void StartUsing() {
- AutoLock autolock(lock_);
+ base::AutoLock autolock(lock_);
used_ = true;
}
@@ -54,7 +54,7 @@ class OCSPIOLoop {
void Shutdown();
bool used() const {
- AutoLock autolock(lock_);
+ base::AutoLock autolock(lock_);
return used_;
}
@@ -74,7 +74,7 @@ class OCSPIOLoop {
void CancelAllRequests();
- mutable Lock lock_;
+ mutable base::Lock lock_;
bool shutdown_; // Protected by |lock_|.
std::set<OCSPRequestSession*> requests_; // Protected by |lock_|.
bool used_; // Protected by |lock_|.
@@ -188,18 +188,18 @@ class OCSPRequestSession
void Cancel() {
// IO thread may set |io_loop_| to NULL, so protect by |lock_|.
- AutoLock autolock(lock_);
+ base::AutoLock autolock(lock_);
CancelLocked();
}
bool Finished() const {
- AutoLock autolock(lock_);
+ base::AutoLock autolock(lock_);
return finished_;
}
bool Wait() {
base::TimeDelta timeout = timeout_;
- AutoLock autolock(lock_);
+ base::AutoLock autolock(lock_);
while (!finished_) {
base::TimeTicks last_time = base::TimeTicks::Now();
cv_.TimedWait(timeout);
@@ -290,7 +290,7 @@ class OCSPRequestSession
request_ = NULL;
g_ocsp_io_loop.Get().RemoveRequest(this);
{
- AutoLock autolock(lock_);
+ base::AutoLock autolock(lock_);
finished_ = true;
io_loop_ = NULL;
}
@@ -303,7 +303,7 @@ class OCSPRequestSession
void CancelURLRequest() {
#ifndef NDEBUG
{
- AutoLock autolock(lock_);
+ base::AutoLock autolock(lock_);
if (io_loop_)
DCHECK_EQ(MessageLoopForIO::current(), io_loop_);
}
@@ -314,7 +314,7 @@ class OCSPRequestSession
request_ = NULL;
g_ocsp_io_loop.Get().RemoveRequest(this);
{
- AutoLock autolock(lock_);
+ base::AutoLock autolock(lock_);
finished_ = true;
io_loop_ = NULL;
}
@@ -356,7 +356,7 @@ class OCSPRequestSession
return;
{
- AutoLock autolock(lock_);
+ base::AutoLock autolock(lock_);
DCHECK(!io_loop_);
io_loop_ = MessageLoopForIO::current();
g_ocsp_io_loop.Get().AddRequest(this);
@@ -401,8 +401,8 @@ class OCSPRequestSession
std::string data_; // Results of the requst
// |lock_| protects |finished_| and |io_loop_|.
- mutable Lock lock_;
- ConditionVariable cv_;
+ mutable base::Lock lock_;
+ base::ConditionVariable cv_;
MessageLoop* io_loop_; // Message loop of the IO thread
bool finished_;
@@ -462,7 +462,7 @@ OCSPIOLoop::~OCSPIOLoop() {
// IO thread was already deleted before the singleton is deleted
// in AtExitManager.
{
- AutoLock autolock(lock_);
+ base::AutoLock autolock(lock_);
DCHECK(!io_loop_);
DCHECK(!used_);
DCHECK(shutdown_);
@@ -479,7 +479,7 @@ void OCSPIOLoop::Shutdown() {
// Prevent the worker thread from trying to access |io_loop_|.
{
- AutoLock autolock(lock_);
+ base::AutoLock autolock(lock_);
io_loop_ = NULL;
used_ = false;
shutdown_ = true;
@@ -494,13 +494,13 @@ void OCSPIOLoop::Shutdown() {
void OCSPIOLoop::PostTaskToIOLoop(
const tracked_objects::Location& from_here, Task* task) {
- AutoLock autolock(lock_);
+ base::AutoLock autolock(lock_);
if (io_loop_)
io_loop_->PostTask(from_here, task);
}
void OCSPIOLoop::EnsureIOLoop() {
- AutoLock autolock(lock_);
+ base::AutoLock autolock(lock_);
DCHECK_EQ(MessageLoopForIO::current(), io_loop_);
}
@@ -512,7 +512,7 @@ void OCSPIOLoop::AddRequest(OCSPRequestSession* request) {
void OCSPIOLoop::RemoveRequest(OCSPRequestSession* request) {
{
// Ignore if we've already shutdown.
- AutoLock auto_lock(lock_);
+ base::AutoLock auto_lock(lock_);
if (shutdown_)
return;
}
diff --git a/net/tools/hresolv/hresolv.cc b/net/tools/hresolv/hresolv.cc
index 16124d7..24d73a8 100644
--- a/net/tools/hresolv/hresolv.cc
+++ b/net/tools/hresolv/hresolv.cc
@@ -24,7 +24,6 @@
#include "base/at_exit.h"
#include "base/command_line.h"
-#include "base/condition_variable.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/message_loop.h"
diff --git a/o3d/core/cross/message_queue_test.cc b/o3d/core/cross/message_queue_test.cc
index c94eb52..fd8840d 100644
--- a/o3d/core/cross/message_queue_test.cc
+++ b/o3d/core/cross/message_queue_test.cc
@@ -42,10 +42,10 @@
#include "core/cross/types.h"
#include "core/cross/renderer.h"
#include "tests/common/win/testing_common.h"
-#include "base/condition_variable.h"
-#include "base/lock.h"
#include "base/platform_thread.h"
#include "base/time.h"
+#include "base/synchronization/condition_variable.h"
+#include "base/synchronization/lock.h"
using ::base::Time;
using ::base::TimeDelta;
@@ -81,8 +81,8 @@ class WallClockTimeSource : public TimeSource {
// of times, this indicates one failure mode of the test.
class TestWatchdog {
private:
- Lock lock_;
- ConditionVariable condition_;
+ base::Lock lock_;
+ base::ConditionVariable condition_;
int expected_num_signals_;
TimeDelta time_to_run_;
TimeSource* time_source_;
@@ -98,7 +98,7 @@ class TestWatchdog {
time_source_(time_source) {}
void Signal() {
- AutoLock locker(lock_);
+ base::AutoLock locker(lock_);
ASSERT_GE(expected_num_signals_, 0);
--expected_num_signals_;
condition_.Broadcast();
@@ -107,7 +107,7 @@ class TestWatchdog {
// Pause the current thread briefly waiting for a signal so we don't
// consume all CPU
void WaitBrieflyForSignal() {
- AutoLock locker(lock_);
+ base::AutoLock locker(lock_);
condition_.TimedWait(TimeDelta::FromMilliseconds(5));
}
diff --git a/remoting/base/tracer.cc b/remoting/base/tracer.cc
index 0126e1f..25ed244 100644
--- a/remoting/base/tracer.cc
+++ b/remoting/base/tracer.cc
@@ -7,12 +7,12 @@
#include <list>
#include "base/basictypes.h"
-#include "base/condition_variable.h"
#include "base/lazy_instance.h"
#include "base/message_loop.h"
#include "base/rand_util.h"
#include "base/ref_counted.h"
#include "base/stl_util-inl.h"
+#include "base/synchronization/condition_variable.h"
#include "base/threading/thread.h"
#include "base/threading/platform_thread.h"
#include "base/threading/thread_local.h"
@@ -36,7 +36,7 @@ class OutputLogger {
void OutputTrace(TraceBuffer* buffer) {
scoped_ptr<TraceBuffer> buffer_ref_(buffer);
- AutoLock l(lock_);
+ base::AutoLock l(lock_);
// Drop messages if we're overwhelming the logger.
if (buffers_.size() < 10) {
@@ -71,7 +71,7 @@ class OutputLogger {
while(!stopped_) {
TraceBuffer* buffer = NULL;
{
- AutoLock l(lock_);
+ base::AutoLock l(lock_);
if (buffers_.size() == 0) {
wake_.Wait();
}
@@ -94,7 +94,7 @@ class OutputLogger {
~OutputLogger() {
{
- AutoLock l(lock_);
+ base::AutoLock l(lock_);
stopped_ = true;
wake_.Signal();
}
@@ -103,10 +103,10 @@ class OutputLogger {
STLDeleteElements(&buffers_);
}
- Lock lock_;
+ base::Lock lock_;
base::Thread thread_;
bool stopped_;
- ConditionVariable wake_;
+ base::ConditionVariable wake_;
std::list<TraceBuffer*> buffers_;
};
@@ -125,7 +125,7 @@ Tracer::Tracer(const std::string& name, double sample_percent) {
}
void Tracer::PrintString(const std::string& s) {
- AutoLock l(lock_);
+ base::AutoLock l(lock_);
if (!buffer_.get()) {
return;
}
@@ -140,7 +140,7 @@ void Tracer::PrintString(const std::string& s) {
}
Tracer::~Tracer() {
- AutoLock l(lock_);
+ base::AutoLock l(lock_);
if (buffer_.get()) {
g_output_logger.Get().OutputTrace(buffer_.release());