| OLD | NEW |
| 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 <pthread.h> | 8 #include <pthread.h> |
| 9 #include <stdio.h> | 9 #include <stdio.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 | 337 |
| 338 | 338 |
| 339 void EventHandlerImplementation::EventHandlerEntry(uword args) { | 339 void EventHandlerImplementation::EventHandlerEntry(uword args) { |
| 340 static const intptr_t kMaxEvents = 16; | 340 static const intptr_t kMaxEvents = 16; |
| 341 struct kevent events[kMaxEvents]; | 341 struct kevent events[kMaxEvents]; |
| 342 EventHandlerImplementation* handler = | 342 EventHandlerImplementation* handler = |
| 343 reinterpret_cast<EventHandlerImplementation*>(args); | 343 reinterpret_cast<EventHandlerImplementation*>(args); |
| 344 ASSERT(handler != NULL); | 344 ASSERT(handler != NULL); |
| 345 while (1) { | 345 while (1) { |
| 346 intptr_t millis = handler->GetTimeout(); | 346 intptr_t millis = handler->GetTimeout(); |
| 347 // NULL pointer timespec for infinite timeout. |
| 348 ASSERT(kInfinityTimeout < 0); |
| 349 struct timespec* timeout = NULL; |
| 347 struct timespec ts; | 350 struct timespec ts; |
| 348 int64_t secs = 0; | 351 if (millis >= 0) { |
| 349 int64_t nanos = 0; | 352 ts.tv_sec = millis / 1000; |
| 350 if (millis > 0) { | 353 ts.tv_nsec = (millis - (ts.tv_sec * 1000)) * 1000000; |
| 351 secs = millis / 1000; | 354 timeout = &ts; |
| 352 nanos = (millis - (secs * 1000)) * 1000000; | |
| 353 } | 355 } |
| 354 ts.tv_sec = secs; | |
| 355 ts.tv_nsec = nanos; | |
| 356 intptr_t result = TEMP_FAILURE_RETRY(kevent(handler->kqueue_fd_, | 356 intptr_t result = TEMP_FAILURE_RETRY(kevent(handler->kqueue_fd_, |
| 357 NULL, | 357 NULL, |
| 358 0, | 358 0, |
| 359 events, | 359 events, |
| 360 kMaxEvents, | 360 kMaxEvents, |
| 361 &ts)); | 361 timeout)); |
| 362 if (result == -1) { | 362 if (result == -1) { |
| 363 perror("kevent failed"); | 363 perror("kevent failed"); |
| 364 FATAL("kevent failed\n"); | 364 FATAL("kevent failed\n"); |
| 365 } else { | 365 } else { |
| 366 handler->HandleTimeout(); | 366 handler->HandleTimeout(); |
| 367 handler->HandleEvents(events, result); | 367 handler->HandleEvents(events, result); |
| 368 } | 368 } |
| 369 } | 369 } |
| 370 } | 370 } |
| 371 | 371 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 390 void* EventHandlerImplementation::GetHashmapKeyFromFd(intptr_t fd) { | 390 void* EventHandlerImplementation::GetHashmapKeyFromFd(intptr_t fd) { |
| 391 // The hashmap does not support keys with value 0. | 391 // The hashmap does not support keys with value 0. |
| 392 return reinterpret_cast<void*>(fd + 1); | 392 return reinterpret_cast<void*>(fd + 1); |
| 393 } | 393 } |
| 394 | 394 |
| 395 | 395 |
| 396 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { | 396 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { |
| 397 // The hashmap does not support keys with value 0. | 397 // The hashmap does not support keys with value 0. |
| 398 return dart::Utils::WordHash(fd + 1); | 398 return dart::Utils::WordHash(fd + 1); |
| 399 } | 399 } |
| OLD | NEW |