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

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

Issue 9332003: Use epoll for the event handler on Linux. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
« no previous file with comments | « no previous file | runtime/bin/eventhandler_linux.cc » ('j') | runtime/bin/eventhandler_linux.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef BIN_EVENTHANDLER_LINUX_H_ 5 #ifndef BIN_EVENTHANDLER_LINUX_H_
6 #define BIN_EVENTHANDLER_LINUX_H_ 6 #define BIN_EVENTHANDLER_LINUX_H_
7 7
8 #if !defined(BIN_EVENTHANDLER_H_) 8 #if !defined(BIN_EVENTHANDLER_H_)
9 #error Do not include eventhandler_linux.h directly; use eventhandler.h instead. 9 #error Do not include eventhandler_linux.h directly; use eventhandler.h instead.
10 #endif 10 #endif
(...skipping 12 matching lines...) Expand all
23 23
24 24
25 enum PortDataFlags { 25 enum PortDataFlags {
26 kClosedRead = 0, 26 kClosedRead = 0,
27 kClosedWrite = 1, 27 kClosedWrite = 1,
28 }; 28 };
29 29
30 30
31 class SocketData { 31 class SocketData {
32 public: 32 public:
33 explicit SocketData(intptr_t fd) : fd_(fd), port_(0), mask_(0), flags_(0) { 33 explicit SocketData(intptr_t fd)
34 : tracked_by_epoll_(false), fd_(fd), port_(0), mask_(0), flags_(0) {
34 ASSERT(fd_ != -1); 35 ASSERT(fd_ != -1);
35 } 36 }
36 37
37 intptr_t GetPollEvents(); 38 intptr_t GetPollEvents();
38 39
39 void Unregister() {
40 port_ = 0;
41 mask_ = 0;
42 }
43
44 void ShutdownRead() { 40 void ShutdownRead() {
45 shutdown(fd_, SHUT_RD); 41 shutdown(fd_, SHUT_RD);
46 MarkClosedRead(); 42 MarkClosedRead();
47 } 43 }
48 44
49 void ShutdownWrite() { 45 void ShutdownWrite() {
50 shutdown(fd_, SHUT_WR); 46 shutdown(fd_, SHUT_WR);
51 MarkClosedWrite(); 47 MarkClosedWrite();
52 } 48 }
53 49
54 void Close() { 50 void Close() {
55 Unregister(); 51 port_ = 0;
52 mask_ = 0;
56 flags_ = 0; 53 flags_ = 0;
57 close(fd_); 54 close(fd_);
58 fd_ = -1; 55 fd_ = -1;
59 } 56 }
60 57
61 bool IsListeningSocket() { return (mask_ & (1 << kListeningSocket)) != 0; } 58 bool IsListeningSocket() { return (mask_ & (1 << kListeningSocket)) != 0; }
62 bool IsPipe() { return (mask_ & (1 << kPipe)) != 0; } 59 bool IsPipe() { return (mask_ & (1 << kPipe)) != 0; }
63 bool IsClosedRead() { return (flags_ & (1 << kClosedRead)) != 0; } 60 bool IsClosedRead() { return (flags_ & (1 << kClosedRead)) != 0; }
64 bool IsClosedWrite() { return (flags_ & (1 << kClosedWrite)) != 0; } 61 bool IsClosedWrite() { return (flags_ & (1 << kClosedWrite)) != 0; }
65 62
66 void MarkClosedRead() { flags_ |= (1 << kClosedRead); } 63 void MarkClosedRead() { flags_ |= (1 << kClosedRead); }
67 void MarkClosedWrite() { flags_ |= (1 << kClosedWrite); } 64 void MarkClosedWrite() { flags_ |= (1 << kClosedWrite); }
68 65
69 bool HasPollEvents() { return mask_ != 0; }
70
71 void SetPortAndMask(Dart_Port port, intptr_t mask) { 66 void SetPortAndMask(Dart_Port port, intptr_t mask) {
72 ASSERT(fd_ != -1); 67 ASSERT(fd_ != -1);
73 port_ = port; 68 port_ = port;
74 mask_ = mask; 69 mask_ = mask;
75 } 70 }
76 71
77 intptr_t fd() { return fd_; } 72 intptr_t fd() { return fd_; }
78 Dart_Port port() { return port_; } 73 Dart_Port port() { return port_; }
79 intptr_t mask() { return mask_; } 74 intptr_t mask() { return mask_; }
75 bool tracked_by_epoll() { return tracked_by_epoll_; }
76 void set_tracked_by_epoll(bool value) { tracked_by_epoll_ = value; }
80 77
81 private: 78 private:
79 bool tracked_by_epoll_;
82 intptr_t fd_; 80 intptr_t fd_;
83 Dart_Port port_; 81 Dart_Port port_;
84 intptr_t mask_; 82 intptr_t mask_;
85 intptr_t flags_; 83 intptr_t flags_;
86 }; 84 };
87 85
88 86
89 class EventHandlerImplementation { 87 class EventHandlerImplementation {
90 public: 88 public:
91 EventHandlerImplementation(); 89 EventHandlerImplementation();
92 ~EventHandlerImplementation(); 90 ~EventHandlerImplementation();
93 91
94 // Gets the socket data structure for a given file 92 // Gets the socket data structure for a given file
95 // descriptor. Creates a new one of one is not found. 93 // descriptor. Creates a new one if one is not found.
96 SocketData* GetSocketData(intptr_t fd); 94 SocketData* GetSocketData(intptr_t fd);
97 void SendData(intptr_t id, Dart_Port dart_port, intptr_t data); 95 void SendData(intptr_t id, Dart_Port dart_port, intptr_t data);
98 void StartEventHandler(); 96 void StartEventHandler();
99 97
100 private: 98 private:
101 intptr_t GetTimeout(); 99 intptr_t GetTimeout();
102 bool GetInterruptMessage(InterruptMessage* msg); 100 bool GetInterruptMessage(InterruptMessage* msg);
103 struct pollfd* GetPollFds(intptr_t* size); 101 void HandleEvents(struct epoll_event* events, int size);
104 void HandleEvents(struct pollfd* pollfds, int pollfds_size, int result_size);
105 void HandleTimeout(); 102 void HandleTimeout();
106 static void Poll(uword args); 103 static void Poll(uword args);
107 void WakeupHandler(intptr_t id, Dart_Port dart_port, int64_t data); 104 void WakeupHandler(intptr_t id, Dart_Port dart_port, int64_t data);
108 void HandleInterruptFd(); 105 void HandleInterruptFd();
109 void SetPort(intptr_t fd, Dart_Port dart_port, intptr_t mask); 106 void SetPort(intptr_t fd, Dart_Port dart_port, intptr_t mask);
110 intptr_t GetPollEvents(struct pollfd* pollfd); 107 intptr_t GetPollEvents(intptr_t events, SocketData* sd);
111 static void* GetHashmapKeyFromFd(intptr_t fd); 108 static void* GetHashmapKeyFromFd(intptr_t fd);
112 static uint32_t GetHashmapHashFromFd(intptr_t fd); 109 static uint32_t GetHashmapHashFromFd(intptr_t fd);
113 110
114 HashMap socket_map_; 111 HashMap socket_map_;
115 int64_t timeout_; // Time for next timeout. 112 int64_t timeout_; // Time for next timeout.
116 Dart_Port timeout_port_; 113 Dart_Port timeout_port_;
117 int interrupt_fds_[2]; 114 int interrupt_fds_[2];
115 int epoll_fd;
Søren Gjesse 2012/02/07 07:54:12 Missing trailing underscore.
Mads Ager (google) 2012/02/07 08:09:35 Done.
118 }; 116 };
119 117
120 118
121 #endif // BIN_EVENTHANDLER_LINUX_H_ 119 #endif // BIN_EVENTHANDLER_LINUX_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/eventhandler_linux.cc » ('j') | runtime/bin/eventhandler_linux.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698