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 #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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 bool AddPort(Dart_Port port) { | 180 bool AddPort(Dart_Port port) { |
181 HashMap::Entry* entry = tokens_map_.Lookup( | 181 HashMap::Entry* entry = tokens_map_.Lookup( |
182 GetHashmapKeyFromPort(port), GetHashmapHashFromPort(port), true); | 182 GetHashmapKeyFromPort(port), GetHashmapHashFromPort(port), true); |
183 entry->value = reinterpret_cast<void*>(kTokenCount); | 183 entry->value = reinterpret_cast<void*>(kTokenCount); |
184 return live_ports_.Add(port); | 184 return live_ports_.Add(port); |
185 } | 185 } |
186 | 186 |
187 virtual bool RemovePort(Dart_Port port) { | 187 virtual bool RemovePort(Dart_Port port) { |
188 HashMap::Entry* entry = tokens_map_.Lookup( | 188 HashMap::Entry* entry = tokens_map_.Lookup( |
189 GetHashmapKeyFromPort(port), GetHashmapHashFromPort(port), false); | 189 GetHashmapKeyFromPort(port), GetHashmapHashFromPort(port), false); |
190 ASSERT(entry != NULL); | 190 if (entry != NULL) { |
191 intptr_t tokens = reinterpret_cast<intptr_t>(entry->value); | 191 intptr_t tokens = reinterpret_cast<intptr_t>(entry->value); |
192 if (tokens == 0) { | 192 if (tokens == 0) { |
193 while (idle_ports_.head() != port) { | 193 while (idle_ports_.head() != port) { |
194 idle_ports_.Rotate(); | 194 idle_ports_.Rotate(); |
| 195 } |
| 196 idle_ports_.RemoveHead(); |
| 197 } else { |
| 198 while (live_ports_.head() != port) { |
| 199 live_ports_.Rotate(); |
| 200 } |
| 201 live_ports_.RemoveHead(); |
195 } | 202 } |
196 idle_ports_.RemoveHead(); | 203 tokens_map_.Remove( |
| 204 GetHashmapKeyFromPort(port), GetHashmapHashFromPort(port)); |
197 } else { | 205 } else { |
198 while (live_ports_.head() != port) { | 206 // NOTE: This is a listening socket which has been immediately closed. |
199 live_ports_.Rotate(); | 207 // |
200 } | 208 // If a listening socket is not listened on, the event handler does not |
201 live_ports_.RemoveHead(); | 209 // know about it beforehand. So the first time the event handler knows |
| 210 // about it, is when it is supposed to be closed. We therefore do nothing |
| 211 // here. |
| 212 // |
| 213 // But whether to close it, depends on whether other isolates have it open |
| 214 // as well or not. |
202 } | 215 } |
203 tokens_map_.Remove( | |
204 GetHashmapKeyFromPort(port), GetHashmapHashFromPort(port)); | |
205 return !live_ports_.HasHead(); | 216 return !live_ports_.HasHead(); |
206 } | 217 } |
207 | 218 |
208 bool TakeToken() { | 219 bool TakeToken() { |
209 ASSERT(live_ports_.HasHead()); | 220 ASSERT(live_ports_.HasHead()); |
210 Dart_Port port = live_ports_.head(); | 221 Dart_Port port = live_ports_.head(); |
211 HashMap::Entry* entry = tokens_map_.Lookup( | 222 HashMap::Entry* entry = tokens_map_.Lookup( |
212 GetHashmapKeyFromPort(port), GetHashmapHashFromPort(port), false); | 223 GetHashmapKeyFromPort(port), GetHashmapHashFromPort(port), false); |
213 ASSERT(entry != NULL); | 224 ASSERT(entry != NULL); |
214 intptr_t tokens = reinterpret_cast<intptr_t>(entry->value); | 225 intptr_t tokens = reinterpret_cast<intptr_t>(entry->value); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 bool shutdown_; | 293 bool shutdown_; |
283 int interrupt_fds_[2]; | 294 int interrupt_fds_[2]; |
284 int epoll_fd_; | 295 int epoll_fd_; |
285 int timer_fd_; | 296 int timer_fd_; |
286 }; | 297 }; |
287 | 298 |
288 } // namespace bin | 299 } // namespace bin |
289 } // namespace dart | 300 } // namespace dart |
290 | 301 |
291 #endif // BIN_EVENTHANDLER_LINUX_H_ | 302 #endif // BIN_EVENTHANDLER_LINUX_H_ |
OLD | NEW |