| 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 NativeService::NativeService(const char* name, |
| 12 Dart_NativeMessageHandler handler, |
| 13 int number_of_ports) |
| 14 : name_(name), |
| 15 handler_(handler), |
| 16 service_ports_size_(number_of_ports), |
| 17 service_ports_index_(0) { |
| 18 service_ports_ = new Dart_Port[service_ports_size_]; |
| 19 for (int i = 0; i < service_ports_size_; i++) { |
| 20 service_ports_[i] = ILLEGAL_PORT; |
| 21 } |
| 22 } |
| 23 |
| 24 |
| 25 NativeService::~NativeService() { |
| 26 delete[] service_ports_; |
| 27 } |
| 28 |
| 29 |
| 30 Dart_Port NativeService::GetServicePort() { |
| 31 MutexLocker lock(&mutex_); |
| 32 Dart_Port result = service_ports_[service_ports_index_]; |
| 33 if (result == ILLEGAL_PORT) { |
| 34 result = Dart_NewNativePort(name_, handler_, true); |
| 35 ASSERT(result != ILLEGAL_PORT); |
| 36 service_ports_[service_ports_index_] = result; |
| 37 } |
| 38 service_ports_index_ = (service_ports_index_ + 1) % service_ports_size_; |
| 39 return result; |
| 40 } |
| OLD | NEW |