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

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: there can be only one RequestContext! 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
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/public/c/system/data_pipe.h"
23 24
24 namespace mojo { 25 namespace mojo {
25 namespace edk { 26 namespace edk {
26 27
27 namespace { 28 namespace {
28 29
29 struct SerializedState { 30 struct SerializedState {
30 MojoCreateDataPipeOptions options; 31 MojoCreateDataPipeOptions options;
31 uint64_t pipe_id; 32 uint64_t pipe_id;
32 bool peer_closed; 33 bool peer_closed;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 Dispatcher::Type DataPipeProducerDispatcher::GetType() const { 79 Dispatcher::Type DataPipeProducerDispatcher::GetType() const {
79 return Type::DATA_PIPE_PRODUCER; 80 return Type::DATA_PIPE_PRODUCER;
80 } 81 }
81 82
82 MojoResult DataPipeProducerDispatcher::Close() { 83 MojoResult DataPipeProducerDispatcher::Close() {
83 base::AutoLock lock(lock_); 84 base::AutoLock lock(lock_);
84 DVLOG(1) << "Closing data pipe producer " << pipe_id_; 85 DVLOG(1) << "Closing data pipe producer " << pipe_id_;
85 return CloseNoLock(); 86 return CloseNoLock();
86 } 87 }
87 88
89 MojoResult DataPipeProducerDispatcher::Watch(
90 MojoHandleSignals signals,
91 const Watcher::WatchCallback& callback,
92 uintptr_t context) {
93 base::AutoLock lock(lock_);
94
95 if (is_closed_ || in_transit_)
96 return MOJO_RESULT_INVALID_ARGUMENT;
97
98 return awakable_list_.AddWatcher(
99 signals, callback, context, GetHandleSignalsStateNoLock());
100 }
101
102 MojoResult DataPipeProducerDispatcher::CancelWatch(uintptr_t context) {
103 base::AutoLock lock(lock_);
104
105 if (is_closed_ || in_transit_)
106 return MOJO_RESULT_INVALID_ARGUMENT;
107
108 return awakable_list_.RemoveWatcher(context);
109 }
110
88 MojoResult DataPipeProducerDispatcher::WriteData(const void* elements, 111 MojoResult DataPipeProducerDispatcher::WriteData(const void* elements,
89 uint32_t* num_bytes, 112 uint32_t* num_bytes,
90 MojoWriteDataFlags flags) { 113 MojoWriteDataFlags flags) {
91 base::AutoLock lock(lock_); 114 base::AutoLock lock(lock_);
92 if (!shared_ring_buffer_ || in_transit_) 115 if (!shared_ring_buffer_ || in_transit_)
93 return MOJO_RESULT_INVALID_ARGUMENT; 116 return MOJO_RESULT_INVALID_ARGUMENT;
94 117
95 if (in_two_phase_write_) 118 if (in_two_phase_write_)
96 return MOJO_RESULT_BUSY; 119 return MOJO_RESULT_BUSY;
97 120
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 } 525 }
503 526
504 if (peer_closed_ != was_peer_closed || 527 if (peer_closed_ != was_peer_closed ||
505 available_capacity_ != previous_capacity) { 528 available_capacity_ != previous_capacity) {
506 awakable_list_.AwakeForStateChange(GetHandleSignalsStateNoLock()); 529 awakable_list_.AwakeForStateChange(GetHandleSignalsStateNoLock());
507 } 530 }
508 } 531 }
509 532
510 } // namespace edk 533 } // namespace edk
511 } // namespace mojo 534 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698