Chromium Code Reviews| Index: runtime/vm/port.cc |
| =================================================================== |
| --- runtime/vm/port.cc (revision 34133) |
| +++ runtime/vm/port.cc (working copy) |
| @@ -20,7 +20,7 @@ |
| intptr_t PortMap::capacity_ = 0; |
| intptr_t PortMap::used_ = 0; |
| intptr_t PortMap::deleted_ = 0; |
| -Dart_Port PortMap::next_port_ = 7111; |
| +Random* PortMap::prng_ = NULL; |
| intptr_t PortMap::FindPort(Dart_Port port) { |
| @@ -63,13 +63,11 @@ |
| Dart_Port PortMap::AllocatePort() { |
| - Dart_Port result = next_port_; |
| + Dart_Port result = prng_->NextUInt32() & kSmiMax; |
| - do { |
| - // TODO(iposva): Use an approved hashing function to have less predictable |
| - // port ids, or make them not accessible from Dart code or both. |
| - next_port_++; |
| - } while (FindPort(next_port_) >= 0); |
| + while ((result == 0) && (FindPort(result) >= 0)) { |
|
kasperl
2014/03/26 11:39:03
Shouldn't this be ||? Otherwise, you'll just get t
hausner
2014/03/28 23:13:20
What Kasper says. And you could turn this into a d
|
| + result = prng_->NextUInt32() & kSmiMax; |
| + } |
| ASSERT(result != 0); |
| return result; |
| @@ -258,6 +256,7 @@ |
| void PortMap::InitOnce() { |
| mutex_ = new Mutex(); |
| + prng_ = new Random(); |
| static const intptr_t kInitialCapacity = 8; |
| // TODO(iposva): Verify whether we want to keep exponentially growing. |