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

Side by Side Diff: mojo/public/platform/dart/dart_handle_watcher.cc

Issue 1519213004: Roll Dart forward. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Fix comment Created 5 years 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/dart/packages/mojo/sdk_ext/src/natives.dart ('k') | 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <cstdio> 5 #include <cstdio>
6 #include <cstring> 6 #include <cstring>
7 #include <memory> 7 #include <memory>
8 #include <set> 8 #include <set>
9 #include <unordered_map> 9 #include <unordered_map>
10 #include <vector> 10 #include <vector>
(...skipping 21 matching lines...) Expand all
32 } 32 }
33 Dart_CObject message; 33 Dart_CObject message;
34 message.type = Dart_CObject_kNull; 34 message.type = Dart_CObject_kNull;
35 Dart_PostCObject(port, &message); 35 Dart_PostCObject(port, &message);
36 } 36 }
37 37
38 static void PostSignal(Dart_Port port, int32_t signalled) { 38 static void PostSignal(Dart_Port port, int32_t signalled) {
39 if (port == ILLEGAL_PORT) { 39 if (port == ILLEGAL_PORT) {
40 return; 40 return;
41 } 41 }
42 Dart_CObject message; 42 Dart_PostInteger(port, signalled);
43 message.type = Dart_CObject_kInt32;
44 message.value.as_int32 = signalled;
45 Dart_PostCObject(port, &message);
46 } 43 }
47 44
48 // The internal state of the handle watcher thread. 45 // The internal state of the handle watcher thread.
49 class HandleWatcherThreadState { 46 class HandleWatcherThreadState {
50 public: 47 public:
51 HandleWatcherThreadState(MojoHandle control_pipe_consumer_handle); 48 HandleWatcherThreadState(MojoHandle control_pipe_consumer_handle);
52 49
53 ~HandleWatcherThreadState(); 50 ~HandleWatcherThreadState();
54 51
55 void Run(); 52 void Run();
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 break; 296 break;
300 case HandleWatcherCommand::kCommandShutdownHandleWatcher: 297 case HandleWatcherCommand::kCommandShutdownHandleWatcher:
301 Shutdown(command.port()); 298 Shutdown(command.port());
302 break; 299 break;
303 default: 300 default:
304 MOJO_CHECK(false); 301 MOJO_CHECK(false);
305 break; 302 break;
306 } 303 }
307 } 304 }
308 305
309 // Dart's DateTime class calls gettimeofday to get the time. 306 // Dart's Timer class uses MojoCoreNatives.timerMillisecondClock(), which
310 // TODO(johnmccutchan): Expose an API in |dart_api.h| that returns the same 307 // calls MojoGetTimeTicksNow() and divides by 1000;
311 // value that DateTime uses.
312 static int64_t GetDartTimeInMillis() { 308 static int64_t GetDartTimeInMillis() {
313 struct timeval tv; 309 MojoTimeTicks ticks = MojoGetTimeTicksNow();
314 if (gettimeofday(&tv, nullptr) < 0) { 310 return static_cast<int64_t>(ticks) / 1000;
315 MOJO_CHECK(false);
316 return 0;
317 }
318 return ((static_cast<int64_t>(tv.tv_sec) * 1000000) + tv.tv_usec) / 1000;
319 } 311 }
320 312
321 void HandleWatcherThreadState::ProcessTimers() { 313 void HandleWatcherThreadState::ProcessTimers() {
322 int64_t now = GetDartTimeInMillis(); 314 int64_t now = GetDartTimeInMillis();
323 while (HasTimers() && now >= NextTimerDeadline()) { 315 while (HasTimers() && now >= NextTimerDeadline()) {
324 CompleteNextTimer(); 316 CompleteNextTimer();
325 now = GetDartTimeInMillis(); 317 now = GetDartTimeInMillis();
326 } 318 }
327 } 319 }
328 320
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 return MojoWriteMessage(control_pipe_producer_handle, 515 return MojoWriteMessage(control_pipe_producer_handle,
524 reinterpret_cast<const void*>(&command), 516 reinterpret_cast<const void*>(&command),
525 sizeof(command), 517 sizeof(command),
526 nullptr, 518 nullptr,
527 0, 519 0,
528 0); 520 0);
529 } 521 }
530 522
531 } // namespace dart 523 } // namespace dart
532 } // namespace mojo 524 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/dart/packages/mojo/sdk_ext/src/natives.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698