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/core.h" | 5 #include "mojo/edk/system/core.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 // - Locks at the "INF" level may not have any locks taken while they are | 78 // - Locks at the "INF" level may not have any locks taken while they are |
79 // held. | 79 // held. |
80 | 80 |
81 Core::Core(embedder::PlatformSupport* platform_support) | 81 Core::Core(embedder::PlatformSupport* platform_support) |
82 : platform_support_(platform_support) { | 82 : platform_support_(platform_support) { |
83 } | 83 } |
84 | 84 |
85 Core::~Core() { | 85 Core::~Core() { |
86 } | 86 } |
87 | 87 |
88 MojoHandle Core::AddDispatcher(const scoped_refptr<Dispatcher>& dispatcher) { | 88 MojoHandle Core::AddDispatcher(Dispatcher* dispatcher) { |
89 MutexLocker locker(&handle_table_mutex_); | 89 MutexLocker locker(&handle_table_mutex_); |
90 return handle_table_.AddDispatcher(dispatcher); | 90 return handle_table_.AddDispatcher(dispatcher); |
91 } | 91 } |
92 | 92 |
93 scoped_refptr<Dispatcher> Core::GetDispatcher(MojoHandle handle) { | 93 RefPtr<Dispatcher> Core::GetDispatcher(MojoHandle handle) { |
94 if (handle == MOJO_HANDLE_INVALID) | 94 if (handle == MOJO_HANDLE_INVALID) |
95 return nullptr; | 95 return nullptr; |
96 | 96 |
97 MutexLocker locker(&handle_table_mutex_); | 97 MutexLocker locker(&handle_table_mutex_); |
98 return handle_table_.GetDispatcher(handle); | 98 return RefPtr<Dispatcher>(handle_table_.GetDispatcher(handle)); |
99 } | 99 } |
100 | 100 |
101 MojoResult Core::GetAndRemoveDispatcher(MojoHandle handle, | 101 MojoResult Core::GetAndRemoveDispatcher(MojoHandle handle, |
102 scoped_refptr<Dispatcher>* dispatcher) { | 102 RefPtr<Dispatcher>* dispatcher) { |
103 if (handle == MOJO_HANDLE_INVALID) | 103 if (handle == MOJO_HANDLE_INVALID) |
104 return MOJO_RESULT_INVALID_ARGUMENT; | 104 return MOJO_RESULT_INVALID_ARGUMENT; |
105 | 105 |
106 MutexLocker locker(&handle_table_mutex_); | 106 MutexLocker locker(&handle_table_mutex_); |
107 return handle_table_.GetAndRemoveDispatcher(handle, dispatcher); | 107 return handle_table_.GetAndRemoveDispatcher(handle, dispatcher); |
108 } | 108 } |
109 | 109 |
110 MojoResult Core::AsyncWait(MojoHandle handle, | 110 MojoResult Core::AsyncWait(MojoHandle handle, |
111 MojoHandleSignals signals, | 111 MojoHandleSignals signals, |
112 const base::Callback<void(MojoResult)>& callback) { | 112 const base::Callback<void(MojoResult)>& callback) { |
113 scoped_refptr<Dispatcher> dispatcher = GetDispatcher(handle); | 113 RefPtr<Dispatcher> dispatcher(GetDispatcher(handle)); |
114 DCHECK(dispatcher); | 114 DCHECK(dispatcher); |
115 | 115 |
116 std::unique_ptr<AsyncWaiter> waiter(new AsyncWaiter(callback)); | 116 std::unique_ptr<AsyncWaiter> waiter(new AsyncWaiter(callback)); |
117 MojoResult rv = dispatcher->AddAwakable(waiter.get(), signals, 0, nullptr); | 117 MojoResult rv = dispatcher->AddAwakable(waiter.get(), signals, 0, nullptr); |
118 if (rv == MOJO_RESULT_OK) | 118 if (rv == MOJO_RESULT_OK) |
119 ignore_result(waiter.release()); | 119 ignore_result(waiter.release()); |
120 return rv; | 120 return rv; |
121 } | 121 } |
122 | 122 |
123 MojoTimeTicks Core::GetTimeTicksNow() { | 123 MojoTimeTicks Core::GetTimeTicksNow() { |
124 return platform_support_->GetTimeTicksNow(); | 124 return platform_support_->GetTimeTicksNow(); |
125 } | 125 } |
126 | 126 |
127 MojoResult Core::Close(MojoHandle handle) { | 127 MojoResult Core::Close(MojoHandle handle) { |
128 if (handle == MOJO_HANDLE_INVALID) | 128 if (handle == MOJO_HANDLE_INVALID) |
129 return MOJO_RESULT_INVALID_ARGUMENT; | 129 return MOJO_RESULT_INVALID_ARGUMENT; |
130 | 130 |
131 scoped_refptr<Dispatcher> dispatcher; | 131 RefPtr<Dispatcher> dispatcher; |
132 { | 132 { |
133 MutexLocker locker(&handle_table_mutex_); | 133 MutexLocker locker(&handle_table_mutex_); |
134 MojoResult result = | 134 MojoResult result = |
135 handle_table_.GetAndRemoveDispatcher(handle, &dispatcher); | 135 handle_table_.GetAndRemoveDispatcher(handle, &dispatcher); |
136 if (result != MOJO_RESULT_OK) | 136 if (result != MOJO_RESULT_OK) |
137 return result; | 137 return result; |
138 } | 138 } |
139 | 139 |
140 // The dispatcher doesn't have a say in being closed, but gets notified of it. | 140 // The dispatcher doesn't have a say in being closed, but gets notified of it. |
141 // Note: This is done outside of |handle_table_mutex_|. As a result, there's a | 141 // Note: This is done outside of |handle_table_mutex_|. As a result, there's a |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 MojoResult Core::CreateMessagePipe( | 197 MojoResult Core::CreateMessagePipe( |
198 UserPointer<const MojoCreateMessagePipeOptions> options, | 198 UserPointer<const MojoCreateMessagePipeOptions> options, |
199 UserPointer<MojoHandle> message_pipe_handle0, | 199 UserPointer<MojoHandle> message_pipe_handle0, |
200 UserPointer<MojoHandle> message_pipe_handle1) { | 200 UserPointer<MojoHandle> message_pipe_handle1) { |
201 MojoCreateMessagePipeOptions validated_options = {}; | 201 MojoCreateMessagePipeOptions validated_options = {}; |
202 MojoResult result = | 202 MojoResult result = |
203 MessagePipeDispatcher::ValidateCreateOptions(options, &validated_options); | 203 MessagePipeDispatcher::ValidateCreateOptions(options, &validated_options); |
204 if (result != MOJO_RESULT_OK) | 204 if (result != MOJO_RESULT_OK) |
205 return result; | 205 return result; |
206 | 206 |
207 scoped_refptr<MessagePipeDispatcher> dispatcher0 = | 207 auto dispatcher0 = MessagePipeDispatcher::Create(validated_options); |
208 MessagePipeDispatcher::Create(validated_options); | 208 auto dispatcher1 = MessagePipeDispatcher::Create(validated_options); |
209 scoped_refptr<MessagePipeDispatcher> dispatcher1 = | |
210 MessagePipeDispatcher::Create(validated_options); | |
211 | 209 |
212 std::pair<MojoHandle, MojoHandle> handle_pair; | 210 std::pair<MojoHandle, MojoHandle> handle_pair; |
213 { | 211 { |
214 MutexLocker locker(&handle_table_mutex_); | 212 MutexLocker locker(&handle_table_mutex_); |
215 handle_pair = handle_table_.AddDispatcherPair(dispatcher0, dispatcher1); | 213 handle_pair = |
| 214 handle_table_.AddDispatcherPair(dispatcher0.get(), dispatcher1.get()); |
216 } | 215 } |
217 if (handle_pair.first == MOJO_HANDLE_INVALID) { | 216 if (handle_pair.first == MOJO_HANDLE_INVALID) { |
218 DCHECK_EQ(handle_pair.second, MOJO_HANDLE_INVALID); | 217 DCHECK_EQ(handle_pair.second, MOJO_HANDLE_INVALID); |
219 LOG(ERROR) << "Handle table full"; | 218 LOG(ERROR) << "Handle table full"; |
220 dispatcher0->Close(); | 219 dispatcher0->Close(); |
221 dispatcher1->Close(); | 220 dispatcher1->Close(); |
222 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 221 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
223 } | 222 } |
224 | 223 |
225 auto message_pipe = MessagePipe::CreateLocalLocal(); | 224 auto message_pipe = MessagePipe::CreateLocalLocal(); |
(...skipping 11 matching lines...) Expand all Loading... |
237 // dispatcher to a new dispatcher, and then close the old dispatcher. If this | 236 // dispatcher to a new dispatcher, and then close the old dispatcher. If this |
238 // isn't done, in the in-process case, calls on the old handle may complete | 237 // isn't done, in the in-process case, calls on the old handle may complete |
239 // after the the message has been received and a new handle created (and | 238 // after the the message has been received and a new handle created (and |
240 // possibly even after calls have been made on the new handle). | 239 // possibly even after calls have been made on the new handle). |
241 MojoResult Core::WriteMessage(MojoHandle message_pipe_handle, | 240 MojoResult Core::WriteMessage(MojoHandle message_pipe_handle, |
242 UserPointer<const void> bytes, | 241 UserPointer<const void> bytes, |
243 uint32_t num_bytes, | 242 uint32_t num_bytes, |
244 UserPointer<const MojoHandle> handles, | 243 UserPointer<const MojoHandle> handles, |
245 uint32_t num_handles, | 244 uint32_t num_handles, |
246 MojoWriteMessageFlags flags) { | 245 MojoWriteMessageFlags flags) { |
247 scoped_refptr<Dispatcher> dispatcher(GetDispatcher(message_pipe_handle)); | 246 RefPtr<Dispatcher> dispatcher(GetDispatcher(message_pipe_handle)); |
248 if (!dispatcher) | 247 if (!dispatcher) |
249 return MOJO_RESULT_INVALID_ARGUMENT; | 248 return MOJO_RESULT_INVALID_ARGUMENT; |
250 | 249 |
251 // Easy case: not sending any handles. | 250 // Easy case: not sending any handles. |
252 if (num_handles == 0) | 251 if (num_handles == 0) |
253 return dispatcher->WriteMessage(bytes, num_bytes, nullptr, flags); | 252 return dispatcher->WriteMessage(bytes, num_bytes, nullptr, flags); |
254 | 253 |
255 // We have to handle |handles| here, since we have to mark them busy in the | 254 // We have to handle |handles| here, since we have to mark them busy in the |
256 // global handle table. We can't delegate this to the dispatcher, since the | 255 // global handle table. We can't delegate this to the dispatcher, since the |
257 // handle table lock must be acquired before the dispatcher lock. | 256 // handle table lock must be acquired before the dispatcher lock. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 | 303 |
305 return rv; | 304 return rv; |
306 } | 305 } |
307 | 306 |
308 MojoResult Core::ReadMessage(MojoHandle message_pipe_handle, | 307 MojoResult Core::ReadMessage(MojoHandle message_pipe_handle, |
309 UserPointer<void> bytes, | 308 UserPointer<void> bytes, |
310 UserPointer<uint32_t> num_bytes, | 309 UserPointer<uint32_t> num_bytes, |
311 UserPointer<MojoHandle> handles, | 310 UserPointer<MojoHandle> handles, |
312 UserPointer<uint32_t> num_handles, | 311 UserPointer<uint32_t> num_handles, |
313 MojoReadMessageFlags flags) { | 312 MojoReadMessageFlags flags) { |
314 scoped_refptr<Dispatcher> dispatcher(GetDispatcher(message_pipe_handle)); | 313 RefPtr<Dispatcher> dispatcher(GetDispatcher(message_pipe_handle)); |
315 if (!dispatcher) | 314 if (!dispatcher) |
316 return MOJO_RESULT_INVALID_ARGUMENT; | 315 return MOJO_RESULT_INVALID_ARGUMENT; |
317 | 316 |
318 uint32_t num_handles_value = num_handles.IsNull() ? 0 : num_handles.Get(); | 317 uint32_t num_handles_value = num_handles.IsNull() ? 0 : num_handles.Get(); |
319 | 318 |
320 MojoResult rv; | 319 MojoResult rv; |
321 if (num_handles_value == 0) { | 320 if (num_handles_value == 0) { |
322 // Easy case: won't receive any handles. | 321 // Easy case: won't receive any handles. |
323 rv = dispatcher->ReadMessage(bytes, num_bytes, nullptr, &num_handles_value, | 322 rv = dispatcher->ReadMessage(bytes, num_bytes, nullptr, &num_handles_value, |
324 flags); | 323 flags); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 MojoResult Core::CreateDataPipe( | 362 MojoResult Core::CreateDataPipe( |
364 UserPointer<const MojoCreateDataPipeOptions> options, | 363 UserPointer<const MojoCreateDataPipeOptions> options, |
365 UserPointer<MojoHandle> data_pipe_producer_handle, | 364 UserPointer<MojoHandle> data_pipe_producer_handle, |
366 UserPointer<MojoHandle> data_pipe_consumer_handle) { | 365 UserPointer<MojoHandle> data_pipe_consumer_handle) { |
367 MojoCreateDataPipeOptions validated_options = {}; | 366 MojoCreateDataPipeOptions validated_options = {}; |
368 MojoResult result = | 367 MojoResult result = |
369 DataPipe::ValidateCreateOptions(options, &validated_options); | 368 DataPipe::ValidateCreateOptions(options, &validated_options); |
370 if (result != MOJO_RESULT_OK) | 369 if (result != MOJO_RESULT_OK) |
371 return result; | 370 return result; |
372 | 371 |
373 scoped_refptr<DataPipeProducerDispatcher> producer_dispatcher = | 372 auto producer_dispatcher = DataPipeProducerDispatcher::Create(); |
374 DataPipeProducerDispatcher::Create(); | 373 auto consumer_dispatcher = DataPipeConsumerDispatcher::Create(); |
375 scoped_refptr<DataPipeConsumerDispatcher> consumer_dispatcher = | |
376 DataPipeConsumerDispatcher::Create(); | |
377 | 374 |
378 std::pair<MojoHandle, MojoHandle> handle_pair; | 375 std::pair<MojoHandle, MojoHandle> handle_pair; |
379 { | 376 { |
380 MutexLocker locker(&handle_table_mutex_); | 377 MutexLocker locker(&handle_table_mutex_); |
381 handle_pair = handle_table_.AddDispatcherPair(producer_dispatcher, | 378 handle_pair = handle_table_.AddDispatcherPair(producer_dispatcher.get(), |
382 consumer_dispatcher); | 379 consumer_dispatcher.get()); |
383 } | 380 } |
384 if (handle_pair.first == MOJO_HANDLE_INVALID) { | 381 if (handle_pair.first == MOJO_HANDLE_INVALID) { |
385 DCHECK_EQ(handle_pair.second, MOJO_HANDLE_INVALID); | 382 DCHECK_EQ(handle_pair.second, MOJO_HANDLE_INVALID); |
386 LOG(ERROR) << "Handle table full"; | 383 LOG(ERROR) << "Handle table full"; |
387 producer_dispatcher->Close(); | 384 producer_dispatcher->Close(); |
388 consumer_dispatcher->Close(); | 385 consumer_dispatcher->Close(); |
389 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 386 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
390 } | 387 } |
391 DCHECK_NE(handle_pair.second, MOJO_HANDLE_INVALID); | 388 DCHECK_NE(handle_pair.second, MOJO_HANDLE_INVALID); |
392 | 389 |
393 auto data_pipe = DataPipe::CreateLocal(validated_options); | 390 auto data_pipe = DataPipe::CreateLocal(validated_options); |
394 producer_dispatcher->Init(data_pipe.Clone()); | 391 producer_dispatcher->Init(data_pipe.Clone()); |
395 consumer_dispatcher->Init(std::move(data_pipe)); | 392 consumer_dispatcher->Init(std::move(data_pipe)); |
396 | 393 |
397 data_pipe_producer_handle.Put(handle_pair.first); | 394 data_pipe_producer_handle.Put(handle_pair.first); |
398 data_pipe_consumer_handle.Put(handle_pair.second); | 395 data_pipe_consumer_handle.Put(handle_pair.second); |
399 return MOJO_RESULT_OK; | 396 return MOJO_RESULT_OK; |
400 } | 397 } |
401 | 398 |
402 MojoResult Core::WriteData(MojoHandle data_pipe_producer_handle, | 399 MojoResult Core::WriteData(MojoHandle data_pipe_producer_handle, |
403 UserPointer<const void> elements, | 400 UserPointer<const void> elements, |
404 UserPointer<uint32_t> num_bytes, | 401 UserPointer<uint32_t> num_bytes, |
405 MojoWriteDataFlags flags) { | 402 MojoWriteDataFlags flags) { |
406 scoped_refptr<Dispatcher> dispatcher( | 403 RefPtr<Dispatcher> dispatcher(GetDispatcher(data_pipe_producer_handle)); |
407 GetDispatcher(data_pipe_producer_handle)); | |
408 if (!dispatcher) | 404 if (!dispatcher) |
409 return MOJO_RESULT_INVALID_ARGUMENT; | 405 return MOJO_RESULT_INVALID_ARGUMENT; |
410 | 406 |
411 return dispatcher->WriteData(elements, num_bytes, flags); | 407 return dispatcher->WriteData(elements, num_bytes, flags); |
412 } | 408 } |
413 | 409 |
414 MojoResult Core::BeginWriteData(MojoHandle data_pipe_producer_handle, | 410 MojoResult Core::BeginWriteData(MojoHandle data_pipe_producer_handle, |
415 UserPointer<void*> buffer, | 411 UserPointer<void*> buffer, |
416 UserPointer<uint32_t> buffer_num_bytes, | 412 UserPointer<uint32_t> buffer_num_bytes, |
417 MojoWriteDataFlags flags) { | 413 MojoWriteDataFlags flags) { |
418 scoped_refptr<Dispatcher> dispatcher( | 414 RefPtr<Dispatcher> dispatcher(GetDispatcher(data_pipe_producer_handle)); |
419 GetDispatcher(data_pipe_producer_handle)); | |
420 if (!dispatcher) | 415 if (!dispatcher) |
421 return MOJO_RESULT_INVALID_ARGUMENT; | 416 return MOJO_RESULT_INVALID_ARGUMENT; |
422 | 417 |
423 return dispatcher->BeginWriteData(buffer, buffer_num_bytes, flags); | 418 return dispatcher->BeginWriteData(buffer, buffer_num_bytes, flags); |
424 } | 419 } |
425 | 420 |
426 MojoResult Core::EndWriteData(MojoHandle data_pipe_producer_handle, | 421 MojoResult Core::EndWriteData(MojoHandle data_pipe_producer_handle, |
427 uint32_t num_bytes_written) { | 422 uint32_t num_bytes_written) { |
428 scoped_refptr<Dispatcher> dispatcher( | 423 RefPtr<Dispatcher> dispatcher(GetDispatcher(data_pipe_producer_handle)); |
429 GetDispatcher(data_pipe_producer_handle)); | |
430 if (!dispatcher) | 424 if (!dispatcher) |
431 return MOJO_RESULT_INVALID_ARGUMENT; | 425 return MOJO_RESULT_INVALID_ARGUMENT; |
432 | 426 |
433 return dispatcher->EndWriteData(num_bytes_written); | 427 return dispatcher->EndWriteData(num_bytes_written); |
434 } | 428 } |
435 | 429 |
436 MojoResult Core::ReadData(MojoHandle data_pipe_consumer_handle, | 430 MojoResult Core::ReadData(MojoHandle data_pipe_consumer_handle, |
437 UserPointer<void> elements, | 431 UserPointer<void> elements, |
438 UserPointer<uint32_t> num_bytes, | 432 UserPointer<uint32_t> num_bytes, |
439 MojoReadDataFlags flags) { | 433 MojoReadDataFlags flags) { |
440 scoped_refptr<Dispatcher> dispatcher( | 434 RefPtr<Dispatcher> dispatcher(GetDispatcher(data_pipe_consumer_handle)); |
441 GetDispatcher(data_pipe_consumer_handle)); | |
442 if (!dispatcher) | 435 if (!dispatcher) |
443 return MOJO_RESULT_INVALID_ARGUMENT; | 436 return MOJO_RESULT_INVALID_ARGUMENT; |
444 | 437 |
445 return dispatcher->ReadData(elements, num_bytes, flags); | 438 return dispatcher->ReadData(elements, num_bytes, flags); |
446 } | 439 } |
447 | 440 |
448 MojoResult Core::BeginReadData(MojoHandle data_pipe_consumer_handle, | 441 MojoResult Core::BeginReadData(MojoHandle data_pipe_consumer_handle, |
449 UserPointer<const void*> buffer, | 442 UserPointer<const void*> buffer, |
450 UserPointer<uint32_t> buffer_num_bytes, | 443 UserPointer<uint32_t> buffer_num_bytes, |
451 MojoReadDataFlags flags) { | 444 MojoReadDataFlags flags) { |
452 scoped_refptr<Dispatcher> dispatcher( | 445 RefPtr<Dispatcher> dispatcher(GetDispatcher(data_pipe_consumer_handle)); |
453 GetDispatcher(data_pipe_consumer_handle)); | |
454 if (!dispatcher) | 446 if (!dispatcher) |
455 return MOJO_RESULT_INVALID_ARGUMENT; | 447 return MOJO_RESULT_INVALID_ARGUMENT; |
456 | 448 |
457 return dispatcher->BeginReadData(buffer, buffer_num_bytes, flags); | 449 return dispatcher->BeginReadData(buffer, buffer_num_bytes, flags); |
458 } | 450 } |
459 | 451 |
460 MojoResult Core::EndReadData(MojoHandle data_pipe_consumer_handle, | 452 MojoResult Core::EndReadData(MojoHandle data_pipe_consumer_handle, |
461 uint32_t num_bytes_read) { | 453 uint32_t num_bytes_read) { |
462 scoped_refptr<Dispatcher> dispatcher( | 454 RefPtr<Dispatcher> dispatcher(GetDispatcher(data_pipe_consumer_handle)); |
463 GetDispatcher(data_pipe_consumer_handle)); | |
464 if (!dispatcher) | 455 if (!dispatcher) |
465 return MOJO_RESULT_INVALID_ARGUMENT; | 456 return MOJO_RESULT_INVALID_ARGUMENT; |
466 | 457 |
467 return dispatcher->EndReadData(num_bytes_read); | 458 return dispatcher->EndReadData(num_bytes_read); |
468 } | 459 } |
469 | 460 |
470 MojoResult Core::CreateSharedBuffer( | 461 MojoResult Core::CreateSharedBuffer( |
471 UserPointer<const MojoCreateSharedBufferOptions> options, | 462 UserPointer<const MojoCreateSharedBufferOptions> options, |
472 uint64_t num_bytes, | 463 uint64_t num_bytes, |
473 UserPointer<MojoHandle> shared_buffer_handle) { | 464 UserPointer<MojoHandle> shared_buffer_handle) { |
474 MojoCreateSharedBufferOptions validated_options = {}; | 465 MojoCreateSharedBufferOptions validated_options = {}; |
475 MojoResult result = SharedBufferDispatcher::ValidateCreateOptions( | 466 MojoResult result = SharedBufferDispatcher::ValidateCreateOptions( |
476 options, &validated_options); | 467 options, &validated_options); |
477 if (result != MOJO_RESULT_OK) | 468 if (result != MOJO_RESULT_OK) |
478 return result; | 469 return result; |
479 | 470 |
480 scoped_refptr<SharedBufferDispatcher> dispatcher; | 471 auto dispatcher = SharedBufferDispatcher::Create( |
481 result = SharedBufferDispatcher::Create(platform_support_, validated_options, | 472 platform_support_, validated_options, num_bytes, &result); |
482 num_bytes, &dispatcher); | |
483 if (result != MOJO_RESULT_OK) { | 473 if (result != MOJO_RESULT_OK) { |
484 DCHECK(!dispatcher); | 474 DCHECK(!dispatcher); |
485 return result; | 475 return result; |
486 } | 476 } |
487 | 477 |
488 MojoHandle h = AddDispatcher(dispatcher); | 478 MojoHandle h = AddDispatcher(dispatcher.get()); |
489 if (h == MOJO_HANDLE_INVALID) { | 479 if (h == MOJO_HANDLE_INVALID) { |
490 LOG(ERROR) << "Handle table full"; | 480 LOG(ERROR) << "Handle table full"; |
491 dispatcher->Close(); | 481 dispatcher->Close(); |
492 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 482 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
493 } | 483 } |
494 | 484 |
495 shared_buffer_handle.Put(h); | 485 shared_buffer_handle.Put(h); |
496 return MOJO_RESULT_OK; | 486 return MOJO_RESULT_OK; |
497 } | 487 } |
498 | 488 |
499 MojoResult Core::DuplicateBufferHandle( | 489 MojoResult Core::DuplicateBufferHandle( |
500 MojoHandle buffer_handle, | 490 MojoHandle buffer_handle, |
501 UserPointer<const MojoDuplicateBufferHandleOptions> options, | 491 UserPointer<const MojoDuplicateBufferHandleOptions> options, |
502 UserPointer<MojoHandle> new_buffer_handle) { | 492 UserPointer<MojoHandle> new_buffer_handle) { |
503 scoped_refptr<Dispatcher> dispatcher(GetDispatcher(buffer_handle)); | 493 RefPtr<Dispatcher> dispatcher(GetDispatcher(buffer_handle)); |
504 if (!dispatcher) | 494 if (!dispatcher) |
505 return MOJO_RESULT_INVALID_ARGUMENT; | 495 return MOJO_RESULT_INVALID_ARGUMENT; |
506 | 496 |
507 // Don't verify |options| here; that's the dispatcher's job. | 497 // Don't verify |options| here; that's the dispatcher's job. |
508 scoped_refptr<Dispatcher> new_dispatcher; | 498 RefPtr<Dispatcher> new_dispatcher; |
509 MojoResult result = | 499 MojoResult result = |
510 dispatcher->DuplicateBufferHandle(options, &new_dispatcher); | 500 dispatcher->DuplicateBufferHandle(options, &new_dispatcher); |
511 if (result != MOJO_RESULT_OK) | 501 if (result != MOJO_RESULT_OK) |
512 return result; | 502 return result; |
513 | 503 |
514 MojoHandle new_handle = AddDispatcher(new_dispatcher); | 504 MojoHandle new_handle = AddDispatcher(new_dispatcher.get()); |
515 if (new_handle == MOJO_HANDLE_INVALID) { | 505 if (new_handle == MOJO_HANDLE_INVALID) { |
516 LOG(ERROR) << "Handle table full"; | 506 LOG(ERROR) << "Handle table full"; |
517 dispatcher->Close(); | 507 new_dispatcher->Close(); |
518 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 508 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
519 } | 509 } |
520 | 510 |
521 new_buffer_handle.Put(new_handle); | 511 new_buffer_handle.Put(new_handle); |
522 return MOJO_RESULT_OK; | 512 return MOJO_RESULT_OK; |
523 } | 513 } |
524 | 514 |
525 MojoResult Core::MapBuffer(MojoHandle buffer_handle, | 515 MojoResult Core::MapBuffer(MojoHandle buffer_handle, |
526 uint64_t offset, | 516 uint64_t offset, |
527 uint64_t num_bytes, | 517 uint64_t num_bytes, |
528 UserPointer<void*> buffer, | 518 UserPointer<void*> buffer, |
529 MojoMapBufferFlags flags) { | 519 MojoMapBufferFlags flags) { |
530 scoped_refptr<Dispatcher> dispatcher(GetDispatcher(buffer_handle)); | 520 RefPtr<Dispatcher> dispatcher(GetDispatcher(buffer_handle)); |
531 if (!dispatcher) | 521 if (!dispatcher) |
532 return MOJO_RESULT_INVALID_ARGUMENT; | 522 return MOJO_RESULT_INVALID_ARGUMENT; |
533 | 523 |
534 std::unique_ptr<embedder::PlatformSharedBufferMapping> mapping; | 524 std::unique_ptr<embedder::PlatformSharedBufferMapping> mapping; |
535 MojoResult result = dispatcher->MapBuffer(offset, num_bytes, flags, &mapping); | 525 MojoResult result = dispatcher->MapBuffer(offset, num_bytes, flags, &mapping); |
536 if (result != MOJO_RESULT_OK) | 526 if (result != MOJO_RESULT_OK) |
537 return result; | 527 return result; |
538 | 528 |
539 DCHECK(mapping); | 529 DCHECK(mapping); |
540 void* address = mapping->GetBase(); | 530 void* address = mapping->GetBase(); |
(...skipping 22 matching lines...) Expand all Loading... |
563 uint32_t num_handles, | 553 uint32_t num_handles, |
564 MojoDeadline deadline, | 554 MojoDeadline deadline, |
565 uint32_t* result_index, | 555 uint32_t* result_index, |
566 HandleSignalsState* signals_states) { | 556 HandleSignalsState* signals_states) { |
567 DCHECK_GT(num_handles, 0u); | 557 DCHECK_GT(num_handles, 0u); |
568 DCHECK_EQ(*result_index, static_cast<uint32_t>(-1)); | 558 DCHECK_EQ(*result_index, static_cast<uint32_t>(-1)); |
569 | 559 |
570 DispatcherVector dispatchers; | 560 DispatcherVector dispatchers; |
571 dispatchers.reserve(num_handles); | 561 dispatchers.reserve(num_handles); |
572 for (uint32_t i = 0; i < num_handles; i++) { | 562 for (uint32_t i = 0; i < num_handles; i++) { |
573 scoped_refptr<Dispatcher> dispatcher = GetDispatcher(handles[i]); | 563 RefPtr<Dispatcher> dispatcher = GetDispatcher(handles[i]); |
574 if (!dispatcher) { | 564 if (!dispatcher) { |
575 *result_index = i; | 565 *result_index = i; |
576 return MOJO_RESULT_INVALID_ARGUMENT; | 566 return MOJO_RESULT_INVALID_ARGUMENT; |
577 } | 567 } |
578 dispatchers.push_back(dispatcher); | 568 dispatchers.push_back(dispatcher); |
579 } | 569 } |
580 | 570 |
581 // TODO(vtl): Should make the waiter live (permanently) in TLS. | 571 // TODO(vtl): Should make the waiter live (permanently) in TLS. |
582 Waiter waiter; | 572 Waiter waiter; |
583 waiter.Init(); | 573 waiter.Init(); |
(...skipping 25 matching lines...) Expand all Loading... |
609 if (signals_states) { | 599 if (signals_states) { |
610 for (; i < num_handles; i++) | 600 for (; i < num_handles; i++) |
611 signals_states[i] = dispatchers[i]->GetHandleSignalsState(); | 601 signals_states[i] = dispatchers[i]->GetHandleSignalsState(); |
612 } | 602 } |
613 | 603 |
614 return rv; | 604 return rv; |
615 } | 605 } |
616 | 606 |
617 } // namespace system | 607 } // namespace system |
618 } // namespace mojo | 608 } // namespace mojo |
OLD | NEW |