Path: blob/main/system/lib/pthread/thread_mailbox.h
6171 views
/*1* Copyright 2023 The Emscripten Authors. All rights reserved.2* Emscripten is available under two separate licenses, the MIT license and the3* University of Illinois/NCSA Open Source License. Both these licenses can be4* found in the LICENSE file.5*/67#pragma once89#include <em_task_queue.h>10#include <pthread.h>1112// Try to increment the refcount of the mailbox, ensuring it will stay open13// until the refcount is decremented again. Returns 1 on success or 0 if the14// mailbox is already closed.15int emscripten_thread_mailbox_ref(pthread_t thread);1617// Decrement the mailbox's refcount.18void emscripten_thread_mailbox_unref(pthread_t thread);1920// Send a message to the given `thread`. This should only be called after21// incrementing the mailbox refcount to ensure it stays open. The receiving22// thread will receive the message the next time it returns to its event loop,23// or if the target thread shuts down before then, the message's shutdown24// handler will be called instead.25void emscripten_thread_mailbox_send(pthread_t thread, task t);2627// Initialize the mailbox on a pthread struct. Called during `pthread_create`.28void _emscripten_thread_mailbox_init(pthread_t thread);2930void _emscripten_thread_mailbox_await(pthread_t thread);3132// Close the mailbox and cancel any pending messages.33void _emscripten_thread_mailbox_shutdown(pthread_t thread);3435// Send a postMessage notification telling the target thread to check its36// mailbox when it returns to its event loop. Pass in the current thread id37// minimize calls back into Wasm.38void _emscripten_notify_mailbox_postmessage(pthread_t target_thread,39pthread_t curr_thread);404142