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

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

Issue 1800863002: Cleanup in //runtime/bin (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Windows fixes Created 4 years, 9 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
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 "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_LINUX) 6 #if defined(TARGET_OS_LINUX)
7 7
8 #include "bin/eventhandler.h" 8 #include "bin/eventhandler.h"
9 #include "bin/eventhandler_linux.h" 9 #include "bin/eventhandler_linux.h"
10 10
11 #include <errno.h> // NOLINT 11 #include <errno.h> // NOLINT
12 #include <fcntl.h> // NOLINT
12 #include <pthread.h> // NOLINT 13 #include <pthread.h> // NOLINT
13 #include <stdio.h> // NOLINT 14 #include <stdio.h> // NOLINT
14 #include <string.h> // NOLINT 15 #include <string.h> // NOLINT
15 #include <sys/epoll.h> // NOLINT 16 #include <sys/epoll.h> // NOLINT
16 #include <sys/stat.h> // NOLINT 17 #include <sys/stat.h> // NOLINT
17 #include <sys/timerfd.h> // NOLINT 18 #include <sys/timerfd.h> // NOLINT
18 #include <unistd.h> // NOLINT 19 #include <unistd.h> // NOLINT
19 #include <fcntl.h> // NOLINT
20 20
21 #include "bin/dartutils.h" 21 #include "bin/dartutils.h"
22 #include "bin/fdutils.h" 22 #include "bin/fdutils.h"
23 #include "bin/log.h" 23 #include "bin/log.h"
24 #include "bin/lockers.h" 24 #include "bin/lockers.h"
25 #include "bin/socket.h" 25 #include "bin/socket.h"
26 #include "bin/thread.h" 26 #include "bin/thread.h"
27 #include "platform/utils.h" 27 #include "platform/utils.h"
28 28
29
30 namespace dart { 29 namespace dart {
31 namespace bin { 30 namespace bin {
32 31
33
34 intptr_t DescriptorInfo::GetPollEvents() { 32 intptr_t DescriptorInfo::GetPollEvents() {
35 // Do not ask for EPOLLERR and EPOLLHUP explicitly as they are 33 // Do not ask for EPOLLERR and EPOLLHUP explicitly as they are
36 // triggered anyway. 34 // triggered anyway.
37 intptr_t events = 0; 35 intptr_t events = 0;
38 if ((Mask() & (1 << kInEvent)) != 0) { 36 if ((Mask() & (1 << kInEvent)) != 0) {
39 events |= EPOLLIN; 37 events |= EPOLLIN;
40 } 38 }
41 if ((Mask() & (1 << kOutEvent)) != 0) { 39 if ((Mask() & (1 << kOutEvent)) != 0) {
42 events |= EPOLLOUT; 40 events |= EPOLLOUT;
43 } 41 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 VOID_TEMP_FAILURE_RETRY(close(epoll_fd_)); 129 VOID_TEMP_FAILURE_RETRY(close(epoll_fd_));
132 VOID_TEMP_FAILURE_RETRY(close(timer_fd_)); 130 VOID_TEMP_FAILURE_RETRY(close(timer_fd_));
133 VOID_TEMP_FAILURE_RETRY(close(interrupt_fds_[0])); 131 VOID_TEMP_FAILURE_RETRY(close(interrupt_fds_[0]));
134 VOID_TEMP_FAILURE_RETRY(close(interrupt_fds_[1])); 132 VOID_TEMP_FAILURE_RETRY(close(interrupt_fds_[1]));
135 } 133 }
136 134
137 135
138 void EventHandlerImplementation::UpdateEpollInstance(intptr_t old_mask, 136 void EventHandlerImplementation::UpdateEpollInstance(intptr_t old_mask,
139 DescriptorInfo *di) { 137 DescriptorInfo *di) {
140 intptr_t new_mask = di->Mask(); 138 intptr_t new_mask = di->Mask();
141 if (old_mask != 0 && new_mask == 0) { 139 if ((old_mask != 0) && (new_mask == 0)) {
142 RemoveFromEpollInstance(epoll_fd_, di); 140 RemoveFromEpollInstance(epoll_fd_, di);
143 } else if (old_mask == 0 && new_mask != 0) { 141 } else if ((old_mask == 0) && (new_mask != 0)) {
144 AddToEpollInstance(epoll_fd_, di); 142 AddToEpollInstance(epoll_fd_, di);
145 } else if (old_mask != 0 && new_mask != 0 && old_mask != new_mask) { 143 } else if ((old_mask != 0) && (new_mask != 0) && (old_mask != new_mask)) {
146 ASSERT(!di->IsListeningSocket()); 144 ASSERT(!di->IsListeningSocket());
147 RemoveFromEpollInstance(epoll_fd_, di); 145 RemoveFromEpollInstance(epoll_fd_, di);
148 AddToEpollInstance(epoll_fd_, di); 146 AddToEpollInstance(epoll_fd_, di);
149 } 147 }
150 } 148 }
151 149
152 150
153 DescriptorInfo* EventHandlerImplementation::GetDescriptorInfo( 151 DescriptorInfo* EventHandlerImplementation::GetDescriptorInfo(
154 intptr_t fd, bool is_listening) { 152 intptr_t fd, bool is_listening) {
155 ASSERT(fd >= 0); 153 ASSERT(fd >= 0);
156 HashMap::Entry* entry = socket_map_.Lookup( 154 HashMap::Entry* entry = socket_map_.Lookup(
157 GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd), true); 155 GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd), true);
158 ASSERT(entry != NULL); 156 ASSERT(entry != NULL);
159 DescriptorInfo* di = 157 DescriptorInfo* di = reinterpret_cast<DescriptorInfo*>(entry->value);
160 reinterpret_cast<DescriptorInfo*>(entry->value);
161 if (di == NULL) { 158 if (di == NULL) {
162 // If there is no data in the hash map for this file descriptor a 159 // If there is no data in the hash map for this file descriptor a
163 // new DescriptorInfo for the file descriptor is inserted. 160 // new DescriptorInfo for the file descriptor is inserted.
164 if (is_listening) { 161 if (is_listening) {
165 di = new DescriptorInfoMultiple(fd); 162 di = new DescriptorInfoMultiple(fd);
166 } else { 163 } else {
167 di = new DescriptorInfoSingle(fd); 164 di = new DescriptorInfoSingle(fd);
168 } 165 }
169 entry->value = di; 166 entry->value = di;
170 } 167 }
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 intptr_t old_mask = di->Mask(); 272 intptr_t old_mask = di->Mask();
276 di->SetPortAndMask(msg[i].dart_port, msg[i].data & EVENT_MASK); 273 di->SetPortAndMask(msg[i].dart_port, msg[i].data & EVENT_MASK);
277 UpdateEpollInstance(old_mask, di); 274 UpdateEpollInstance(old_mask, di);
278 } else { 275 } else {
279 UNREACHABLE(); 276 UNREACHABLE();
280 } 277 }
281 } 278 }
282 } 279 }
283 } 280 }
284 281
282
285 #ifdef DEBUG_POLL 283 #ifdef DEBUG_POLL
286 static void PrintEventMask(intptr_t fd, intptr_t events) { 284 static void PrintEventMask(intptr_t fd, intptr_t events) {
287 Log::Print("%d ", fd); 285 Log::Print("%d ", fd);
288 if ((events & EPOLLIN) != 0) Log::Print("EPOLLIN "); 286 if ((events & EPOLLIN) != 0) {
289 if ((events & EPOLLPRI) != 0) Log::Print("EPOLLPRI "); 287 Log::Print("EPOLLIN ");
290 if ((events & EPOLLOUT) != 0) Log::Print("EPOLLOUT "); 288 }
291 if ((events & EPOLLERR) != 0) Log::Print("EPOLLERR "); 289 if ((events & EPOLLPRI) != 0) {
292 if ((events & EPOLLHUP) != 0) Log::Print("EPOLLHUP "); 290 Log::Print("EPOLLPRI ");
293 if ((events & EPOLLRDHUP) != 0) Log::Print("EPOLLRDHUP "); 291 }
292 if ((events & EPOLLOUT) != 0) {
293 Log::Print("EPOLLOUT ");
294 }
295 if ((events & EPOLLERR) != 0) {
296 Log::Print("EPOLLERR ");
297 }
298 if ((events & EPOLLHUP) != 0) {
299 Log::Print("EPOLLHUP ");
300 }
301 if ((events & EPOLLRDHUP) != 0) {
302 Log::Print("EPOLLRDHUP ");
303 }
294 int all_events = EPOLLIN | EPOLLPRI | EPOLLOUT | 304 int all_events = EPOLLIN | EPOLLPRI | EPOLLOUT |
295 EPOLLERR | EPOLLHUP | EPOLLRDHUP; 305 EPOLLERR | EPOLLHUP | EPOLLRDHUP;
296 if ((events & ~all_events) != 0) { 306 if ((events & ~all_events) != 0) {
297 Log::Print("(and %08x) ", events & ~all_events); 307 Log::Print("(and %08x) ", events & ~all_events);
298 } 308 }
299 Log::Print("(available %d) ", FDUtils::AvailableBytes(fd)); 309 Log::Print("(available %d) ", FDUtils::AvailableBytes(fd));
300 310
301 Log::Print("\n"); 311 Log::Print("\n");
302 } 312 }
303 #endif 313 #endif
304 314
315
305 intptr_t EventHandlerImplementation::GetPollEvents(intptr_t events, 316 intptr_t EventHandlerImplementation::GetPollEvents(intptr_t events,
306 DescriptorInfo* di) { 317 DescriptorInfo* di) {
307 #ifdef DEBUG_POLL 318 #ifdef DEBUG_POLL
308 PrintEventMask(di->fd(), events); 319 PrintEventMask(di->fd(), events);
309 #endif 320 #endif
310 if (events & EPOLLERR) { 321 if (events & EPOLLERR) {
311 // Return error only if EPOLLIN is present. 322 // Return error only if EPOLLIN is present.
312 return (events & EPOLLIN) ? (1 << kErrorEvent) : 0; 323 return (events & EPOLLIN) ? (1 << kErrorEvent) : 0;
313 } 324 }
314 intptr_t event_mask = 0; 325 intptr_t event_mask = 0;
315 if (events & EPOLLIN) event_mask |= (1 << kInEvent); 326 if (events & EPOLLIN) {
316 if (events & EPOLLOUT) event_mask |= (1 << kOutEvent); 327 event_mask |= (1 << kInEvent);
317 if (events & (EPOLLHUP | EPOLLRDHUP)) event_mask |= (1 << kCloseEvent); 328 }
329 if (events & EPOLLOUT) {
330 event_mask |= (1 << kOutEvent);
331 }
332 if (events & (EPOLLHUP | EPOLLRDHUP)) {
333 event_mask |= (1 << kCloseEvent);
334 }
318 return event_mask; 335 return event_mask;
319 } 336 }
320 337
321 338
322 void EventHandlerImplementation::HandleEvents(struct epoll_event* events, 339 void EventHandlerImplementation::HandleEvents(struct epoll_event* events,
323 int size) { 340 int size) {
324 bool interrupt_seen = false; 341 bool interrupt_seen = false;
325 for (int i = 0; i < size; i++) { 342 for (int i = 0; i < size; i++) {
326 if (events[i].data.ptr == NULL) { 343 if (events[i].data.ptr == NULL) {
327 interrupt_seen = true; 344 interrupt_seen = true;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 430
414 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { 431 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) {
415 // The hashmap does not support keys with value 0. 432 // The hashmap does not support keys with value 0.
416 return dart::Utils::WordHash(fd + 1); 433 return dart::Utils::WordHash(fd + 1);
417 } 434 }
418 435
419 } // namespace bin 436 } // namespace bin
420 } // namespace dart 437 } // namespace dart
421 438
422 #endif // defined(TARGET_OS_LINUX) 439 #endif // defined(TARGET_OS_LINUX)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698