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

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

Issue 1785843002: [mojo] Implement pipe fusion API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase 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/core.h ('k') | mojo/edk/system/message_pipe_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/core.h" 5 #include "mojo/edk/system/core.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 *message_pipe_handle0 = AddDispatcher( 444 *message_pipe_handle0 = AddDispatcher(
445 new MessagePipeDispatcher(GetNodeController(), port0, pipe_id, 0)); 445 new MessagePipeDispatcher(GetNodeController(), port0, pipe_id, 0));
446 if (*message_pipe_handle0 == MOJO_HANDLE_INVALID) 446 if (*message_pipe_handle0 == MOJO_HANDLE_INVALID)
447 return MOJO_RESULT_RESOURCE_EXHAUSTED; 447 return MOJO_RESULT_RESOURCE_EXHAUSTED;
448 448
449 *message_pipe_handle1 = AddDispatcher( 449 *message_pipe_handle1 = AddDispatcher(
450 new MessagePipeDispatcher(GetNodeController(), port1, pipe_id, 1)); 450 new MessagePipeDispatcher(GetNodeController(), port1, pipe_id, 1));
451 if (*message_pipe_handle1 == MOJO_HANDLE_INVALID) { 451 if (*message_pipe_handle1 == MOJO_HANDLE_INVALID) {
452 scoped_refptr<Dispatcher> unused; 452 scoped_refptr<Dispatcher> unused;
453 unused->Close(); 453 unused->Close();
454
455 base::AutoLock lock(handles_lock_);
454 handles_.GetAndRemoveDispatcher(*message_pipe_handle0, &unused); 456 handles_.GetAndRemoveDispatcher(*message_pipe_handle0, &unused);
455 return MOJO_RESULT_RESOURCE_EXHAUSTED; 457 return MOJO_RESULT_RESOURCE_EXHAUSTED;
456 } 458 }
457 459
458 return MOJO_RESULT_OK; 460 return MOJO_RESULT_OK;
459 } 461 }
460 462
461 MojoResult Core::WriteMessage(MojoHandle message_pipe_handle, 463 MojoResult Core::WriteMessage(MojoHandle message_pipe_handle,
462 const void* bytes, 464 const void* bytes,
463 uint32_t num_bytes, 465 uint32_t num_bytes,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 MojoReadMessageFlags flags) { 518 MojoReadMessageFlags flags) {
517 RequestContext request_context; 519 RequestContext request_context;
518 CHECK((!num_handles || !*num_handles || handles) && 520 CHECK((!num_handles || !*num_handles || handles) &&
519 (!num_bytes || !*num_bytes || bytes)); 521 (!num_bytes || !*num_bytes || bytes));
520 auto dispatcher = GetDispatcher(message_pipe_handle); 522 auto dispatcher = GetDispatcher(message_pipe_handle);
521 if (!dispatcher) 523 if (!dispatcher)
522 return MOJO_RESULT_INVALID_ARGUMENT; 524 return MOJO_RESULT_INVALID_ARGUMENT;
523 return dispatcher->ReadMessage(bytes, num_bytes, handles, num_handles, flags); 525 return dispatcher->ReadMessage(bytes, num_bytes, handles, num_handles, flags);
524 } 526 }
525 527
528 MojoResult Core::FuseMessagePipes(MojoHandle handle0, MojoHandle handle1) {
529 RequestContext request_context;
530 scoped_refptr<Dispatcher> dispatcher0;
531 scoped_refptr<Dispatcher> dispatcher1;
532
533 bool valid_handles = true;
534 {
535 base::AutoLock lock(handles_lock_);
536 MojoResult result0 = handles_.GetAndRemoveDispatcher(handle0, &dispatcher0);
537 MojoResult result1 = handles_.GetAndRemoveDispatcher(handle1, &dispatcher1);
538 if (result0 != MOJO_RESULT_OK || result1 != MOJO_RESULT_OK ||
539 dispatcher0->GetType() != Dispatcher::Type::MESSAGE_PIPE ||
540 dispatcher1->GetType() != Dispatcher::Type::MESSAGE_PIPE)
541 valid_handles = false;
542 }
543
544 if (!valid_handles) {
545 if (dispatcher0)
546 dispatcher0->Close();
547 if (dispatcher1)
548 dispatcher1->Close();
549 return MOJO_RESULT_INVALID_ARGUMENT;
550 }
551
552 MessagePipeDispatcher* mpd0 =
553 static_cast<MessagePipeDispatcher*>(dispatcher0.get());
554 MessagePipeDispatcher* mpd1 =
555 static_cast<MessagePipeDispatcher*>(dispatcher1.get());
556
557 if (!mpd0->Fuse(mpd1))
558 return MOJO_RESULT_FAILED_PRECONDITION;
559
560 return MOJO_RESULT_OK;
561 }
562
526 MojoResult Core::CreateDataPipe( 563 MojoResult Core::CreateDataPipe(
527 const MojoCreateDataPipeOptions* options, 564 const MojoCreateDataPipeOptions* options,
528 MojoHandle* data_pipe_producer_handle, 565 MojoHandle* data_pipe_producer_handle,
529 MojoHandle* data_pipe_consumer_handle) { 566 MojoHandle* data_pipe_consumer_handle) {
530 RequestContext request_context; 567 RequestContext request_context;
531 if (options && options->struct_size != sizeof(MojoCreateDataPipeOptions)) 568 if (options && options->struct_size != sizeof(MojoCreateDataPipeOptions))
532 return MOJO_RESULT_INVALID_ARGUMENT; 569 return MOJO_RESULT_INVALID_ARGUMENT;
533 570
534 MojoCreateDataPipeOptions create_options; 571 MojoCreateDataPipeOptions create_options;
535 create_options.struct_size = sizeof(MojoCreateDataPipeOptions); 572 create_options.struct_size = sizeof(MojoCreateDataPipeOptions);
(...skipping 25 matching lines...) Expand all
561 scoped_refptr<Dispatcher> consumer = new DataPipeConsumerDispatcher( 598 scoped_refptr<Dispatcher> consumer = new DataPipeConsumerDispatcher(
562 GetNodeController(), port1, ring_buffer, create_options, 599 GetNodeController(), port1, ring_buffer, create_options,
563 true /* initialized */, pipe_id); 600 true /* initialized */, pipe_id);
564 601
565 *data_pipe_producer_handle = AddDispatcher(producer); 602 *data_pipe_producer_handle = AddDispatcher(producer);
566 *data_pipe_consumer_handle = AddDispatcher(consumer); 603 *data_pipe_consumer_handle = AddDispatcher(consumer);
567 if (*data_pipe_producer_handle == MOJO_HANDLE_INVALID || 604 if (*data_pipe_producer_handle == MOJO_HANDLE_INVALID ||
568 *data_pipe_consumer_handle == MOJO_HANDLE_INVALID) { 605 *data_pipe_consumer_handle == MOJO_HANDLE_INVALID) {
569 if (*data_pipe_producer_handle != MOJO_HANDLE_INVALID) { 606 if (*data_pipe_producer_handle != MOJO_HANDLE_INVALID) {
570 scoped_refptr<Dispatcher> unused; 607 scoped_refptr<Dispatcher> unused;
608 base::AutoLock lock(handles_lock_);
571 handles_.GetAndRemoveDispatcher(*data_pipe_producer_handle, &unused); 609 handles_.GetAndRemoveDispatcher(*data_pipe_producer_handle, &unused);
572 } 610 }
573 producer->Close(); 611 producer->Close();
574 consumer->Close(); 612 consumer->Close();
575 return MOJO_RESULT_RESOURCE_EXHAUSTED; 613 return MOJO_RESULT_RESOURCE_EXHAUSTED;
576 } 614 }
577 615
578 return MOJO_RESULT_OK; 616 return MOJO_RESULT_OK;
579 } 617 }
580 618
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 scoped_ptr<NodeController> node_controller) { 857 scoped_ptr<NodeController> node_controller) {
820 // It's OK to leak this reference. At this point we know the IO loop is still 858 // It's OK to leak this reference. At this point we know the IO loop is still
821 // running, and we know the NodeController will observe its eventual 859 // running, and we know the NodeController will observe its eventual
822 // destruction. This tells the NodeController to delete itself when that 860 // destruction. This tells the NodeController to delete itself when that
823 // happens. 861 // happens.
824 node_controller.release()->DestroyOnIOThreadShutdown(); 862 node_controller.release()->DestroyOnIOThreadShutdown();
825 } 863 }
826 864
827 } // namespace edk 865 } // namespace edk
828 } // namespace mojo 866 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/core.h ('k') | mojo/edk/system/message_pipe_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698