Chromium Code Reviews| 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. |
|
Søren Gjesse
2014/10/22 07:23:51
Add "do nothing" to the comment to make it obvious
kustermann
2014/10/23 21:59:23
Done.
| |
| 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. | |
| 211 // But whether to close it, depends on whether other isolates have it open | |
| 212 // as well or not. | |
| 202 } | 213 } |
| 203 tokens_map_.Remove( | |
| 204 GetHashmapKeyFromPort(port), GetHashmapHashFromPort(port)); | |
| 205 return !live_ports_.HasHead(); | 214 return !live_ports_.HasHead(); |
| 206 } | 215 } |
| 207 | 216 |
| 208 bool TakeToken() { | 217 bool TakeToken() { |
| 209 ASSERT(live_ports_.HasHead()); | 218 ASSERT(live_ports_.HasHead()); |
| 210 Dart_Port port = live_ports_.head(); | 219 Dart_Port port = live_ports_.head(); |
| 211 HashMap::Entry* entry = tokens_map_.Lookup( | 220 HashMap::Entry* entry = tokens_map_.Lookup( |
| 212 GetHashmapKeyFromPort(port), GetHashmapHashFromPort(port), false); | 221 GetHashmapKeyFromPort(port), GetHashmapHashFromPort(port), false); |
| 213 ASSERT(entry != NULL); | 222 ASSERT(entry != NULL); |
| 214 intptr_t tokens = reinterpret_cast<intptr_t>(entry->value); | 223 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_; | 291 bool shutdown_; |
| 283 int interrupt_fds_[2]; | 292 int interrupt_fds_[2]; |
| 284 int epoll_fd_; | 293 int epoll_fd_; |
| 285 int timer_fd_; | 294 int timer_fd_; |
| 286 }; | 295 }; |
| 287 | 296 |
| 288 } // namespace bin | 297 } // namespace bin |
| 289 } // namespace dart | 298 } // namespace dart |
| 290 | 299 |
| 291 #endif // BIN_EVENTHANDLER_LINUX_H_ | 300 #endif // BIN_EVENTHANDLER_LINUX_H_ |
| OLD | NEW |