| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 #include "bin/native_service.h" | |
| 6 | |
| 7 #include "platform/globals.h" | |
| 8 #include "bin/thread.h" | |
| 9 | |
| 10 | |
| 11 namespace dart { | |
| 12 namespace bin { | |
| 13 | |
| 14 NativeService::NativeService(const char* name, | |
| 15 Dart_NativeMessageHandler handler, | |
| 16 int number_of_ports) | |
| 17 : name_(name), | |
| 18 handler_(handler), | |
| 19 service_ports_size_(number_of_ports), | |
| 20 service_ports_index_(0) { | |
| 21 service_ports_ = new Dart_Port[service_ports_size_]; | |
| 22 for (int i = 0; i < service_ports_size_; i++) { | |
| 23 service_ports_[i] = ILLEGAL_PORT; | |
| 24 } | |
| 25 } | |
| 26 | |
| 27 | |
| 28 NativeService::~NativeService() { | |
| 29 delete[] service_ports_; | |
| 30 } | |
| 31 | |
| 32 | |
| 33 Dart_Port NativeService::GetServicePort() { | |
| 34 MutexLocker lock(&mutex_); | |
| 35 Dart_Port result = service_ports_[service_ports_index_]; | |
| 36 if (result == ILLEGAL_PORT) { | |
| 37 result = Dart_NewNativePort(name_, handler_, true); | |
| 38 ASSERT(result != ILLEGAL_PORT); | |
| 39 service_ports_[service_ports_index_] = result; | |
| 40 } | |
| 41 service_ports_index_ = (service_ports_index_ + 1) % service_ports_size_; | |
| 42 return result; | |
| 43 } | |
| 44 | |
| 45 } // namespace bin | |
| 46 } // namespace dart | |
| OLD | NEW |