Make Dispatcher::AddAwakable(), etc. always set *signals_state (if signals_state is non-null).

For persistent awakables (e.g., wait sets), it's helpful to be able to
get the initial state.

R=vardhan@google.com
BUG=#350

Review URL: https://codereview.chromium.org/2078043002 .
diff --git a/mojo/edk/system/data_pipe.cc b/mojo/edk/system/data_pipe.cc
index cff209a..06e1840 100644
--- a/mojo/edk/system/data_pipe.cc
+++ b/mojo/edk/system/data_pipe.cc
@@ -400,18 +400,15 @@
   DCHECK(has_local_producer_no_lock());
 
   HandleSignalsState producer_state = impl_->ProducerGetHandleSignalsState();
+  if (signals_state)
+    *signals_state = producer_state;
   if (producer_state.satisfies(signals)) {
     if (force)
       producer_awakable_list_->Add(awakable, signals, context);
-    if (signals_state)
-      *signals_state = producer_state;
     return MOJO_RESULT_ALREADY_EXISTS;
   }
-  if (!producer_state.can_satisfy(signals)) {
-    if (signals_state)
-      *signals_state = producer_state;
+  if (!producer_state.can_satisfy(signals))
     return MOJO_RESULT_FAILED_PRECONDITION;
-  }
 
   producer_awakable_list_->Add(awakable, signals, context);
   return MOJO_RESULT_OK;
@@ -623,18 +620,15 @@
   DCHECK(has_local_consumer_no_lock());
 
   HandleSignalsState consumer_state = impl_->ConsumerGetHandleSignalsState();
+  if (signals_state)
+    *signals_state = consumer_state;
   if (consumer_state.satisfies(signals)) {
     if (force)
       consumer_awakable_list_->Add(awakable, signals, context);
-    if (signals_state)
-      *signals_state = consumer_state;
     return MOJO_RESULT_ALREADY_EXISTS;
   }
-  if (!consumer_state.can_satisfy(signals)) {
-    if (signals_state)
-      *signals_state = consumer_state;
+  if (!consumer_state.can_satisfy(signals))
     return MOJO_RESULT_FAILED_PRECONDITION;
-  }
 
   consumer_awakable_list_->Add(awakable, signals, context);
   return MOJO_RESULT_OK;
diff --git a/mojo/edk/system/dispatcher.h b/mojo/edk/system/dispatcher.h
index 6369f04..0646f7b 100644
--- a/mojo/edk/system/dispatcher.h
+++ b/mojo/edk/system/dispatcher.h
@@ -193,8 +193,8 @@
   // also be woken up when it becomes impossible for the object to ever satisfy
   // |signals| with a suitable error status.
   //
-  // If |signals_state| is non-null, on *failure* |*signals_state| will be set
-  // to the current handle signals state (on success, it is left untouched).
+  // If |signals_state| is non-null, |*signals_state| will be set to the current
+  // handle signals state.
   //
   // Any awakable that's added must either eventually be removed (using
   // |RemoveAwakable()| or |RemoveAwakableWithContext()|, below). If an
@@ -214,8 +214,7 @@
                          uint64_t context,
                          HandleSignalsState* signals_state);
   // Like |AddAwakable()|, but in the |MOJO_RESULT_ALREADY_EXISTS| case still
-  // adds the awakable (|MOJO_RESULT_ALREADY_EXISTS| will still be returned and
-  // |*signals_state| will still be set if |signals_state| is non-null).
+  // adds the awakable (|MOJO_RESULT_ALREADY_EXISTS| will still be returned).
   MojoResult AddAwakableUnconditional(Awakable* awakable,
                                       MojoHandleSignals signals,
                                       uint64_t context,
diff --git a/mojo/edk/system/local_message_pipe_endpoint.cc b/mojo/edk/system/local_message_pipe_endpoint.cc
index be7f0c5..5d72842 100644
--- a/mojo/edk/system/local_message_pipe_endpoint.cc
+++ b/mojo/edk/system/local_message_pipe_endpoint.cc
@@ -157,18 +157,15 @@
   DCHECK(is_open_);
 
   HandleSignalsState state = GetHandleSignalsState();
+  if (signals_state)
+    *signals_state = state;
   if (state.satisfies(signals)) {
     if (force)
       awakable_list_.Add(awakable, signals, context);
-    if (signals_state)
-      *signals_state = state;
     return MOJO_RESULT_ALREADY_EXISTS;
   }
-  if (!state.can_satisfy(signals)) {
-    if (signals_state)
-      *signals_state = state;
+  if (!state.can_satisfy(signals))
     return MOJO_RESULT_FAILED_PRECONDITION;
-  }
 
   awakable_list_.Add(awakable, signals, context);
   return MOJO_RESULT_OK;
diff --git a/mojo/edk/system/simple_dispatcher.cc b/mojo/edk/system/simple_dispatcher.cc
index 7624b40..0050133 100644
--- a/mojo/edk/system/simple_dispatcher.cc
+++ b/mojo/edk/system/simple_dispatcher.cc
@@ -34,18 +34,15 @@
   mutex().AssertHeld();
 
   HandleSignalsState state(GetHandleSignalsStateImplNoLock());
+  if (signals_state)
+    *signals_state = state;
   if (state.satisfies(signals)) {
     if (force)
       awakable_list_.Add(awakable, signals, context);
-    if (signals_state)
-      *signals_state = state;
     return MOJO_RESULT_ALREADY_EXISTS;
   }
-  if (!state.can_satisfy(signals)) {
-    if (signals_state)
-      *signals_state = state;
+  if (!state.can_satisfy(signals))
     return MOJO_RESULT_FAILED_PRECONDITION;
-  }
 
   awakable_list_.Add(awakable, signals, context);
   return MOJO_RESULT_OK;