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

Side by Side Diff: runtime/bin/eventhandler_macos.cc

Issue 9104041: Added API Dart_PostCMessage for posting a Dart_CMessage structure (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added new API Dart_PostCMessage Created 8 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "bin/eventhandler.h" 5 #include "bin/eventhandler.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <poll.h> 8 #include <poll.h>
9 #include <pthread.h> 9 #include <pthread.h>
10 #include <stdio.h> 10 #include <stdio.h>
11 #include <string.h> 11 #include <string.h>
12 #include <sys/time.h> 12 #include <sys/time.h>
13 #include <unistd.h> 13 #include <unistd.h>
14 14
15 #include "bin/dartutils.h"
15 #include "bin/fdutils.h" 16 #include "bin/fdutils.h"
16 #include "bin/hashmap.h" 17 #include "bin/hashmap.h"
17 #include "platform/utils.h" 18 #include "platform/utils.h"
18 19
19 20
20 int64_t GetCurrentTimeMilliseconds() { 21 int64_t GetCurrentTimeMilliseconds() {
21 struct timeval tv; 22 struct timeval tv;
22 if (gettimeofday(&tv, NULL) < 0) { 23 if (gettimeofday(&tv, NULL) < 0) {
23 UNREACHABLE(); 24 UNREACHABLE();
24 return 0; 25 return 0;
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 * The fd is unregistered. It gets re-registered when the request 303 * The fd is unregistered. It gets re-registered when the request
303 * was handled by dart. 304 * was handled by dart.
304 */ 305 */
305 intptr_t event_mask = GetPollEvents(&pollfds[i]); 306 intptr_t event_mask = GetPollEvents(&pollfds[i]);
306 if (event_mask != 0) { 307 if (event_mask != 0) {
307 intptr_t fd = pollfds[i].fd; 308 intptr_t fd = pollfds[i].fd;
308 SocketData* sd = GetSocketData(fd); 309 SocketData* sd = GetSocketData(fd);
309 Dart_Port port = sd->port(); 310 Dart_Port port = sd->port();
310 ASSERT(port != 0); 311 ASSERT(port != 0);
311 sd->Unregister(); 312 sd->Unregister();
312 Dart_PostIntArray(port, 1, &event_mask); 313 DartUtils::PostInteger(port, event_mask);
313 } 314 }
314 } 315 }
315 } 316 }
316 HandleInterruptFd(); 317 HandleInterruptFd();
317 } 318 }
318 319
319 320
320 intptr_t EventHandlerImplementation::GetTimeout() { 321 intptr_t EventHandlerImplementation::GetTimeout() {
321 if (timeout_ == kInfinityTimeout) { 322 if (timeout_ == kInfinityTimeout) {
322 return kInfinityTimeout; 323 return kInfinityTimeout;
323 } 324 }
324 intptr_t millis = timeout_ - GetCurrentTimeMilliseconds(); 325 intptr_t millis = timeout_ - GetCurrentTimeMilliseconds();
325 return (millis < 0) ? 0 : millis; 326 return (millis < 0) ? 0 : millis;
326 } 327 }
327 328
328 329
329 void EventHandlerImplementation::HandleTimeout() { 330 void EventHandlerImplementation::HandleTimeout() {
330 if (timeout_ != kInfinityTimeout) { 331 if (timeout_ != kInfinityTimeout) {
331 intptr_t millis = timeout_ - GetCurrentTimeMilliseconds(); 332 intptr_t millis = timeout_ - GetCurrentTimeMilliseconds();
332 if (millis <= 0) { 333 if (millis <= 0) {
333 Dart_PostIntArray(timeout_port_, 0, NULL); 334 DartUtils::PostNull(timeout_port_);
334 timeout_ = kInfinityTimeout; 335 timeout_ = kInfinityTimeout;
335 timeout_port_ = 0; 336 timeout_port_ = 0;
336 } 337 }
337 } 338 }
338 } 339 }
339 340
340 341
341 void EventHandlerImplementation::Poll(uword args) { 342 void EventHandlerImplementation::Poll(uword args) {
342 intptr_t pollfds_size; 343 intptr_t pollfds_size;
343 struct pollfd* pollfds; 344 struct pollfd* pollfds;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 void* EventHandlerImplementation::GetHashmapKeyFromFd(intptr_t fd) { 382 void* EventHandlerImplementation::GetHashmapKeyFromFd(intptr_t fd) {
382 // The hashmap does not support keys with value 0. 383 // The hashmap does not support keys with value 0.
383 return reinterpret_cast<void*>(fd + 1); 384 return reinterpret_cast<void*>(fd + 1);
384 } 385 }
385 386
386 387
387 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { 388 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) {
388 // The hashmap does not support keys with value 0. 389 // The hashmap does not support keys with value 0.
389 return dart::Utils::WordHash(fd + 1); 390 return dart::Utils::WordHash(fd + 1);
390 } 391 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698