Index: third_party/mojo/src/mojo/edk/system/dispatcher.cc |
diff --git a/third_party/mojo/src/mojo/edk/system/dispatcher.cc b/third_party/mojo/src/mojo/edk/system/dispatcher.cc |
index ad362fe5eacd01807a1cc3569355fff19c5ce74e..24f2c264a24a5e41f380e9724f1492655d550a80 100644 |
--- a/third_party/mojo/src/mojo/edk/system/dispatcher.cc |
+++ b/third_party/mojo/src/mojo/edk/system/dispatcher.cc |
@@ -26,18 +26,16 @@ |
// Dispatcher ------------------------------------------------------------------ |
-// TODO(vtl): The thread-safety analyzer isn't smart enough to deal with the |
-// fact that we give up if |TryLock()| fails. |
// static |
DispatcherTransport Dispatcher::HandleTableAccess::TryStartTransport( |
- Dispatcher* dispatcher) MOJO_NO_THREAD_SAFETY_ANALYSIS { |
+ Dispatcher* dispatcher) { |
DCHECK(dispatcher); |
- if (!dispatcher->mutex_.TryLock()) |
+ if (!dispatcher->lock_.Try()) |
return DispatcherTransport(); |
// We shouldn't race with things that close dispatchers, since closing can |
- // only take place either under |handle_table_mutex_| or when the handle is |
+ // only take place either under |handle_table_lock_| or when the handle is |
// marked as busy. |
DCHECK(!dispatcher->is_closed_); |
@@ -98,7 +96,7 @@ |
} |
MojoResult Dispatcher::Close() { |
- MutexLocker locker(&mutex_); |
+ base::AutoLock locker(lock_); |
if (is_closed_) |
return MOJO_RESULT_INVALID_ARGUMENT; |
@@ -115,7 +113,7 @@ |
(transports->size() > 0 && |
transports->size() < GetConfiguration().max_message_num_handles)); |
- MutexLocker locker(&mutex_); |
+ base::AutoLock locker(lock_); |
if (is_closed_) |
return MOJO_RESULT_INVALID_ARGUMENT; |
@@ -130,7 +128,7 @@ |
DCHECK(!num_dispatchers || *num_dispatchers == 0 || |
(dispatchers && dispatchers->empty())); |
- MutexLocker locker(&mutex_); |
+ base::AutoLock locker(lock_); |
if (is_closed_) |
return MOJO_RESULT_INVALID_ARGUMENT; |
@@ -141,7 +139,7 @@ |
MojoResult Dispatcher::WriteData(UserPointer<const void> elements, |
UserPointer<uint32_t> num_bytes, |
MojoWriteDataFlags flags) { |
- MutexLocker locker(&mutex_); |
+ base::AutoLock locker(lock_); |
if (is_closed_) |
return MOJO_RESULT_INVALID_ARGUMENT; |
@@ -151,7 +149,7 @@ |
MojoResult Dispatcher::BeginWriteData(UserPointer<void*> buffer, |
UserPointer<uint32_t> buffer_num_bytes, |
MojoWriteDataFlags flags) { |
- MutexLocker locker(&mutex_); |
+ base::AutoLock locker(lock_); |
if (is_closed_) |
return MOJO_RESULT_INVALID_ARGUMENT; |
@@ -159,7 +157,7 @@ |
} |
MojoResult Dispatcher::EndWriteData(uint32_t num_bytes_written) { |
- MutexLocker locker(&mutex_); |
+ base::AutoLock locker(lock_); |
if (is_closed_) |
return MOJO_RESULT_INVALID_ARGUMENT; |
@@ -169,7 +167,7 @@ |
MojoResult Dispatcher::ReadData(UserPointer<void> elements, |
UserPointer<uint32_t> num_bytes, |
MojoReadDataFlags flags) { |
- MutexLocker locker(&mutex_); |
+ base::AutoLock locker(lock_); |
if (is_closed_) |
return MOJO_RESULT_INVALID_ARGUMENT; |
@@ -179,7 +177,7 @@ |
MojoResult Dispatcher::BeginReadData(UserPointer<const void*> buffer, |
UserPointer<uint32_t> buffer_num_bytes, |
MojoReadDataFlags flags) { |
- MutexLocker locker(&mutex_); |
+ base::AutoLock locker(lock_); |
if (is_closed_) |
return MOJO_RESULT_INVALID_ARGUMENT; |
@@ -187,7 +185,7 @@ |
} |
MojoResult Dispatcher::EndReadData(uint32_t num_bytes_read) { |
- MutexLocker locker(&mutex_); |
+ base::AutoLock locker(lock_); |
if (is_closed_) |
return MOJO_RESULT_INVALID_ARGUMENT; |
@@ -197,7 +195,7 @@ |
MojoResult Dispatcher::DuplicateBufferHandle( |
UserPointer<const MojoDuplicateBufferHandleOptions> options, |
scoped_refptr<Dispatcher>* new_dispatcher) { |
- MutexLocker locker(&mutex_); |
+ base::AutoLock locker(lock_); |
if (is_closed_) |
return MOJO_RESULT_INVALID_ARGUMENT; |
@@ -209,7 +207,7 @@ |
uint64_t num_bytes, |
MojoMapBufferFlags flags, |
scoped_ptr<embedder::PlatformSharedBufferMapping>* mapping) { |
- MutexLocker locker(&mutex_); |
+ base::AutoLock locker(lock_); |
if (is_closed_) |
return MOJO_RESULT_INVALID_ARGUMENT; |
@@ -217,7 +215,7 @@ |
} |
HandleSignalsState Dispatcher::GetHandleSignalsState() const { |
- MutexLocker locker(&mutex_); |
+ base::AutoLock locker(lock_); |
if (is_closed_) |
return HandleSignalsState(); |
@@ -228,7 +226,7 @@ |
MojoHandleSignals signals, |
uint32_t context, |
HandleSignalsState* signals_state) { |
- MutexLocker locker(&mutex_); |
+ base::AutoLock locker(lock_); |
if (is_closed_) { |
if (signals_state) |
*signals_state = HandleSignalsState(); |
@@ -240,7 +238,7 @@ |
void Dispatcher::RemoveAwakable(Awakable* awakable, |
HandleSignalsState* handle_signals_state) { |
- MutexLocker locker(&mutex_); |
+ base::AutoLock locker(lock_); |
if (is_closed_) { |
if (handle_signals_state) |
*handle_signals_state = HandleSignalsState(); |
@@ -259,14 +257,14 @@ |
} |
void Dispatcher::CancelAllAwakablesNoLock() { |
- mutex_.AssertHeld(); |
+ lock_.AssertAcquired(); |
DCHECK(is_closed_); |
// By default, waiting isn't supported. Only dispatchers that can be waited on |
// will do something nontrivial. |
} |
void Dispatcher::CloseImplNoLock() { |
- mutex_.AssertHeld(); |
+ lock_.AssertAcquired(); |
DCHECK(is_closed_); |
// This may not need to do anything. Dispatchers should override this to do |
// any actual close-time cleanup necessary. |
@@ -277,7 +275,7 @@ |
uint32_t /*num_bytes*/, |
std::vector<DispatcherTransport>* /*transports*/, |
MojoWriteMessageFlags /*flags*/) { |
- mutex_.AssertHeld(); |
+ lock_.AssertAcquired(); |
DCHECK(!is_closed_); |
// By default, not supported. Only needed for message pipe dispatchers. |
return MOJO_RESULT_INVALID_ARGUMENT; |
@@ -289,7 +287,7 @@ |
DispatcherVector* /*dispatchers*/, |
uint32_t* /*num_dispatchers*/, |
MojoReadMessageFlags /*flags*/) { |
- mutex_.AssertHeld(); |
+ lock_.AssertAcquired(); |
DCHECK(!is_closed_); |
// By default, not supported. Only needed for message pipe dispatchers. |
return MOJO_RESULT_INVALID_ARGUMENT; |
@@ -298,7 +296,7 @@ |
MojoResult Dispatcher::WriteDataImplNoLock(UserPointer<const void> /*elements*/, |
UserPointer<uint32_t> /*num_bytes*/, |
MojoWriteDataFlags /*flags*/) { |
- mutex_.AssertHeld(); |
+ lock_.AssertAcquired(); |
DCHECK(!is_closed_); |
// By default, not supported. Only needed for data pipe dispatchers. |
return MOJO_RESULT_INVALID_ARGUMENT; |
@@ -308,14 +306,14 @@ |
UserPointer<void*> /*buffer*/, |
UserPointer<uint32_t> /*buffer_num_bytes*/, |
MojoWriteDataFlags /*flags*/) { |
- mutex_.AssertHeld(); |
+ lock_.AssertAcquired(); |
DCHECK(!is_closed_); |
// By default, not supported. Only needed for data pipe dispatchers. |
return MOJO_RESULT_INVALID_ARGUMENT; |
} |
MojoResult Dispatcher::EndWriteDataImplNoLock(uint32_t /*num_bytes_written*/) { |
- mutex_.AssertHeld(); |
+ lock_.AssertAcquired(); |
DCHECK(!is_closed_); |
// By default, not supported. Only needed for data pipe dispatchers. |
return MOJO_RESULT_INVALID_ARGUMENT; |
@@ -324,7 +322,7 @@ |
MojoResult Dispatcher::ReadDataImplNoLock(UserPointer<void> /*elements*/, |
UserPointer<uint32_t> /*num_bytes*/, |
MojoReadDataFlags /*flags*/) { |
- mutex_.AssertHeld(); |
+ lock_.AssertAcquired(); |
DCHECK(!is_closed_); |
// By default, not supported. Only needed for data pipe dispatchers. |
return MOJO_RESULT_INVALID_ARGUMENT; |
@@ -334,14 +332,14 @@ |
UserPointer<const void*> /*buffer*/, |
UserPointer<uint32_t> /*buffer_num_bytes*/, |
MojoReadDataFlags /*flags*/) { |
- mutex_.AssertHeld(); |
+ lock_.AssertAcquired(); |
DCHECK(!is_closed_); |
// By default, not supported. Only needed for data pipe dispatchers. |
return MOJO_RESULT_INVALID_ARGUMENT; |
} |
MojoResult Dispatcher::EndReadDataImplNoLock(uint32_t /*num_bytes_read*/) { |
- mutex_.AssertHeld(); |
+ lock_.AssertAcquired(); |
DCHECK(!is_closed_); |
// By default, not supported. Only needed for data pipe dispatchers. |
return MOJO_RESULT_INVALID_ARGUMENT; |
@@ -350,7 +348,7 @@ |
MojoResult Dispatcher::DuplicateBufferHandleImplNoLock( |
UserPointer<const MojoDuplicateBufferHandleOptions> /*options*/, |
scoped_refptr<Dispatcher>* /*new_dispatcher*/) { |
- mutex_.AssertHeld(); |
+ lock_.AssertAcquired(); |
DCHECK(!is_closed_); |
// By default, not supported. Only needed for buffer dispatchers. |
return MOJO_RESULT_INVALID_ARGUMENT; |
@@ -361,14 +359,14 @@ |
uint64_t /*num_bytes*/, |
MojoMapBufferFlags /*flags*/, |
scoped_ptr<embedder::PlatformSharedBufferMapping>* /*mapping*/) { |
- mutex_.AssertHeld(); |
+ lock_.AssertAcquired(); |
DCHECK(!is_closed_); |
// By default, not supported. Only needed for buffer dispatchers. |
return MOJO_RESULT_INVALID_ARGUMENT; |
} |
HandleSignalsState Dispatcher::GetHandleSignalsStateImplNoLock() const { |
- mutex_.AssertHeld(); |
+ lock_.AssertAcquired(); |
DCHECK(!is_closed_); |
// By default, waiting isn't supported. Only dispatchers that can be waited on |
// will do something nontrivial. |
@@ -380,7 +378,7 @@ |
MojoHandleSignals /*signals*/, |
uint32_t /*context*/, |
HandleSignalsState* signals_state) { |
- mutex_.AssertHeld(); |
+ lock_.AssertAcquired(); |
DCHECK(!is_closed_); |
// By default, waiting isn't supported. Only dispatchers that can be waited on |
// will do something nontrivial. |
@@ -391,7 +389,7 @@ |
void Dispatcher::RemoveAwakableImplNoLock(Awakable* /*awakable*/, |
HandleSignalsState* signals_state) { |
- mutex_.AssertHeld(); |
+ lock_.AssertAcquired(); |
DCHECK(!is_closed_); |
// By default, waiting isn't supported. Only dispatchers that can be waited on |
// will do something nontrivial. |
@@ -421,7 +419,7 @@ |
} |
bool Dispatcher::IsBusyNoLock() const { |
- mutex_.AssertHeld(); |
+ lock_.AssertAcquired(); |
DCHECK(!is_closed_); |
// Most dispatchers support only "atomic" operations, so they are never busy |
// (in this sense). |
@@ -429,7 +427,7 @@ |
} |
void Dispatcher::CloseNoLock() { |
- mutex_.AssertHeld(); |
+ lock_.AssertAcquired(); |
DCHECK(!is_closed_); |
is_closed_ = true; |
@@ -439,7 +437,7 @@ |
scoped_refptr<Dispatcher> |
Dispatcher::CreateEquivalentDispatcherAndCloseNoLock() { |
- mutex_.AssertHeld(); |
+ lock_.AssertAcquired(); |
DCHECK(!is_closed_); |
is_closed_ = true; |
@@ -477,7 +475,7 @@ |
// See the comment above |EndSerializeAndCloseImplNoLock()|. In brief: Locking |
// isn't actually needed, but we need to satisfy assertions (which we don't |
// want to remove or weaken). |
- MutexLocker locker(&mutex_); |
+ base::AutoLock locker(lock_); |
#endif |
return EndSerializeAndCloseImplNoLock(channel, destination, actual_size, |
@@ -488,7 +486,7 @@ |
void DispatcherTransport::End() { |
DCHECK(dispatcher_); |
- dispatcher_->mutex_.Unlock(); |
+ dispatcher_->lock_.Release(); |
dispatcher_ = nullptr; |
} |