OLD | NEW |
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/data_pipe_consumer_dispatcher.h" | 5 #include "mojo/edk/system/data_pipe_consumer_dispatcher.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 #include <limits> | 11 #include <limits> |
12 #include <utility> | 12 #include <utility> |
13 | 13 |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
18 #include "mojo/edk/embedder/embedder_internal.h" | 18 #include "mojo/edk/embedder/embedder_internal.h" |
19 #include "mojo/edk/embedder/platform_shared_buffer.h" | 19 #include "mojo/edk/embedder/platform_shared_buffer.h" |
20 #include "mojo/edk/system/core.h" | 20 #include "mojo/edk/system/core.h" |
21 #include "mojo/edk/system/data_pipe_control_message.h" | 21 #include "mojo/edk/system/data_pipe_control_message.h" |
22 #include "mojo/edk/system/node_controller.h" | 22 #include "mojo/edk/system/node_controller.h" |
23 #include "mojo/edk/system/ports_message.h" | 23 #include "mojo/edk/system/ports_message.h" |
| 24 #include "mojo/edk/system/request_context.h" |
24 #include "mojo/public/c/system/data_pipe.h" | 25 #include "mojo/public/c/system/data_pipe.h" |
25 | 26 |
26 namespace mojo { | 27 namespace mojo { |
27 namespace edk { | 28 namespace edk { |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 struct MOJO_ALIGNAS(8) SerializedState { | 32 struct MOJO_ALIGNAS(8) SerializedState { |
32 MojoCreateDataPipeOptions options; | 33 MojoCreateDataPipeOptions options; |
33 uint64_t pipe_id; | 34 uint64_t pipe_id; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 Dispatcher::Type DataPipeConsumerDispatcher::GetType() const { | 80 Dispatcher::Type DataPipeConsumerDispatcher::GetType() const { |
80 return Type::DATA_PIPE_CONSUMER; | 81 return Type::DATA_PIPE_CONSUMER; |
81 } | 82 } |
82 | 83 |
83 MojoResult DataPipeConsumerDispatcher::Close() { | 84 MojoResult DataPipeConsumerDispatcher::Close() { |
84 base::AutoLock lock(lock_); | 85 base::AutoLock lock(lock_); |
85 DVLOG(1) << "Closing data pipe consumer " << pipe_id_; | 86 DVLOG(1) << "Closing data pipe consumer " << pipe_id_; |
86 return CloseNoLock(); | 87 return CloseNoLock(); |
87 } | 88 } |
88 | 89 |
| 90 |
| 91 MojoResult DataPipeConsumerDispatcher::Watch( |
| 92 MojoHandleSignals signals, |
| 93 const Watcher::WatchCallback& callback, |
| 94 uintptr_t context) { |
| 95 base::AutoLock lock(lock_); |
| 96 |
| 97 if (is_closed_ || in_transit_) |
| 98 return MOJO_RESULT_INVALID_ARGUMENT; |
| 99 |
| 100 return awakable_list_.AddWatcher( |
| 101 signals, callback, context, GetHandleSignalsStateNoLock()); |
| 102 } |
| 103 |
| 104 MojoResult DataPipeConsumerDispatcher::CancelWatch(uintptr_t context) { |
| 105 base::AutoLock lock(lock_); |
| 106 |
| 107 if (is_closed_ || in_transit_) |
| 108 return MOJO_RESULT_INVALID_ARGUMENT; |
| 109 |
| 110 return awakable_list_.RemoveWatcher(context); |
| 111 } |
| 112 |
89 MojoResult DataPipeConsumerDispatcher::ReadData(void* elements, | 113 MojoResult DataPipeConsumerDispatcher::ReadData(void* elements, |
90 uint32_t* num_bytes, | 114 uint32_t* num_bytes, |
91 MojoReadDataFlags flags) { | 115 MojoReadDataFlags flags) { |
92 base::AutoLock lock(lock_); | 116 base::AutoLock lock(lock_); |
93 if (!shared_ring_buffer_ || in_transit_) | 117 if (!shared_ring_buffer_ || in_transit_) |
94 return MOJO_RESULT_INVALID_ARGUMENT; | 118 return MOJO_RESULT_INVALID_ARGUMENT; |
95 | 119 |
96 if (in_two_phase_read_) | 120 if (in_two_phase_read_) |
97 return MOJO_RESULT_BUSY; | 121 return MOJO_RESULT_BUSY; |
98 | 122 |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 // to ignore. | 491 // to ignore. |
468 if (transferred_) | 492 if (transferred_) |
469 return; | 493 return; |
470 | 494 |
471 DVLOG(1) << "Control port status changed for data pipe producer " << pipe_id_; | 495 DVLOG(1) << "Control port status changed for data pipe producer " << pipe_id_; |
472 | 496 |
473 UpdateSignalsStateNoLock(); | 497 UpdateSignalsStateNoLock(); |
474 } | 498 } |
475 | 499 |
476 void DataPipeConsumerDispatcher::UpdateSignalsStateNoLock() { | 500 void DataPipeConsumerDispatcher::UpdateSignalsStateNoLock() { |
| 501 RequestContext request_context; |
| 502 |
477 lock_.AssertAcquired(); | 503 lock_.AssertAcquired(); |
478 | 504 |
479 bool was_peer_closed = peer_closed_; | 505 bool was_peer_closed = peer_closed_; |
480 size_t previous_bytes_available = bytes_available_; | 506 size_t previous_bytes_available = bytes_available_; |
481 | 507 |
482 ports::PortStatus port_status; | 508 ports::PortStatus port_status; |
483 if (node_controller_->node()->GetStatus(control_port_, &port_status) != | 509 if (node_controller_->node()->GetStatus(control_port_, &port_status) != |
484 ports::OK || | 510 ports::OK || |
485 !port_status.receiving_messages) { | 511 !port_status.receiving_messages) { |
486 DVLOG(1) << "Data pipe consumer " << pipe_id_ << " is aware of peer closure" | 512 DVLOG(1) << "Data pipe consumer " << pipe_id_ << " is aware of peer closure" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 } | 550 } |
525 | 551 |
526 if (peer_closed_ != was_peer_closed || | 552 if (peer_closed_ != was_peer_closed || |
527 bytes_available_ != previous_bytes_available) { | 553 bytes_available_ != previous_bytes_available) { |
528 awakable_list_.AwakeForStateChange(GetHandleSignalsStateNoLock()); | 554 awakable_list_.AwakeForStateChange(GetHandleSignalsStateNoLock()); |
529 } | 555 } |
530 } | 556 } |
531 | 557 |
532 } // namespace edk | 558 } // namespace edk |
533 } // namespace mojo | 559 } // namespace mojo |
OLD | NEW |