@agoric/swingset-vat 0.32.3-dev-64cd079.0 → 0.32.3-dev-bf2d699.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +12 -11
- package/src/devices/timer/device-timer.js +39 -22
- package/tools/manual-timer.js +2 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/swingset-vat",
|
|
3
|
-
"version": "0.32.3-dev-
|
|
3
|
+
"version": "0.32.3-dev-bf2d699.0+bf2d699",
|
|
4
4
|
"description": "Vat/Container Launcher",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"scripts": {
|
|
14
14
|
"build": "exit 0",
|
|
15
15
|
"test": "ava",
|
|
16
|
+
"test:c8": "c8 --all $C8_OPTIONS ava",
|
|
16
17
|
"test:xs": "SWINGSET_WORKER_TYPE=xs-worker ava",
|
|
17
18
|
"test:xs-worker": "ava test/workers -m 'xsnap vat manager'",
|
|
18
19
|
"lint-fix": "yarn lint:eslint --fix",
|
|
@@ -28,15 +29,15 @@
|
|
|
28
29
|
"ava": "^5.3.0"
|
|
29
30
|
},
|
|
30
31
|
"dependencies": {
|
|
31
|
-
"@agoric/internal": "0.3.3-dev-
|
|
32
|
-
"@agoric/kmarshal": "0.1.1-dev-
|
|
33
|
-
"@agoric/store": "0.9.3-dev-
|
|
34
|
-
"@agoric/swing-store": "0.9.2-dev-
|
|
35
|
-
"@agoric/swingset-liveslots": "0.10.3-dev-
|
|
36
|
-
"@agoric/swingset-xsnap-supervisor": "0.10.3-dev-
|
|
37
|
-
"@agoric/time": "0.3.3-dev-
|
|
38
|
-
"@agoric/vat-data": "0.5.3-dev-
|
|
39
|
-
"@agoric/xsnap-lockdown": "0.14.1-dev-
|
|
32
|
+
"@agoric/internal": "0.3.3-dev-bf2d699.0+bf2d699",
|
|
33
|
+
"@agoric/kmarshal": "0.1.1-dev-bf2d699.0+bf2d699",
|
|
34
|
+
"@agoric/store": "0.9.3-dev-bf2d699.0+bf2d699",
|
|
35
|
+
"@agoric/swing-store": "0.9.2-dev-bf2d699.0+bf2d699",
|
|
36
|
+
"@agoric/swingset-liveslots": "0.10.3-dev-bf2d699.0+bf2d699",
|
|
37
|
+
"@agoric/swingset-xsnap-supervisor": "0.10.3-dev-bf2d699.0+bf2d699",
|
|
38
|
+
"@agoric/time": "0.3.3-dev-bf2d699.0+bf2d699",
|
|
39
|
+
"@agoric/vat-data": "0.5.3-dev-bf2d699.0+bf2d699",
|
|
40
|
+
"@agoric/xsnap-lockdown": "0.14.1-dev-bf2d699.0+bf2d699",
|
|
40
41
|
"@endo/base64": "^1.0.9",
|
|
41
42
|
"@endo/bundle-source": "^4.0.0",
|
|
42
43
|
"@endo/captp": "^4.4.5",
|
|
@@ -103,5 +104,5 @@
|
|
|
103
104
|
"typeCoverage": {
|
|
104
105
|
"atLeast": 76.47
|
|
105
106
|
},
|
|
106
|
-
"gitHead": "
|
|
107
|
+
"gitHead": "bf2d699d33a52491b887a245fa1a33e54d8b4ebb"
|
|
107
108
|
}
|
|
@@ -86,6 +86,7 @@ function makeTimerMap(state = undefined) {
|
|
|
86
86
|
return copyState(schedule);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
/** @param {bigint} time */
|
|
89
90
|
function eventsFor(time) {
|
|
90
91
|
assert.typeof(time, 'bigint');
|
|
91
92
|
for (let i = 0; i < schedule.length && schedule[i].time <= time; i += 1) {
|
|
@@ -101,17 +102,29 @@ function makeTimerMap(state = undefined) {
|
|
|
101
102
|
// There's some question as to whether it's important to invoke the handlers
|
|
102
103
|
// in the order of their deadlines. If so, we should probably ensure that the
|
|
103
104
|
// recorded deadlines don't have finer granularity than the turns.
|
|
104
|
-
|
|
105
|
+
/**
|
|
106
|
+
*
|
|
107
|
+
* @param {bigint} time
|
|
108
|
+
* @param {Waker} handler
|
|
109
|
+
* @param {number} [index]
|
|
110
|
+
* @returns {bigint}
|
|
111
|
+
*/
|
|
112
|
+
function add(time, handler, index = undefined) {
|
|
105
113
|
assert.typeof(time, 'bigint');
|
|
114
|
+
/** @type {IndexedHandler} */
|
|
106
115
|
const handlerRecord =
|
|
107
|
-
typeof
|
|
116
|
+
typeof index === 'number' ? { handler, index } : { handler };
|
|
108
117
|
const { handlers: records } = eventsFor(time);
|
|
109
118
|
records.push(handlerRecord);
|
|
110
119
|
schedule.sort((a, b) => Number(a.time - b.time));
|
|
111
120
|
return time;
|
|
112
121
|
}
|
|
113
122
|
|
|
114
|
-
|
|
123
|
+
/**
|
|
124
|
+
* Remove and return all pairs indexed by numbers up to target
|
|
125
|
+
*
|
|
126
|
+
* @param {bigint} target
|
|
127
|
+
*/
|
|
115
128
|
function removeEventsThrough(target) {
|
|
116
129
|
assert.typeof(target, 'bigint');
|
|
117
130
|
const returnValues = [];
|
|
@@ -132,33 +145,29 @@ function makeTimerMap(state = undefined) {
|
|
|
132
145
|
}
|
|
133
146
|
|
|
134
147
|
// We don't expect this to be called often, so we don't optimize for it.
|
|
148
|
+
/**
|
|
149
|
+
*
|
|
150
|
+
* @param {Waker} targetHandler
|
|
151
|
+
* @returns {bigint[]} times that have been removed (may contain duplicates)
|
|
152
|
+
*/
|
|
135
153
|
function remove(targetHandler) {
|
|
154
|
+
/** @type {bigint[]} */
|
|
136
155
|
const droppedTimes = [];
|
|
137
156
|
let i = 0;
|
|
138
157
|
while (i < schedule.length) {
|
|
139
158
|
const { time, handlers } = schedule[i];
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
159
|
+
// Nothing prevents a particular handler from appearing more than once
|
|
160
|
+
for (let j = handlers.length - 1; j >= 0; j -= 1) {
|
|
161
|
+
if (handlers[j].handler === targetHandler) {
|
|
162
|
+
handlers.splice(j, 1);
|
|
143
163
|
droppedTimes.push(time);
|
|
144
|
-
} else {
|
|
145
|
-
i += 1;
|
|
146
164
|
}
|
|
165
|
+
}
|
|
166
|
+
if (handlers.length === 0) {
|
|
167
|
+
// Splice out this element, preserving `i` so we visit any successor.
|
|
168
|
+
schedule.splice(i, 1);
|
|
147
169
|
} else {
|
|
148
|
-
|
|
149
|
-
for (const { handler } of handlers) {
|
|
150
|
-
// @ts-expect-error xxx Waker vs IndexedHandler
|
|
151
|
-
if (handler === targetHandler && handlers.indexOf(handler) !== -1) {
|
|
152
|
-
// @ts-expect-error xxx Waker vs IndexedHandler
|
|
153
|
-
handlers.splice(handlers.indexOf(handler), 1);
|
|
154
|
-
droppedTimes.push(time);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
if (handlers.length === 0) {
|
|
158
|
-
schedule.splice(i, 1);
|
|
159
|
-
} else {
|
|
160
|
-
i += 1;
|
|
161
|
-
}
|
|
170
|
+
i += 1;
|
|
162
171
|
}
|
|
163
172
|
}
|
|
164
173
|
return droppedTimes;
|
|
@@ -277,6 +286,10 @@ export function buildRootDeviceNode(tools) {
|
|
|
277
286
|
saveState();
|
|
278
287
|
return baseTime;
|
|
279
288
|
},
|
|
289
|
+
/**
|
|
290
|
+
* @param {Waker} handler
|
|
291
|
+
* @returns {bigint[]} times that have been removed (may contain duplicates)
|
|
292
|
+
*/
|
|
280
293
|
removeWakeup(handler) {
|
|
281
294
|
const times = deadlines.remove(handler);
|
|
282
295
|
saveState();
|
|
@@ -304,6 +317,10 @@ export function buildRootDeviceNode(tools) {
|
|
|
304
317
|
saveState();
|
|
305
318
|
return index;
|
|
306
319
|
},
|
|
320
|
+
/**
|
|
321
|
+
* @param {number} index
|
|
322
|
+
* @param {Waker} handler
|
|
323
|
+
*/
|
|
307
324
|
schedule(index, handler) {
|
|
308
325
|
const nextTime = nextScheduleTime(index, repeaters, lastPolled);
|
|
309
326
|
deadlines.add(nextTime, handler, index);
|
package/tools/manual-timer.js
CHANGED
|
@@ -8,7 +8,7 @@ import { buildRootObject } from '../src/vats/timer/vat-timer.js';
|
|
|
8
8
|
/**
|
|
9
9
|
* @import {Timestamp} from '@agoric/time'
|
|
10
10
|
* @import {TimerService} from '@agoric/time'
|
|
11
|
-
* @import {Waker} from '../src/devices/timer/device-timer.js'
|
|
11
|
+
* @import {TimerDevice, Waker} from '../src/devices/timer/device-timer.js'
|
|
12
12
|
*
|
|
13
13
|
* @typedef {object} ManualTimerCallbacks
|
|
14
14
|
* @property {(newTime: bigint, msg?: string) => void} [advanceTo]
|
|
@@ -34,8 +34,7 @@ const setup = callbacks => {
|
|
|
34
34
|
currentWakeup: undefined,
|
|
35
35
|
currentHandler: undefined,
|
|
36
36
|
};
|
|
37
|
-
/** @type {
|
|
38
|
-
const deviceMarker = harden({});
|
|
37
|
+
const deviceMarker = /** @type {TimerDevice} */ (harden({}));
|
|
39
38
|
const timerDeviceFuncs = harden({
|
|
40
39
|
getLastPolled: () => state.now,
|
|
41
40
|
setWakeup: (when, handler) => {
|