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

Side by Side Diff: runtime/bin/loader.h

Issue 1998963003: Rework standalone to use a synchronous loader that does not invoke Dart code (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 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
OLDNEW
(Empty)
1 // Copyright (c) 2016, 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 #ifndef BIN_LOADER_H_
6 #define BIN_LOADER_H_
7
8 #include "bin/isolate_data.h"
9 #include "include/dart_api.h"
10 #include "include/dart_native_api.h"
11 #include "platform/assert.h"
12 #include "platform/globals.h"
13 #include "bin/thread.h"
14
15 namespace dart {
16 namespace bin {
17
18 class Loader {
19 public:
20 explicit Loader(IsolateData* isolate_data);
21 ~Loader();
22
23 // A static tag handler that hides all usage of a loader for an isolate.
24 static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag,
25 Dart_Handle library,
26 Dart_Handle url);
27
28 Dart_Handle error() const {
29 return error_;
30 }
31
32 private:
33 // The port assigned to our native message handler.
34 Dart_Port port_;
35 // Each Loader is associated with an Isolate via its IsolateData.
36 IsolateData* isolate_data_;
37 // Remember the first error that occurs during loading.
38 Dart_Handle error_;
39
40 // This monitor is used to protect the pending operations count and the
41 // I/O result queue.
42 Monitor* monitor_;
43
44 // The number of operations dispatched to the service isolate for loading.
45 // Must be accessed with monitor_ held.
46 intptr_t pending_operations_;
47
48 // The result of an I/O request to the service isolate. Payload is either
49 // a UInt8Array or a C string containing an error message.
50 struct IOResult {
51 uint8_t* payload;
52 intptr_t payload_length;
53 char* library_uri;
54 char* uri;
55 int8_t tag;
56
57 void Setup(Dart_CObject* message);
58 void Cleanup();
59 };
60 // An array of I/O results queued from the service isolate.
61 IOResult* results_;
62 intptr_t results_length_;
63 intptr_t results_capacity_;
64
65 // Send the loader init request to the service isolate.
66 void Init(const char* package_root,
67 const char* packages_file,
68 const char* working_directory);
69
70 // Send a request from the tag handler to the service isolate.
71 void SendRequest(Dart_LibraryTag tag,
72 Dart_Handle url,
73 Dart_Handle library_url);
74
75 /// Queue |message| and notify the loader that a message is available.
76 void QueueMessage(Dart_CObject* message);
77
78 /// Blocks the caller until the loader is finished.
79 void BlockUntilComplete();
80
81 /// Returns false if |result| is an error and the loader should quit.
82 bool ProcessResultLocked(IOResult* result);
83
84 /// Returns false if an error occurred and the loader should quit.
85 bool ProcessQueueLocked();
86
87 // Special inner tag handler for dart: uris.
88 static Dart_Handle DartColonLibraryTagHandler(Dart_LibraryTag tag,
89 Dart_Handle library,
90 Dart_Handle url,
91 const char* library_url_string,
92 const char* url_string);
93
94 // We use one native message handler callback for N loaders. The native
95 // message handler callback provides us with the Dart_Port which we use as a
96 // key into our map of active loaders from |port| to |isolate_data|.
97
98 // Static information to map Dart_Port back to the isolate in question.
99 struct LoaderInfo {
100 Dart_Port port;
101 IsolateData* isolate_data;
102 };
103
104 // The map of active loaders.
105 static Mutex loader_infos_lock_;
106 static LoaderInfo* loader_infos_;
107 static intptr_t loader_infos_length_;
108 static intptr_t loader_infos_capacity_;
109
110 static void AddLoader(Dart_Port port, IsolateData* data);
111 static void RemoveLoader(Dart_Port port);
112 static intptr_t LoaderIndexFor(Dart_Port port);
113 static Loader* LoaderFor(Dart_Port port);
114
115 // This is the global callback for the native message handlers.
116 static void NativeMessageHandler(Dart_Port dest_port_id,
117 Dart_CObject* message);
118 };
119
120 } // namespace bin
121 } // namespace dart
122
123 #endif // BIN_LOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698