summaryrefslogtreecommitdiff
path: root/core/libdeno/deno.h
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2019-04-08 10:12:43 -0400
committerGitHub <noreply@github.com>2019-04-08 10:12:43 -0400
commitf7fdb90fd51e340ea598c055bb3573d3cdfbdaa8 (patch)
tree40db117b3a9fd2ac70e3b5551195e21eef464138 /core/libdeno/deno.h
parentcdb72afd8d91978573f0fa897844aee853983b44 (diff)
core: snapshot improvements (#2052)
* Moves how snapshots are supplied to the Isolate. Previously they were given by Behavior::startup_data() but it was only called once at startup. It makes more sense (and simplifies Behavior) to pass it to the constructor of Isolate. * Adds new libdeno type deno_snapshot instead of overloading deno_buf. * Adds new libdeno method to delete snapshot deno_snapshot_delete(). * Renames deno_get_snapshot() to deno_snapshot_new(). * Makes StartupData hold references to snapshots. This was implicit when it previously held a deno_buf but is made explicit now. Note that include_bytes!() returns a &'static [u8] and we want to avoid copying that.
Diffstat (limited to 'core/libdeno/deno.h')
-rw-r--r--core/libdeno/deno.h28
1 files changed, 19 insertions, 9 deletions
diff --git a/core/libdeno/deno.h b/core/libdeno/deno.h
index f3902985e..8054090ed 100644
--- a/core/libdeno/deno.h
+++ b/core/libdeno/deno.h
@@ -18,6 +18,11 @@ typedef struct {
size_t zero_copy_id; // 0 = normal, 1 = must call deno_zero_copy_release.
} deno_buf;
+typedef struct {
+ uint8_t* data_ptr;
+ size_t data_len;
+} deno_snapshot;
+
typedef struct deno_s Deno;
// A callback to receive a message from a libdeno.send() javascript call.
@@ -31,22 +36,27 @@ const char* deno_v8_version();
void deno_set_v8_flags(int* argc, char** argv);
typedef struct {
- int will_snapshot; // Default 0. If calling deno_get_snapshot 1.
- deno_buf load_snapshot; // Optionally: A deno_buf from deno_get_snapshot.
- deno_buf shared; // Shared buffer to be mapped to libdeno.shared
- deno_recv_cb recv_cb; // Maps to libdeno.send() calls.
+ int will_snapshot; // Default 0. If calling deno_snapshot_new 1.
+ deno_snapshot load_snapshot; // A startup snapshot to use.
+ deno_buf shared; // Shared buffer to be mapped to libdeno.shared
+ deno_recv_cb recv_cb; // Maps to libdeno.send() calls.
} deno_config;
// Create a new deno isolate.
-// Warning: If config.will_snapshot is set, deno_get_snapshot() must be called
+// Warning: If config.will_snapshot is set, deno_snapshot_new() must be called
// or an error will result.
Deno* deno_new(deno_config config);
+void deno_delete(Deno* d);
-// Generate a snapshot. The resulting buf can be used with deno_new.
-// The caller must free the returned data by calling delete[] buf.data_ptr.
-deno_buf deno_get_snapshot(Deno* d);
+// Generate a snapshot. The resulting buf can be used in as the load_snapshot
+// member in deno_confg.
+// When calling this function, the caller must have created the isolate "d" with
+// "will_snapshot" set to 1.
+// The caller must free the returned data with deno_snapshot_delete().
+deno_snapshot deno_snapshot_new(Deno* d);
-void deno_delete(Deno* d);
+// Only for use with data returned from deno_snapshot_new.
+void deno_snapshot_delete(deno_snapshot);
void deno_lock(Deno* d);
void deno_unlock(Deno* d);