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

Side by Side Diff: mojo/public/dart/src/handle.dart

Issue 1027603002: Dart: Removes all but native calls and the handle watcher from the snapshot. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Hoist application interface dependence Created 5 years, 9 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
« no previous file with comments | « mojo/public/dart/src/event_stream.dart ('k') | mojo/public/dart/src/handle_watcher.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 part of core; 5 part of core;
6 6
7 class _MojoHandleNatives {
8 static int register(MojoEventStream eventStream) native "MojoHandle_Register";
9 static int close(int handle) native "MojoHandle_Close";
10 static List wait(
11 int handle, int signals, int deadline) native "MojoHandle_Wait";
12 static List waitMany(List<int> handles, List<int> signals,
13 int deadline) native "MojoHandle_WaitMany";
14 }
15
16 class _HandleCreationRecord { 7 class _HandleCreationRecord {
17 final MojoHandle handle; 8 final MojoHandle handle;
18 final StackTrace stack; 9 final StackTrace stack;
19 _HandleCreationRecord(this.handle, this.stack); 10 _HandleCreationRecord(this.handle, this.stack);
20 } 11 }
21 12
22 class MojoHandle { 13 class MojoHandle {
23 static const int INVALID = 0; 14 static const int INVALID = 0;
24 static const int DEADLINE_INDEFINITE = -1; 15 static const int DEADLINE_INDEFINITE = -1;
25 16
26 int _h; 17 int _h;
27 int get h => _h; 18 int get h => _h;
28 19
29 MojoHandle(this._h) { 20 MojoHandle(this._h) {
30 assert(_addUnclosedHandle(this)); 21 assert(_addUnclosedHandle(this));
31 } 22 }
32 23
33 MojoHandle._internal(this._h); 24 MojoHandle._internal(this._h);
34 25
35 MojoHandle.invalid() : this._internal(INVALID); 26 MojoHandle.invalid() : this._internal(INVALID);
36 27
37 MojoResult close() { 28 MojoResult close() {
38 assert(_removeUnclosedHandle(this)); 29 assert(_removeUnclosedHandle(this));
39 int result = _MojoHandleNatives.close(_h); 30 int result = MojoHandleNatives.close(_h);
40 _h = INVALID; 31 _h = INVALID;
41 return new MojoResult(result); 32 return new MojoResult(result);
42 } 33 }
43 34
44 MojoHandle pass() { 35 MojoHandle pass() {
45 assert(_removeUnclosedHandle(this)); 36 assert(_removeUnclosedHandle(this));
46 return this; 37 return this;
47 } 38 }
48 39
49 MojoWaitResult wait(int signals, int deadline) { 40 MojoWaitResult wait(int signals, int deadline) {
50 List result = _MojoHandleNatives.wait(h, signals, deadline); 41 List result = MojoHandleNatives.wait(h, signals, deadline);
51 return new MojoWaitResult(new MojoResult(result[0]), result[1]); 42 var state = result[1] != null
43 ? new MojoHandleSignalsState(result[1][0], result[1][1])
44 : null;
45 return new MojoWaitResult(new MojoResult(result[0]), state);
52 } 46 }
53 47
54 bool _ready(MojoHandleSignals signal) { 48 bool _ready(MojoHandleSignals signal) {
55 MojoWaitResult mwr = wait(signal.value, 0); 49 MojoWaitResult mwr = wait(signal.value, 0);
56 switch (mwr.result) { 50 switch (mwr.result) {
57 case MojoResult.OK: 51 case MojoResult.OK:
58 return true; 52 return true;
59 case MojoResult.DEADLINE_EXCEEDED: 53 case MojoResult.DEADLINE_EXCEEDED:
60 case MojoResult.CANCELLED: 54 case MojoResult.CANCELLED:
61 case MojoResult.INVALID_ARGUMENT: 55 case MojoResult.INVALID_ARGUMENT:
(...skipping 20 matching lines...) Expand all
82 var mwr = wait(MojoHandleSignals.kAll, 0); 76 var mwr = wait(MojoHandleSignals.kAll, 0);
83 return "MojoHandle(h: $h, status: $mwr)"; 77 return "MojoHandle(h: $h, status: $mwr)";
84 } 78 }
85 79
86 bool operator ==(MojoHandle other) { 80 bool operator ==(MojoHandle other) {
87 return _h == other._h; 81 return _h == other._h;
88 } 82 }
89 83
90 static MojoWaitManyResult waitMany( 84 static MojoWaitManyResult waitMany(
91 List<int> handles, List<int> signals, int deadline) { 85 List<int> handles, List<int> signals, int deadline) {
92 List result = _MojoHandleNatives.waitMany(handles, signals, deadline); 86 List result = MojoHandleNatives.waitMany(handles, signals, deadline);
93 return new MojoWaitManyResult( 87 List states = result[2] != null
94 new MojoResult(result[0]), result[1], result[2]); 88 ? result[2].map((l) => new MojoHandleSignalsState(l[0], l[1])).toList()
89 : null;
90 return new MojoWaitManyResult(new MojoResult(result[0]), result[1], states);
95 } 91 }
96 92
97 static MojoResult register(MojoEventStream eventStream) { 93 static MojoResult register(MojoEventStream eventStream) {
98 return new MojoResult(_MojoHandleNatives.register(eventStream)); 94 return new MojoResult(
95 MojoHandleNatives.register(eventStream, eventStream._handle.h));
99 } 96 }
100 97
101 static HashMap<int, _HandleCreationRecord> _unclosedHandles = new HashMap(); 98 static HashMap<int, _HandleCreationRecord> _unclosedHandles = new HashMap();
102 99
103 // _addUnclosedHandle(), _removeUnclosedHandle(), and dumpLeakedHandles() 100 // _addUnclosedHandle(), _removeUnclosedHandle(), and dumpLeakedHandles()
104 // should only be used inside of assert() statements. 101 // should only be used inside of assert() statements.
105 static bool _addUnclosedHandle(MojoHandle handle) { 102 static bool _addUnclosedHandle(MojoHandle handle) {
106 var stack; 103 var stack;
107 try { 104 try {
108 assert(false); 105 assert(false);
(...skipping 17 matching lines...) Expand all
126 var handleCreation = MojoHandle._unclosedHandles[handle]; 123 var handleCreation = MojoHandle._unclosedHandles[handle];
127 if (handleCreation != null) { 124 if (handleCreation != null) {
128 print("HANDLE LEAK: handle: $handle, created at:"); 125 print("HANDLE LEAK: handle: $handle, created at:");
129 print("${handleCreation.stack}"); 126 print("${handleCreation.stack}");
130 noleaks = false; 127 noleaks = false;
131 } 128 }
132 } 129 }
133 return noleaks; 130 return noleaks;
134 } 131 }
135 } 132 }
OLDNEW
« no previous file with comments | « mojo/public/dart/src/event_stream.dart ('k') | mojo/public/dart/src/handle_watcher.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698