Index: content/browser/browser_thread_impl.cc |
diff --git a/content/browser/browser_thread_impl.cc b/content/browser/browser_thread_impl.cc |
index 90b581882fb7bfb0fc35c332215e1a677b364f6b..6ff498e96d41a6a1f171fb91d807407a2e05e14a 100644 |
--- a/content/browser/browser_thread_impl.cc |
+++ b/content/browser/browser_thread_impl.cc |
@@ -15,6 +15,7 @@ |
#include "base/macros.h" |
#include "base/profiler/scoped_tracker.h" |
#include "base/single_thread_task_runner.h" |
+#include "base/synchronization/read_write_lock.h" |
#include "base/threading/sequenced_worker_pool.h" |
#include "build/build_config.h" |
#include "content/public/browser/browser_thread_delegate.h" |
@@ -99,7 +100,7 @@ struct BrowserThreadGlobals { |
// This lock protects |threads|. Do not read or modify that array |
// without holding this lock. Do not block while holding this lock. |
- base::Lock lock; |
+ base::ReadWriteLock lock; |
// This array is protected by |lock|. The threads are not owned by this |
// array. Typically, the threads are owned on the UI thread by |
@@ -276,14 +277,14 @@ void BrowserThreadImpl::CleanUp() { |
// However, the message loop will soon be destructed without any locking. So |
// to prevent a race with accessing the message loop in PostTaskHelper(), |
// remove this thread from the global array now. |
- base::AutoLock lock(globals.lock); |
+ base::AutoWriteLock lock(globals.lock); |
globals.threads[identifier_] = NULL; |
} |
void BrowserThreadImpl::Initialize() { |
BrowserThreadGlobals& globals = g_globals.Get(); |
- base::AutoLock lock(globals.lock); |
+ base::AutoWriteLock lock(globals.lock); |
DCHECK(identifier_ >= 0 && identifier_ < ID_COUNT); |
DCHECK(globals.threads[identifier_] == NULL); |
globals.threads[identifier_] = this; |
@@ -296,7 +297,7 @@ BrowserThreadImpl::~BrowserThreadImpl() { |
Stop(); |
BrowserThreadGlobals& globals = g_globals.Get(); |
- base::AutoLock lock(globals.lock); |
+ base::AutoWriteLock lock(globals.lock); |
globals.threads[identifier_] = NULL; |
#ifndef NDEBUG |
// Double check that the threads are ordered correctly in the enumeration. |
@@ -312,7 +313,7 @@ bool BrowserThreadImpl::StartWithOptions(const Options& options) { |
// starting, as the new thread can asynchronously start touching the |
// table (and other thread's message_loop). |
BrowserThreadGlobals& globals = g_globals.Get(); |
- base::AutoLock lock(globals.lock); |
+ base::AutoWriteLock lock(globals.lock); |
return Thread::StartWithOptions(options); |
} |
@@ -337,7 +338,7 @@ bool BrowserThreadImpl::PostTaskHelper( |
BrowserThreadGlobals& globals = g_globals.Get(); |
if (!target_thread_outlives_current) |
- globals.lock.Acquire(); |
+ globals.lock.ReadAcquire(); |
base::MessageLoop* message_loop = |
globals.threads[identifier] ? globals.threads[identifier]->message_loop() |
@@ -352,7 +353,7 @@ bool BrowserThreadImpl::PostTaskHelper( |
} |
if (!target_thread_outlives_current) |
- globals.lock.Release(); |
+ globals.lock.ReadRelease(); |
return !!message_loop; |
} |
@@ -402,7 +403,7 @@ bool BrowserThread::IsThreadInitialized(ID identifier) { |
return false; |
BrowserThreadGlobals& globals = g_globals.Get(); |
- base::AutoLock lock(globals.lock); |
+ base::AutoReadLock lock(globals.lock); |
DCHECK(identifier >= 0 && identifier < ID_COUNT); |
return globals.threads[identifier] != NULL; |
} |
@@ -410,7 +411,7 @@ bool BrowserThread::IsThreadInitialized(ID identifier) { |
// static |
bool BrowserThread::CurrentlyOn(ID identifier) { |
BrowserThreadGlobals& globals = g_globals.Get(); |
- base::AutoLock lock(globals.lock); |
+ base::AutoReadLock lock(globals.lock); |
DCHECK(identifier >= 0 && identifier < ID_COUNT); |
return globals.threads[identifier] && |
globals.threads[identifier]->message_loop() == |
@@ -449,7 +450,7 @@ bool BrowserThread::IsMessageLoopValid(ID identifier) { |
return false; |
BrowserThreadGlobals& globals = g_globals.Get(); |
- base::AutoLock lock(globals.lock); |
+ base::AutoReadLock lock(globals.lock); |
DCHECK(identifier >= 0 && identifier < ID_COUNT); |
return globals.threads[identifier] && |
globals.threads[identifier]->message_loop(); |
@@ -513,7 +514,7 @@ bool BrowserThread::GetCurrentThreadIdentifier(ID* identifier) { |
// real work on canary and local dev builds, so the cost of having this here |
// should be minimal. |
tracked_objects::ScopedTracker tracking_profile(FROM_HERE); |
- base::AutoLock lock(globals.lock); |
+ base::AutoReadLock lock(globals.lock); |
for (int i = 0; i < ID_COUNT; ++i) { |
if (globals.threads[i] && |
globals.threads[i]->message_loop() == cur_message_loop) { |
@@ -537,7 +538,7 @@ base::MessageLoop* BrowserThread::UnsafeGetMessageLoopForThread(ID identifier) { |
return NULL; |
BrowserThreadGlobals& globals = g_globals.Get(); |
- base::AutoLock lock(globals.lock); |
+ base::AutoReadLock lock(globals.lock); |
base::Thread* thread = globals.threads[identifier]; |
DCHECK(thread); |
base::MessageLoop* loop = thread->message_loop(); |