Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: runtime/bin/native_service.cc

Issue 24395013: Merge services into a shared IOService in dart:io, and use a native port. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Finish off native_service Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/native_service.h ('k') | runtime/bin/secure_socket.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « runtime/bin/native_service.h ('k') | runtime/bin/secure_socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698