Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: mojo/edk/system/local_message_pipe_endpoint.cc

Issue 2072353002: Give AwakableList's wake-up method the old state in addition to the new state. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/edk/system/data_pipe.cc ('k') | mojo/edk/system/mock_simple_dispatcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/edk/system/local_message_pipe_endpoint.h" 5 #include "mojo/edk/system/local_message_pipe_endpoint.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 21 matching lines...) Expand all
32 32
33 bool LocalMessagePipeEndpoint::OnPeerClose() { 33 bool LocalMessagePipeEndpoint::OnPeerClose() {
34 DCHECK(is_open_); 34 DCHECK(is_open_);
35 DCHECK(is_peer_open_); 35 DCHECK(is_peer_open_);
36 36
37 HandleSignalsState old_state = GetHandleSignalsState(); 37 HandleSignalsState old_state = GetHandleSignalsState();
38 is_peer_open_ = false; 38 is_peer_open_ = false;
39 HandleSignalsState new_state = GetHandleSignalsState(); 39 HandleSignalsState new_state = GetHandleSignalsState();
40 40
41 if (!new_state.equals(old_state)) 41 if (!new_state.equals(old_state))
42 awakable_list_.AwakeForStateChange(new_state); 42 awakable_list_.OnStateChange(old_state, new_state);
43 43
44 return true; 44 return true;
45 } 45 }
46 46
47 void LocalMessagePipeEndpoint::EnqueueMessage( 47 void LocalMessagePipeEndpoint::EnqueueMessage(
48 std::unique_ptr<MessageInTransit> message) { 48 std::unique_ptr<MessageInTransit> message) {
49 DCHECK(is_open_); 49 DCHECK(is_open_);
50 DCHECK(is_peer_open_); 50 DCHECK(is_peer_open_);
51 51
52 bool was_empty = message_queue_.IsEmpty(); 52 HandleSignalsState old_state = GetHandleSignalsState();
53 message_queue_.AddMessage(std::move(message)); 53 message_queue_.AddMessage(std::move(message));
54 if (was_empty) 54 HandleSignalsState new_state = GetHandleSignalsState();
55 awakable_list_.AwakeForStateChange(GetHandleSignalsState()); 55
56 if (!new_state.equals(old_state))
57 awakable_list_.OnStateChange(old_state, new_state);
56 } 58 }
57 59
58 void LocalMessagePipeEndpoint::Close() { 60 void LocalMessagePipeEndpoint::Close() {
59 DCHECK(is_open_); 61 DCHECK(is_open_);
60 is_open_ = false; 62 is_open_ = false;
61 message_queue_.Clear(); 63 message_queue_.Clear();
62 } 64 }
63 65
64 void LocalMessagePipeEndpoint::CancelAllState() { 66 void LocalMessagePipeEndpoint::CancelAllState() {
65 DCHECK(is_open_); 67 DCHECK(is_open_);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 } 110 }
109 } 111 }
110 } else { 112 } else {
111 if (num_handles) 113 if (num_handles)
112 *num_handles = 0; 114 *num_handles = 0;
113 } 115 }
114 116
115 message = nullptr; 117 message = nullptr;
116 118
117 if (enough_space || (flags & MOJO_READ_MESSAGE_FLAG_MAY_DISCARD)) { 119 if (enough_space || (flags & MOJO_READ_MESSAGE_FLAG_MAY_DISCARD)) {
120 HandleSignalsState old_state = GetHandleSignalsState();
118 message_queue_.DiscardMessage(); 121 message_queue_.DiscardMessage();
122 HandleSignalsState new_state = GetHandleSignalsState();
119 123
120 // Now it's empty, thus no longer readable. 124 if (!new_state.equals(old_state))
121 if (message_queue_.IsEmpty()) { 125 awakable_list_.OnStateChange(old_state, new_state);
122 // It's currently not possible to wait for non-readability, but we should
123 // do the state change anyway.
124 awakable_list_.AwakeForStateChange(GetHandleSignalsState());
125 }
126 } 126 }
127 127
128 if (!enough_space) 128 if (!enough_space)
129 return MOJO_RESULT_RESOURCE_EXHAUSTED; 129 return MOJO_RESULT_RESOURCE_EXHAUSTED;
130 130
131 return MOJO_RESULT_OK; 131 return MOJO_RESULT_OK;
132 } 132 }
133 133
134 HandleSignalsState LocalMessagePipeEndpoint::GetHandleSignalsState() const { 134 HandleSignalsState LocalMessagePipeEndpoint::GetHandleSignalsState() const {
135 HandleSignalsState rv; 135 HandleSignalsState rv;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 uint64_t context, 188 uint64_t context,
189 HandleSignalsState* signals_state) { 189 HandleSignalsState* signals_state) {
190 DCHECK(is_open_); 190 DCHECK(is_open_);
191 awakable_list_.RemoveWithContext(awakable, context); 191 awakable_list_.RemoveWithContext(awakable, context);
192 if (signals_state) 192 if (signals_state)
193 *signals_state = GetHandleSignalsState(); 193 *signals_state = GetHandleSignalsState();
194 } 194 }
195 195
196 } // namespace system 196 } // namespace system
197 } // namespace mojo 197 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/data_pipe.cc ('k') | mojo/edk/system/mock_simple_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698