Index: mojo/dart/embedder/mojo_natives.cc |
diff --git a/mojo/dart/embedder/mojo_natives.cc b/mojo/dart/embedder/mojo_natives.cc |
index 02eb5956ab4c5495bbe69f9989bfae0d028cd7ab..22f270872a454612e7bd07816483c46789c87f7a 100644 |
--- a/mojo/dart/embedder/mojo_natives.cc |
+++ b/mojo/dart/embedder/mojo_natives.cc |
@@ -10,6 +10,7 @@ |
#include "base/logging.h" |
#include "base/macros.h" |
#include "base/memory/scoped_ptr.h" |
+#include "base/memory/singleton.h" |
#include "dart/runtime/include/dart_api.h" |
#include "mojo/dart/embedder/builtin.h" |
#include "mojo/dart/embedder/mojo_dart_state.h" |
@@ -727,25 +728,32 @@ struct MojoWaitManyState { |
std::vector<uint32_t> signals; |
std::vector<uint32_t> out_index; |
std::vector<MojoHandleSignalsState> out_signals; |
+ |
+ static MojoWaitManyState* GetInstance(); |
}; |
// This global is safe because it is only accessed by the single handle watcher |
// isolate. If multiple handle watcher isolates are ever needed, it will need |
// to be replicated. |
-static MojoWaitManyState handle_watcher_wait_state; |
+MojoWaitManyState* MojoWaitManyState::GetInstance() { |
+ return Singleton<MojoWaitManyState>::get(); |
jamesr
2015/10/09 23:42:32
Singleton<> here is providing thread-safe initiali
jsimmons1
2015/10/09 23:50:46
Done.
|
+} |
void MojoHandleWatcher_GrowStateArrays(Dart_NativeArguments arguments) { |
int64_t new_length; |
CHECK_INTEGER_ARGUMENT(arguments, 0, &new_length, InvalidArgument); |
- handle_watcher_wait_state.handles.resize(new_length); |
- handle_watcher_wait_state.signals.resize(new_length); |
- handle_watcher_wait_state.out_index.resize(1); |
- handle_watcher_wait_state.out_signals.resize(new_length); |
+ MojoWaitManyState* handle_watcher_wait_state = |
jamesr
2015/10/09 23:42:32
Make this a reference and you won't have to change
abarth-chromium
2015/10/09 23:45:46
If you make this a reference, please add DISALLOW_
jsimmons1
2015/10/09 23:50:46
Done.
|
+ MojoWaitManyState::GetInstance(); |
+ |
+ handle_watcher_wait_state->handles.resize(new_length); |
+ handle_watcher_wait_state->signals.resize(new_length); |
+ handle_watcher_wait_state->out_index.resize(1); |
+ handle_watcher_wait_state->out_signals.resize(new_length); |
Dart_Handle dart_handles = Dart_NewExternalTypedData( |
- Dart_TypedData_kUint32, handle_watcher_wait_state.handles.data(), |
- handle_watcher_wait_state.handles.size()); |
+ Dart_TypedData_kUint32, handle_watcher_wait_state->handles.data(), |
+ handle_watcher_wait_state->handles.size()); |
if (Dart_IsError(dart_handles)) { |
Dart_PropagateError(dart_handles); |
} |
@@ -755,8 +763,8 @@ void MojoHandleWatcher_GrowStateArrays(Dart_NativeArguments arguments) { |
} |
Dart_Handle dart_signals = Dart_NewExternalTypedData( |
- Dart_TypedData_kUint32, handle_watcher_wait_state.signals.data(), |
- handle_watcher_wait_state.signals.size()); |
+ Dart_TypedData_kUint32, handle_watcher_wait_state->signals.data(), |
+ handle_watcher_wait_state->signals.size()); |
if (Dart_IsError(dart_signals)) { |
Dart_PropagateError(dart_signals); |
} |
@@ -766,8 +774,8 @@ void MojoHandleWatcher_GrowStateArrays(Dart_NativeArguments arguments) { |
} |
Dart_Handle dart_out_index = Dart_NewExternalTypedData( |
- Dart_TypedData_kUint32, handle_watcher_wait_state.out_index.data(), |
- handle_watcher_wait_state.out_index.size()); |
+ Dart_TypedData_kUint32, handle_watcher_wait_state->out_index.data(), |
+ handle_watcher_wait_state->out_index.size()); |
if (Dart_IsError(dart_out_index)) { |
Dart_PropagateError(dart_out_index); |
} |
@@ -777,8 +785,8 @@ void MojoHandleWatcher_GrowStateArrays(Dart_NativeArguments arguments) { |
} |
Dart_Handle dart_out_signals = Dart_NewExternalTypedData( |
- Dart_TypedData_kUint64, handle_watcher_wait_state.out_signals.data(), |
- handle_watcher_wait_state.out_signals.size()); |
+ Dart_TypedData_kUint64, handle_watcher_wait_state->out_signals.data(), |
+ handle_watcher_wait_state->out_signals.size()); |
if (Dart_IsError(dart_out_signals)) { |
Dart_PropagateError(dart_out_signals); |
} |
@@ -801,11 +809,14 @@ void MojoHandleWatcher_WaitMany(Dart_NativeArguments arguments) { |
CHECK_INTEGER_ARGUMENT(arguments, 0, &handles_len, InvalidArgument); |
CHECK_INTEGER_ARGUMENT(arguments, 1, &deadline, InvalidArgument); |
- uint32_t* handles = handle_watcher_wait_state.handles.data(); |
- uint32_t* signals = handle_watcher_wait_state.signals.data(); |
- uint32_t* out_index = handle_watcher_wait_state.out_index.data(); |
+ MojoWaitManyState* handle_watcher_wait_state = |
+ MojoWaitManyState::GetInstance(); |
+ |
+ uint32_t* handles = handle_watcher_wait_state->handles.data(); |
+ uint32_t* signals = handle_watcher_wait_state->signals.data(); |
+ uint32_t* out_index = handle_watcher_wait_state->out_index.data(); |
MojoHandleSignalsState* out_signals = |
- handle_watcher_wait_state.out_signals.data(); |
+ handle_watcher_wait_state->out_signals.data(); |
Dart_IsolateBlocked(); |
MojoResult mojo_result = MojoWaitMany(handles, signals, handles_len, deadline, |