diff --git a/src/wasi_farm/shared_array_buffer/worker_background/worker_blob.ts b/src/wasi_farm/shared_array_buffer/worker_background/worker_blob.ts index c809626..1103b98 100644 --- a/src/wasi_farm/shared_array_buffer/worker_background/worker_blob.ts +++ b/src/wasi_farm/shared_array_buffer/worker_background/worker_blob.ts @@ -1,10 +1,10 @@ export const url = () => { - const code = - 'function _define_property(r,e,t){return e in r?Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):r[e]=t,r}class AllocatorUseArrayBuffer{static init_self(r){return new AllocatorUseArrayBuffer(r.share_arrays_memory)}async async_write(r,e,t){let o=new Int32Array(this.share_arrays_memory);for(;;){let{value:i}=Atomics.waitAsync(o,0,1);if("timed-out"===(i instanceof Promise?await i:i))throw Error("timed-out lock");if(0===Atomics.compareExchange(o,0,0,1)){this.write_inner(r,e,t),Atomics.store(o,0,0),Atomics.notify(o,0,1);break}}}block_write(r,e,t){for(;;){let o=new Int32Array(this.share_arrays_memory);if("timed-out"===Atomics.wait(o,0,1))throw Error("timed-out lock");if(0!==Atomics.compareExchange(o,0,0,1))continue;let i=this.write_inner(r,e,t);return Atomics.store(o,0,0),Atomics.notify(o,0,1),i}}write_inner(r,e,t){let o,i;let s=new Int32Array(this.share_arrays_memory),a=new Uint8Array(this.share_arrays_memory);o=0===Atomics.add(s,1,1)?Atomics.store(s,2,12):Atomics.load(s,2);let n=this.share_arrays_memory.byteLength,c=r.byteLength,l=o+c;if(n{let{msg:e}=r.data;"ready"===e&&d(),"done"===e&&(this.workers[h].terminate(),this.workers[h]=void 0,console.log(`worker ${h} done so terminate`))},a.postMessage({...this.override_object,...y,worker_id:h,worker_background_ref:this.ref()}),await _,Atomics.store(e,0,h);break r}let a=Atomics.exchange(r,1,0);if(1!==a)throw Error("Lock is already set");let n=Atomics.notify(r,1,1);if(1!==n){if(0===n){console.warn("notify failed, waiter is late");continue}throw Error("notify failed: "+n)}}catch(r){console.error(r)}}constructor(r){_define_property(this,"override_object",void 0),_define_property(this,"allocator",void 0),_define_property(this,"lock",void 0),_define_property(this,"signature_input",void 0),_define_property(this,"workers",[]),_define_property(this,"listen_holder",void 0),this.override_object=r,this.lock=new SharedArrayBuffer(8),this.allocator=new AllocatorUseArrayBuffer(new SharedArrayBuffer(10240)),this.signature_input=new SharedArrayBuffer(24),this.listen_holder=this.listen()}};globalThis.onmessage=r=>{let{override_object:e}=r.data;postMessage(new WorkerBackground(e).ref()),console.log("worker_background ready")};'; + const code = + 'function _define_property(r,e,t){return e in r?Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):r[e]=t,r}class AllocatorUseArrayBuffer{static init_self(r){return new AllocatorUseArrayBuffer(r.share_arrays_memory)}async async_write(r,e,t){let o=new Int32Array(this.share_arrays_memory);for(;;){let{value:i}=Atomics.waitAsync(o,0,1);if("timed-out"===(i instanceof Promise?await i:i))throw Error("timed-out lock");if(0===Atomics.compareExchange(o,0,0,1)){this.write_inner(r,e,t),Atomics.store(o,0,0),Atomics.notify(o,0,1);break}}}block_write(r,e,t){for(;;){let o=new Int32Array(this.share_arrays_memory);if("timed-out"===Atomics.wait(o,0,1))throw Error("timed-out lock");if(0!==Atomics.compareExchange(o,0,0,1))continue;let i=this.write_inner(r,e,t);return Atomics.store(o,0,0),Atomics.notify(o,0,1),i}}write_inner(r,e,t){let o,i;let s=new Int32Array(this.share_arrays_memory),a=new Uint8Array(this.share_arrays_memory);o=0===Atomics.add(s,1,1)?Atomics.store(s,2,12):Atomics.load(s,2);let n=this.share_arrays_memory.byteLength,c=r.byteLength,l=o+c;if(n{let{msg:e}=r.data;"ready"===e&&d(),"done"===e&&(this.workers[h].terminate(),this.workers[h]=void 0,console.log(`worker ${h} done so terminate`))},a.postMessage({...this.override_object,...y,worker_id:h,worker_background_ref:this.ref()}),await _,Atomics.store(e,0,h)}let s=Atomics.exchange(r,1,0);if(1!==s)throw Error("Lock is already set");let a=Atomics.notify(r,1,1);if(1!==a){if(0===a){console.warn("notify failed, waiter is late");continue}throw Error("notify failed: "+a)}}catch(r){console.error(r)}}constructor(r){_define_property(this,"override_object",void 0),_define_property(this,"allocator",void 0),_define_property(this,"lock",void 0),_define_property(this,"signature_input",void 0),_define_property(this,"workers",[]),_define_property(this,"listen_holder",void 0),this.override_object=r,this.lock=new SharedArrayBuffer(8),this.allocator=new AllocatorUseArrayBuffer(new SharedArrayBuffer(10240)),this.signature_input=new SharedArrayBuffer(24),this.listen_holder=this.listen()}};globalThis.onmessage=r=>{let{override_object:e}=r.data;postMessage(new WorkerBackground(e).ref()),console.log("worker_background ready")};'; - const blob = new Blob([code], { type: "application/javascript" }); + const blob = new Blob([code], { type: "application/javascript" }); - const url = URL.createObjectURL(blob); + const url = URL.createObjectURL(blob); - return url; + return url; };