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

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: 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/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->BeginFuse()) {
558 mpd0->Close();
559 mpd1->Close();
560 return MOJO_RESULT_FAILED_PRECONDITION;
561 }
562
563 if (!mpd1->BeginFuse()) {
564 mpd0->CancelFuse();
565 mpd0->Close();
566 mpd1->Close();
567 return MOJO_RESULT_FAILED_PRECONDITION;
568 }
569
570 if (!mpd0->CompleteFuse(mpd1))
571 return MOJO_RESULT_FAILED_PRECONDITION;
572
573 return MOJO_RESULT_OK;
574 }
575
526 MojoResult Core::CreateDataPipe( 576 MojoResult Core::CreateDataPipe(
527 const MojoCreateDataPipeOptions* options, 577 const MojoCreateDataPipeOptions* options,
528 MojoHandle* data_pipe_producer_handle, 578 MojoHandle* data_pipe_producer_handle,
529 MojoHandle* data_pipe_consumer_handle) { 579 MojoHandle* data_pipe_consumer_handle) {
530 RequestContext request_context; 580 RequestContext request_context;
531 if (options && options->struct_size != sizeof(MojoCreateDataPipeOptions)) 581 if (options && options->struct_size != sizeof(MojoCreateDataPipeOptions))
532 return MOJO_RESULT_INVALID_ARGUMENT; 582 return MOJO_RESULT_INVALID_ARGUMENT;
533 583
534 MojoCreateDataPipeOptions create_options; 584 MojoCreateDataPipeOptions create_options;
535 create_options.struct_size = sizeof(MojoCreateDataPipeOptions); 585 create_options.struct_size = sizeof(MojoCreateDataPipeOptions);
(...skipping 25 matching lines...) Expand all
561 scoped_refptr<Dispatcher> consumer = new DataPipeConsumerDispatcher( 611 scoped_refptr<Dispatcher> consumer = new DataPipeConsumerDispatcher(
562 GetNodeController(), port1, ring_buffer, create_options, 612 GetNodeController(), port1, ring_buffer, create_options,
563 true /* initialized */, pipe_id); 613 true /* initialized */, pipe_id);
564 614
565 *data_pipe_producer_handle = AddDispatcher(producer); 615 *data_pipe_producer_handle = AddDispatcher(producer);
566 *data_pipe_consumer_handle = AddDispatcher(consumer); 616 *data_pipe_consumer_handle = AddDispatcher(consumer);
567 if (*data_pipe_producer_handle == MOJO_HANDLE_INVALID || 617 if (*data_pipe_producer_handle == MOJO_HANDLE_INVALID ||
568 *data_pipe_consumer_handle == MOJO_HANDLE_INVALID) { 618 *data_pipe_consumer_handle == MOJO_HANDLE_INVALID) {
569 if (*data_pipe_producer_handle != MOJO_HANDLE_INVALID) { 619 if (*data_pipe_producer_handle != MOJO_HANDLE_INVALID) {
570 scoped_refptr<Dispatcher> unused; 620 scoped_refptr<Dispatcher> unused;
621 base::AutoLock lock(handles_lock_);
571 handles_.GetAndRemoveDispatcher(*data_pipe_producer_handle, &unused); 622 handles_.GetAndRemoveDispatcher(*data_pipe_producer_handle, &unused);
572 } 623 }
573 producer->Close(); 624 producer->Close();
574 consumer->Close(); 625 consumer->Close();
575 return MOJO_RESULT_RESOURCE_EXHAUSTED; 626 return MOJO_RESULT_RESOURCE_EXHAUSTED;
576 } 627 }
577 628
578 return MOJO_RESULT_OK; 629 return MOJO_RESULT_OK;
579 } 630 }
580 631
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 scoped_ptr<NodeController> node_controller) { 870 scoped_ptr<NodeController> node_controller) {
820 // It's OK to leak this reference. At this point we know the IO loop is still 871 // 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 872 // running, and we know the NodeController will observe its eventual
822 // destruction. This tells the NodeController to delete itself when that 873 // destruction. This tells the NodeController to delete itself when that
823 // happens. 874 // happens.
824 node_controller.release()->DestroyOnIOThreadShutdown(); 875 node_controller.release()->DestroyOnIOThreadShutdown();
825 } 876 }
826 877
827 } // namespace edk 878 } // namespace edk
828 } // namespace mojo 879 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698