seems to work

This commit is contained in:
Alistair Smith
2025-06-04 02:45:24 -07:00
parent 6049fee6d4
commit 505d1be9bf
2 changed files with 10 additions and 7 deletions

View File

@@ -272,11 +272,11 @@ void Worker::terminate()
// m_contextProxy.terminateWorkerGlobalScope();
m_terminationFlags.fetch_or(TerminateRequestedFlag);
if (ScriptExecutionContext::getScriptExecutionContext(m_clientIdentifier)) {
auto* impl = lifecycleHandle_;
lifecycleHandle_ = nullptr;
WebWorkerLifecycleHandle__requestTermination(impl);
}
// if (ScriptExecutionContext::getScriptExecutionContext(m_clientIdentifier)) {
// auto* impl = lifecycleHandle_;
// lifecycleHandle_ = nullptr;
// WebWorkerLifecycleHandle__requestTermination(impl);
// }
}
// const char* Worker::activeDOMObjectName() const

View File

@@ -448,6 +448,8 @@ fn unhandledError(this: *WebWorker, _: anyerror) void {
}
pub export fn WebWorkerLifecycleHandle__requestTermination(handle: *WebWorkerLifecycleHandle) void {
if (@intFromPtr(handle) == 0) return;
handle.requestTermination();
}
@@ -700,24 +702,25 @@ const WebWorkerLifecycleHandle = struct {
} else {
self.mutex.unlock();
self.deref();
self.deinit();
}
self.deref();
}
pub fn onTermination(self: *WebWorkerLifecycleHandle) void {
self.ref();
self.mutex.lock();
if (self.requested_terminate.swap(false, .acquire)) {
// we already requested to terminate, therefore this handle has
// already been consumed on the other thread and we are able to free
// it.
self.mutex.unlock();
self.deinit();
self.deref();
return;
}
self.worker = null;
self.mutex.unlock();
self.deref();
}
};