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

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

Issue 1748503002: [mojo-edk] Add MojoWatch and MojoCancelWatch APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: revert RequestContext usage, nits Created 4 years, 9 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_producer_dispatcher.h ('k') | mojo/edk/system/dispatcher.h » ('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/data_pipe_producer_dispatcher.h" 5 #include "mojo/edk/system/data_pipe_producer_dispatcher.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "mojo/edk/embedder/embedder_internal.h" 16 #include "mojo/edk/embedder/embedder_internal.h"
17 #include "mojo/edk/embedder/platform_shared_buffer.h" 17 #include "mojo/edk/embedder/platform_shared_buffer.h"
18 #include "mojo/edk/system/configuration.h" 18 #include "mojo/edk/system/configuration.h"
19 #include "mojo/edk/system/core.h" 19 #include "mojo/edk/system/core.h"
20 #include "mojo/edk/system/data_pipe_control_message.h" 20 #include "mojo/edk/system/data_pipe_control_message.h"
21 #include "mojo/edk/system/node_controller.h" 21 #include "mojo/edk/system/node_controller.h"
22 #include "mojo/edk/system/ports_message.h" 22 #include "mojo/edk/system/ports_message.h"
23 #include "mojo/edk/system/request_context.h"
24 #include "mojo/public/c/system/data_pipe.h"
23 25
24 namespace mojo { 26 namespace mojo {
25 namespace edk { 27 namespace edk {
26 28
27 namespace { 29 namespace {
28 30
29 struct SerializedState { 31 struct SerializedState {
30 MojoCreateDataPipeOptions options; 32 MojoCreateDataPipeOptions options;
31 uint64_t pipe_id; 33 uint64_t pipe_id;
32 bool peer_closed; 34 bool peer_closed;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 Dispatcher::Type DataPipeProducerDispatcher::GetType() const { 80 Dispatcher::Type DataPipeProducerDispatcher::GetType() const {
79 return Type::DATA_PIPE_PRODUCER; 81 return Type::DATA_PIPE_PRODUCER;
80 } 82 }
81 83
82 MojoResult DataPipeProducerDispatcher::Close() { 84 MojoResult DataPipeProducerDispatcher::Close() {
83 base::AutoLock lock(lock_); 85 base::AutoLock lock(lock_);
84 DVLOG(1) << "Closing data pipe producer " << pipe_id_; 86 DVLOG(1) << "Closing data pipe producer " << pipe_id_;
85 return CloseNoLock(); 87 return CloseNoLock();
86 } 88 }
87 89
90 MojoResult DataPipeProducerDispatcher::Watch(
91 MojoHandleSignals signals,
92 const Watcher::WatchCallback& callback,
93 uintptr_t context) {
94 base::AutoLock lock(lock_);
95
96 if (is_closed_ || in_transit_)
97 return MOJO_RESULT_INVALID_ARGUMENT;
98
99 return awakable_list_.AddWatcher(
100 signals, callback, context, GetHandleSignalsStateNoLock());
101 }
102
103 MojoResult DataPipeProducerDispatcher::CancelWatch(uintptr_t context) {
104 base::AutoLock lock(lock_);
105
106 if (is_closed_ || in_transit_)
107 return MOJO_RESULT_INVALID_ARGUMENT;
108
109 return awakable_list_.RemoveWatcher(context);
110 }
111
88 MojoResult DataPipeProducerDispatcher::WriteData(const void* elements, 112 MojoResult DataPipeProducerDispatcher::WriteData(const void* elements,
89 uint32_t* num_bytes, 113 uint32_t* num_bytes,
90 MojoWriteDataFlags flags) { 114 MojoWriteDataFlags flags) {
91 base::AutoLock lock(lock_); 115 base::AutoLock lock(lock_);
92 if (!shared_ring_buffer_ || in_transit_) 116 if (!shared_ring_buffer_ || in_transit_)
93 return MOJO_RESULT_INVALID_ARGUMENT; 117 return MOJO_RESULT_INVALID_ARGUMENT;
94 118
95 if (in_two_phase_write_) 119 if (in_two_phase_write_)
96 return MOJO_RESULT_BUSY; 120 return MOJO_RESULT_BUSY;
97 121
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 // to ignore. 469 // to ignore.
446 if (transferred_) 470 if (transferred_)
447 return; 471 return;
448 472
449 DVLOG(1) << "Control port status changed for data pipe producer " << pipe_id_; 473 DVLOG(1) << "Control port status changed for data pipe producer " << pipe_id_;
450 474
451 UpdateSignalsStateNoLock(); 475 UpdateSignalsStateNoLock();
452 } 476 }
453 477
454 void DataPipeProducerDispatcher::UpdateSignalsStateNoLock() { 478 void DataPipeProducerDispatcher::UpdateSignalsStateNoLock() {
479 RequestContext request_context;
480
455 lock_.AssertAcquired(); 481 lock_.AssertAcquired();
456 482
457 bool was_peer_closed = peer_closed_; 483 bool was_peer_closed = peer_closed_;
458 size_t previous_capacity = available_capacity_; 484 size_t previous_capacity = available_capacity_;
459 485
460 ports::PortStatus port_status; 486 ports::PortStatus port_status;
461 if (node_controller_->node()->GetStatus(control_port_, &port_status) != 487 if (node_controller_->node()->GetStatus(control_port_, &port_status) !=
462 ports::OK || 488 ports::OK ||
463 !port_status.receiving_messages) { 489 !port_status.receiving_messages) {
464 DVLOG(1) << "Data pipe producer " << pipe_id_ << " is aware of peer closure" 490 DVLOG(1) << "Data pipe producer " << pipe_id_ << " is aware of peer closure"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 } 528 }
503 529
504 if (peer_closed_ != was_peer_closed || 530 if (peer_closed_ != was_peer_closed ||
505 available_capacity_ != previous_capacity) { 531 available_capacity_ != previous_capacity) {
506 awakable_list_.AwakeForStateChange(GetHandleSignalsStateNoLock()); 532 awakable_list_.AwakeForStateChange(GetHandleSignalsStateNoLock());
507 } 533 }
508 } 534 }
509 535
510 } // namespace edk 536 } // namespace edk
511 } // namespace mojo 537 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/data_pipe_producer_dispatcher.h ('k') | mojo/edk/system/dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698