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

Side by Side Diff: mojo/dart/embedder/mojo_natives.cc

Issue 1395043003: Use a singleton instead of a global for MojoWaitManyState (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 2 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <stdio.h> 5 #include <stdio.h>
6 #include <string.h> 6 #include <string.h>
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 } 716 }
717 717
718 Dart_Handle list = Dart_NewList(3); 718 Dart_Handle list = Dart_NewList(3);
719 Dart_ListSetAt(list, 0, Dart_NewInteger(res)); 719 Dart_ListSetAt(list, 0, Dart_NewInteger(res));
720 Dart_ListSetAt(list, 1, Dart_NewInteger(blen)); 720 Dart_ListSetAt(list, 1, Dart_NewInteger(blen));
721 Dart_ListSetAt(list, 2, Dart_NewInteger(hlen)); 721 Dart_ListSetAt(list, 2, Dart_NewInteger(hlen));
722 Dart_SetReturnValue(arguments, list); 722 Dart_SetReturnValue(arguments, list);
723 } 723 }
724 724
725 struct MojoWaitManyState { 725 struct MojoWaitManyState {
726 MojoWaitManyState() {}
727
726 std::vector<uint32_t> handles; 728 std::vector<uint32_t> handles;
727 std::vector<uint32_t> signals; 729 std::vector<uint32_t> signals;
728 std::vector<uint32_t> out_index; 730 std::vector<uint32_t> out_index;
729 std::vector<MojoHandleSignalsState> out_signals; 731 std::vector<MojoHandleSignalsState> out_signals;
732
733 static MojoWaitManyState* GetInstance();
734
735 private:
736 DISALLOW_COPY_AND_ASSIGN(MojoWaitManyState);
730 }; 737 };
731 738
732 // This global is safe because it is only accessed by the single handle watcher 739 // This global is safe because it is only accessed by the single handle watcher
733 // isolate. If multiple handle watcher isolates are ever needed, it will need 740 // isolate. If multiple handle watcher isolates are ever needed, it will need
734 // to be replicated. 741 // to be replicated.
735 static MojoWaitManyState handle_watcher_wait_state; 742 MojoWaitManyState* MojoWaitManyState::GetInstance() {
743 static MojoWaitManyState* state = new MojoWaitManyState;
744 return state;
745 }
736 746
737 void MojoHandleWatcher_GrowStateArrays(Dart_NativeArguments arguments) { 747 void MojoHandleWatcher_GrowStateArrays(Dart_NativeArguments arguments) {
738 int64_t new_length; 748 int64_t new_length;
739 CHECK_INTEGER_ARGUMENT(arguments, 0, &new_length, InvalidArgument); 749 CHECK_INTEGER_ARGUMENT(arguments, 0, &new_length, InvalidArgument);
740 750
751 MojoWaitManyState& handle_watcher_wait_state =
752 *MojoWaitManyState::GetInstance();
753
741 handle_watcher_wait_state.handles.resize(new_length); 754 handle_watcher_wait_state.handles.resize(new_length);
742 handle_watcher_wait_state.signals.resize(new_length); 755 handle_watcher_wait_state.signals.resize(new_length);
743 handle_watcher_wait_state.out_index.resize(1); 756 handle_watcher_wait_state.out_index.resize(1);
744 handle_watcher_wait_state.out_signals.resize(new_length); 757 handle_watcher_wait_state.out_signals.resize(new_length);
745 758
746 Dart_Handle dart_handles = Dart_NewExternalTypedData( 759 Dart_Handle dart_handles = Dart_NewExternalTypedData(
747 Dart_TypedData_kUint32, handle_watcher_wait_state.handles.data(), 760 Dart_TypedData_kUint32, handle_watcher_wait_state.handles.data(),
748 handle_watcher_wait_state.handles.size()); 761 handle_watcher_wait_state.handles.size());
749 if (Dart_IsError(dart_handles)) { 762 if (Dart_IsError(dart_handles)) {
750 Dart_PropagateError(dart_handles); 763 Dart_PropagateError(dart_handles);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 Dart_ListSetAt(list, 3, dart_out_signals); 807 Dart_ListSetAt(list, 3, dart_out_signals);
795 Dart_SetReturnValue(arguments, list); 808 Dart_SetReturnValue(arguments, list);
796 } 809 }
797 810
798 void MojoHandleWatcher_WaitMany(Dart_NativeArguments arguments) { 811 void MojoHandleWatcher_WaitMany(Dart_NativeArguments arguments) {
799 int64_t handles_len = 0; 812 int64_t handles_len = 0;
800 int64_t deadline = 0; 813 int64_t deadline = 0;
801 CHECK_INTEGER_ARGUMENT(arguments, 0, &handles_len, InvalidArgument); 814 CHECK_INTEGER_ARGUMENT(arguments, 0, &handles_len, InvalidArgument);
802 CHECK_INTEGER_ARGUMENT(arguments, 1, &deadline, InvalidArgument); 815 CHECK_INTEGER_ARGUMENT(arguments, 1, &deadline, InvalidArgument);
803 816
817 MojoWaitManyState& handle_watcher_wait_state =
818 *MojoWaitManyState::GetInstance();
819
804 uint32_t* handles = handle_watcher_wait_state.handles.data(); 820 uint32_t* handles = handle_watcher_wait_state.handles.data();
805 uint32_t* signals = handle_watcher_wait_state.signals.data(); 821 uint32_t* signals = handle_watcher_wait_state.signals.data();
806 uint32_t* out_index = handle_watcher_wait_state.out_index.data(); 822 uint32_t* out_index = handle_watcher_wait_state.out_index.data();
807 MojoHandleSignalsState* out_signals = 823 MojoHandleSignalsState* out_signals =
808 handle_watcher_wait_state.out_signals.data(); 824 handle_watcher_wait_state.out_signals.data();
809 825
810 Dart_IsolateBlocked(); 826 Dart_IsolateBlocked();
811 MojoResult mojo_result = MojoWaitMany(handles, signals, handles_len, deadline, 827 MojoResult mojo_result = MojoWaitMany(handles, signals, handles_len, deadline,
812 out_index, out_signals); 828 out_index, out_signals);
813 Dart_IsolateUnblocked(); 829 Dart_IsolateUnblocked();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 mojo_control_handle = control_handle; 897 mojo_control_handle = control_handle;
882 Dart_SetIntegerReturnValue(arguments, static_cast<int64_t>(MOJO_RESULT_OK)); 898 Dart_SetIntegerReturnValue(arguments, static_cast<int64_t>(MOJO_RESULT_OK));
883 } 899 }
884 900
885 void MojoHandleWatcher_GetControlHandle(Dart_NativeArguments arguments) { 901 void MojoHandleWatcher_GetControlHandle(Dart_NativeArguments arguments) {
886 Dart_SetIntegerReturnValue(arguments, mojo_control_handle); 902 Dart_SetIntegerReturnValue(arguments, mojo_control_handle);
887 } 903 }
888 904
889 } // namespace dart 905 } // namespace dart
890 } // namespace mojo 906 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698