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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..cd9bbd303f4eb9c7c666f792faa81620990ce10c 100644
--- a/mojo/dart/embedder/mojo_natives.cc
+++ b/mojo/dart/embedder/mojo_natives.cc
@@ -723,21 +723,34 @@ void MojoMessagePipe_Read(Dart_NativeArguments arguments) {
}
struct MojoWaitManyState {
+ MojoWaitManyState() {}
+
std::vector<uint32_t> handles;
std::vector<uint32_t> signals;
std::vector<uint32_t> out_index;
std::vector<MojoHandleSignalsState> out_signals;
+
+ static MojoWaitManyState* GetInstance();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MojoWaitManyState);
};
// 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() {
+ static MojoWaitManyState* state = new MojoWaitManyState;
+ return state;
+}
void MojoHandleWatcher_GrowStateArrays(Dart_NativeArguments arguments) {
int64_t new_length;
CHECK_INTEGER_ARGUMENT(arguments, 0, &new_length, InvalidArgument);
+ MojoWaitManyState& handle_watcher_wait_state =
+ *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);
@@ -801,6 +814,9 @@ void MojoHandleWatcher_WaitMany(Dart_NativeArguments arguments) {
CHECK_INTEGER_ARGUMENT(arguments, 0, &handles_len, InvalidArgument);
CHECK_INTEGER_ARGUMENT(arguments, 1, &deadline, InvalidArgument);
+ 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();
« 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