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

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 intptr_t results_length() {
66 return *static_cast<volatile intptr_t*>(&results_length_);
67 }
68
69 // Send the loader init request to the service isolate.
70 void Init(const char* package_root,
71 const char* packages_file,
72 const char* working_directory);
73
74 // Send a request from the tag handler to the service isolate.
75 void SendRequest(Dart_LibraryTag tag,
76 Dart_Handle url,
77 Dart_Handle library_url);
78
79 /// Queue |message| and notify the loader that a message is available.
80 void QueueMessage(Dart_CObject* message);
81
82 /// Blocks the caller until the loader is finished.
83 void BlockUntilComplete();
84
85 /// Returns false if |result| is an error and the loader should quit.
86 bool ProcessResultLocked(IOResult* result);
87
88 /// Returns false if an error occurred and the loader should quit.
89 bool ProcessQueueLocked();
90
91 // Special inner tag handler for dart: uris.
92 static Dart_Handle DartColonLibraryTagHandler(Dart_LibraryTag tag,
93 Dart_Handle library,
94 Dart_Handle url,
95 const char* library_url_string,
96 const char* url_string);
97
98 // We use one native message handler callback for N loaders. The native
99 // message handler callback provides us with the Dart_Port which we use as a
100 // key into our map of active loaders from |port| to |isolate_data|.
101
102 // Static information to map Dart_Port back to the isolate in question.
103 struct LoaderInfo {
104 Dart_Port port;
105 IsolateData* isolate_data;
106 };
107
108 // The map of active loaders.
109 static Mutex loader_infos_lock_;
110 static LoaderInfo* loader_infos_;
111 static intptr_t loader_infos_length_;
112 static intptr_t loader_infos_capacity_;
113
114 static void AddLoader(Dart_Port port, IsolateData* data);
115 static void RemoveLoader(Dart_Port port);
116 static intptr_t LoaderIndexFor(Dart_Port port);
117 static Loader* LoaderFor(Dart_Port port);
118
119 // This is the global callback for the native message handlers.
120 static void NativeMessageHandler(Dart_Port dest_port_id,
121 Dart_CObject* message);
122 };
123
124 } // namespace bin
125 } // namespace dart
126
127 #endif // BIN_LOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698