OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 @patch | 5 @patch class _IOService { |
6 class _IOService { | |
7 // Lazy initialize service ports, 32 per isolate. | 6 // Lazy initialize service ports, 32 per isolate. |
8 static const int _SERVICE_PORT_COUNT = 32; | 7 static const int _SERVICE_PORT_COUNT = 32; |
9 static List<SendPort> _servicePort = new List(_SERVICE_PORT_COUNT); | 8 static List<SendPort> _servicePort = new List(_SERVICE_PORT_COUNT); |
10 static RawReceivePort _receivePort; | 9 static RawReceivePort _receivePort; |
11 static SendPort _replyToPort; | 10 static SendPort _replyToPort; |
12 static Map<int, Completer> _messageMap = {}; | 11 static Map<int, Completer> _messageMap = {}; |
13 static int _id = 0; | 12 static int _id = 0; |
14 | 13 |
15 @patch | 14 @patch static Future _dispatch(int request, List data) { |
16 static Future _dispatch(int request, List data) { | |
17 int id; | 15 int id; |
18 do { | 16 do { |
19 id = _getNextId(); | 17 id = _getNextId(); |
20 } while (_messageMap.containsKey(id)); | 18 } while (_messageMap.containsKey(id)); |
21 int index = id % _SERVICE_PORT_COUNT; | 19 int index = id % _SERVICE_PORT_COUNT; |
22 _initialize(index); | 20 _initialize(index); |
23 var completer = new Completer(); | 21 var completer = new Completer(); |
24 _messageMap[id] = completer; | 22 _messageMap[id] = completer; |
25 try { | 23 try { |
26 _servicePort[index].send([id, _replyToPort, request, data]); | 24 _servicePort[index].send([id, _replyToPort, request, data]); |
(...skipping 29 matching lines...) Expand all Loading... |
56 _receivePort = null; | 54 _receivePort = null; |
57 } | 55 } |
58 | 56 |
59 static int _getNextId() { | 57 static int _getNextId() { |
60 if (_id == 0x7FFFFFFF) _id = 0; | 58 if (_id == 0x7FFFFFFF) _id = 0; |
61 return _id++; | 59 return _id++; |
62 } | 60 } |
63 | 61 |
64 static SendPort _newServicePort() native "IOService_NewServicePort"; | 62 static SendPort _newServicePort() native "IOService_NewServicePort"; |
65 } | 63 } |
OLD | NEW |