mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-25 19:21:11 +08:00
feat: Atomics.waitAsync/pause 异步臂与 notify 唤醒面
This commit is contained in:
@@ -75,6 +75,12 @@ impl Vm {
|
||||
for job in &self.job_queue {
|
||||
crate::promise::for_each_job_value(job, &mut f);
|
||||
}
|
||||
// Atomics waiter 表登记的 promise 是 GC 根(run 内跨调用存活)。
|
||||
for promises in self.atomics_waiters.values() {
|
||||
for p in promises {
|
||||
f(*p);
|
||||
}
|
||||
}
|
||||
for iter in &self.iters.for_in_iters {
|
||||
if iter.is_null() {
|
||||
continue;
|
||||
@@ -150,6 +156,12 @@ impl Vm {
|
||||
for job in &mut self.job_queue {
|
||||
crate::promise::rewrite_job_values(job, &mut rewrite);
|
||||
}
|
||||
// Atomics waiter 表中的 promise 随 sweep 重写(与 mark 段一一对应)。
|
||||
for promises in self.atomics_waiters.values_mut() {
|
||||
for p in promises {
|
||||
*p = rewrite(*p);
|
||||
}
|
||||
}
|
||||
for iter in &mut self.iters.for_in_iters {
|
||||
if iter.is_null() {
|
||||
continue;
|
||||
|
||||
@@ -189,6 +189,10 @@ pub struct Vm {
|
||||
pub async_generator_function_proto: P<JsObject>,
|
||||
/// 微任务队列(Promise reactions / thenable 委托),`run()` 末尾 FIFO drain。
|
||||
pub(crate) job_queue: VecDeque<crate::promise::Microtask>,
|
||||
/// Atomics.waitAsync waiter 表:键 = (缓冲对象指针, 元素字节偏移),值 =
|
||||
/// 登记的 promise FIFO。键取登记时刻视图的 `buffer` 现指针(同 run 无 GC 时
|
||||
/// notify 侧读同一指针恒匹配);run 边界清空,清位后 promise 无强根自然回收。
|
||||
pub(crate) atomics_waiters: HashMap<(u64, usize), Vec<JsValue>>,
|
||||
pub math_rng_state: u64,
|
||||
/// 子模块平表的表代际注册表:键 = 表代际(`current_gen` 为当前 run 正在
|
||||
/// 装载的代际)。函数对象创建时记录自身所属代际(`JsObject::table_gen`),
|
||||
|
||||
@@ -216,4 +216,13 @@ impl oxide_runtime_api::VmHost for Vm {
|
||||
fn symbol_key_for_id(&self, idx: u32) -> Option<String> {
|
||||
self.symbols.key_for_id(idx)
|
||||
}
|
||||
fn atomics_new_waiter_promise(&mut self) -> JsValue {
|
||||
self.atomics_new_waiter_promise()
|
||||
}
|
||||
fn atomics_register_waiter(&mut self, buffer: *mut JsObject, offset: usize, promise: JsValue) {
|
||||
self.atomics_register_waiter(buffer, offset, promise)
|
||||
}
|
||||
fn atomics_wake_waiters(&mut self, buffer: *mut JsObject, offset: usize, count: f64) -> usize {
|
||||
self.atomics_wake_waiters(buffer, offset, count)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user