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

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

Issue 2100553002: Add Core methods for wait set. (Closed) Base URL: https://github.com/domokit/mojo.git@work790_wait_set_5.4
Patch Set: Created 4 years, 6 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/core_test_base.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 <limits> 7 #include <limits>
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "mojo/edk/embedder/platform_support.h" 13 #include "mojo/edk/embedder/platform_support.h"
14 #include "mojo/edk/platform/platform_shared_buffer.h" 14 #include "mojo/edk/platform/platform_shared_buffer.h"
15 #include "mojo/edk/platform/time_ticks.h" 15 #include "mojo/edk/platform/time_ticks.h"
16 #include "mojo/edk/system/async_waiter.h" 16 #include "mojo/edk/system/async_waiter.h"
17 #include "mojo/edk/system/configuration.h" 17 #include "mojo/edk/system/configuration.h"
18 #include "mojo/edk/system/data_pipe.h" 18 #include "mojo/edk/system/data_pipe.h"
19 #include "mojo/edk/system/data_pipe_consumer_dispatcher.h" 19 #include "mojo/edk/system/data_pipe_consumer_dispatcher.h"
20 #include "mojo/edk/system/data_pipe_producer_dispatcher.h" 20 #include "mojo/edk/system/data_pipe_producer_dispatcher.h"
21 #include "mojo/edk/system/dispatcher.h" 21 #include "mojo/edk/system/dispatcher.h"
22 #include "mojo/edk/system/handle_signals_state.h" 22 #include "mojo/edk/system/handle_signals_state.h"
23 #include "mojo/edk/system/handle_transport.h" 23 #include "mojo/edk/system/handle_transport.h"
24 #include "mojo/edk/system/memory.h" 24 #include "mojo/edk/system/memory.h"
25 #include "mojo/edk/system/message_pipe.h" 25 #include "mojo/edk/system/message_pipe.h"
26 #include "mojo/edk/system/message_pipe_dispatcher.h" 26 #include "mojo/edk/system/message_pipe_dispatcher.h"
27 #include "mojo/edk/system/shared_buffer_dispatcher.h" 27 #include "mojo/edk/system/shared_buffer_dispatcher.h"
28 #include "mojo/edk/system/wait_set_dispatcher.h"
28 #include "mojo/edk/system/waiter.h" 29 #include "mojo/edk/system/waiter.h"
29 #include "mojo/public/c/system/macros.h" 30 #include "mojo/public/c/system/macros.h"
30 #include "mojo/public/cpp/system/macros.h" 31 #include "mojo/public/cpp/system/macros.h"
31 32
32 using mojo::platform::GetTimeTicks; 33 using mojo::platform::GetTimeTicks;
33 using mojo::platform::PlatformSharedBufferMapping; 34 using mojo::platform::PlatformSharedBufferMapping;
34 using mojo::util::MutexLocker; 35 using mojo::util::MutexLocker;
35 using mojo::util::RefPtr; 36 using mojo::util::RefPtr;
36 37
37 namespace mojo { 38 namespace mojo {
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 744
744 buffer.Put(address); 745 buffer.Put(address);
745 return MOJO_RESULT_OK; 746 return MOJO_RESULT_OK;
746 } 747 }
747 748
748 MojoResult Core::UnmapBuffer(UserPointer<void> buffer) { 749 MojoResult Core::UnmapBuffer(UserPointer<void> buffer) {
749 MutexLocker locker(&mapping_table_mutex_); 750 MutexLocker locker(&mapping_table_mutex_);
750 return mapping_table_.RemoveMapping(buffer.GetPointerValue()); 751 return mapping_table_.RemoveMapping(buffer.GetPointerValue());
751 } 752 }
752 753
754 MojoResult Core::CreateWaitSet(
755 UserPointer<const MojoCreateWaitSetOptions> options,
756 UserPointer<MojoHandle> wait_set_handle) {
757 MojoCreateWaitSetOptions validated_options = {};
758 MojoResult result =
759 WaitSetDispatcher::ValidateCreateOptions(options, &validated_options);
760 if (result != MOJO_RESULT_OK)
761 return result;
762
763 auto dispatcher = WaitSetDispatcher::Create(validated_options);
764
765 MojoHandle handle = AddHandle(
766 Handle(dispatcher.Clone(), WaitSetDispatcher::kDefaultHandleRights));
767 if (handle == MOJO_HANDLE_INVALID) {
768 LOG(ERROR) << "Handle table full";
769 dispatcher->Close();
770 return MOJO_RESULT_RESOURCE_EXHAUSTED;
771 }
772
773 wait_set_handle.Put(handle);
774 return MOJO_RESULT_OK;
775 }
776
777 MojoResult Core::WaitSetAdd(MojoHandle wait_set_handle,
778 MojoHandle handle,
779 MojoHandleSignals signals,
780 uint64_t cookie,
781 UserPointer<const MojoWaitSetAddOptions> options) {
782 if (wait_set_handle == MOJO_HANDLE_INVALID)
783 return MOJO_RESULT_INVALID_ARGUMENT;
784 if (handle == MOJO_HANDLE_INVALID)
785 return MOJO_RESULT_INVALID_ARGUMENT;
786
787 Handle wait_set_h;
788 Handle h;
789 {
790 MutexLocker locker(&handle_table_mutex_);
791 MojoResult result = handle_table_.GetHandle(wait_set_handle, &wait_set_h);
792 if (result != MOJO_RESULT_OK)
793 return result;
794 result = handle_table_.GetHandle(handle, &h);
795 if (result != MOJO_RESULT_OK)
796 return result;
797 }
798
799 if (!wait_set_h.has_all_rights(MOJO_HANDLE_RIGHT_WRITE)) {
800 return wait_set_h.dispatcher->SupportsEntrypointClass(
801 EntrypointClass::WAIT_SET)
802 ? MOJO_RESULT_PERMISSION_DENIED
803 : MOJO_RESULT_INVALID_ARGUMENT;
804 }
805
806 return wait_set_h.dispatcher->WaitSetAdd(std::move(h.dispatcher), signals,
807 cookie, options);
808 }
809
810 MojoResult Core::WaitSetRemove(MojoHandle wait_set_handle, uint64_t cookie) {
811 RefPtr<Dispatcher> wait_set_dispatcher;
812 MojoResult result = GetDispatcherAndCheckRights(
813 wait_set_handle, MOJO_HANDLE_RIGHT_WRITE, EntrypointClass::WAIT_SET,
814 &wait_set_dispatcher);
815 if (result != MOJO_RESULT_OK)
816 return result;
817
818 return wait_set_dispatcher->WaitSetRemove(cookie);
819 }
820
821 MojoResult Core::WaitSetWait(MojoHandle wait_set_handle,
822 MojoDeadline deadline,
823 UserPointer<uint32_t> num_results,
824 UserPointer<MojoWaitSetResult> results,
825 UserPointer<uint32_t> max_results) {
826 RefPtr<Dispatcher> wait_set_dispatcher;
827 MojoResult result = GetDispatcherAndCheckRights(
828 wait_set_handle, MOJO_HANDLE_RIGHT_READ, EntrypointClass::WAIT_SET,
829 &wait_set_dispatcher);
830 if (result != MOJO_RESULT_OK)
831 return result;
832
833 return wait_set_dispatcher->WaitSetWait(deadline, num_results, results,
834 max_results);
835 }
836
753 // Note: We allow |handles| to repeat the same handle multiple times, since 837 // Note: We allow |handles| to repeat the same handle multiple times, since
754 // different flags may be specified. 838 // different flags may be specified.
755 MojoResult Core::WaitManyInternal(const MojoHandle* handles, 839 MojoResult Core::WaitManyInternal(const MojoHandle* handles,
756 const MojoHandleSignals* signals, 840 const MojoHandleSignals* signals,
757 uint32_t num_handles, 841 uint32_t num_handles,
758 MojoDeadline deadline, 842 MojoDeadline deadline,
759 uint64_t* result_index, 843 uint64_t* result_index,
760 HandleSignalsState* signals_states) { 844 HandleSignalsState* signals_states) {
761 DCHECK_GT(num_handles, 0u); 845 DCHECK_GT(num_handles, 0u);
762 DCHECK_EQ(*result_index, static_cast<uint64_t>(-1)); 846 DCHECK_EQ(*result_index, static_cast<uint64_t>(-1));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 if (signals_states) { 898 if (signals_states) {
815 for (; i < num_handles; i++) 899 for (; i < num_handles; i++)
816 signals_states[i] = dispatchers[i]->GetHandleSignalsState(); 900 signals_states[i] = dispatchers[i]->GetHandleSignalsState();
817 } 901 }
818 902
819 return result; 903 return result;
820 } 904 }
821 905
822 } // namespace system 906 } // namespace system
823 } // namespace mojo 907 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/core.h ('k') | mojo/edk/system/core_test_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698