Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/system/lib/pthread/thread_mailbox.h
6171 views
1
/*
2
* Copyright 2023 The Emscripten Authors. All rights reserved.
3
* Emscripten is available under two separate licenses, the MIT license and the
4
* University of Illinois/NCSA Open Source License. Both these licenses can be
5
* found in the LICENSE file.
6
*/
7
8
#pragma once
9
10
#include <em_task_queue.h>
11
#include <pthread.h>
12
13
// Try to increment the refcount of the mailbox, ensuring it will stay open
14
// until the refcount is decremented again. Returns 1 on success or 0 if the
15
// mailbox is already closed.
16
int emscripten_thread_mailbox_ref(pthread_t thread);
17
18
// Decrement the mailbox's refcount.
19
void emscripten_thread_mailbox_unref(pthread_t thread);
20
21
// Send a message to the given `thread`. This should only be called after
22
// incrementing the mailbox refcount to ensure it stays open. The receiving
23
// thread will receive the message the next time it returns to its event loop,
24
// or if the target thread shuts down before then, the message's shutdown
25
// handler will be called instead.
26
void emscripten_thread_mailbox_send(pthread_t thread, task t);
27
28
// Initialize the mailbox on a pthread struct. Called during `pthread_create`.
29
void _emscripten_thread_mailbox_init(pthread_t thread);
30
31
void _emscripten_thread_mailbox_await(pthread_t thread);
32
33
// Close the mailbox and cancel any pending messages.
34
void _emscripten_thread_mailbox_shutdown(pthread_t thread);
35
36
// Send a postMessage notification telling the target thread to check its
37
// mailbox when it returns to its event loop. Pass in the current thread id
38
// minimize calls back into Wasm.
39
void _emscripten_notify_mailbox_postmessage(pthread_t target_thread,
40
pthread_t curr_thread);
41
42