11#ifndef __MUTEKI_THREADING_H__
12#define __MUTEKI_THREADING_H__
Common include file for all muteki-shims headers.
#define SYS_ALIGN(n)
Attribute for forcing alignment.
Definition common.h:86
Besta error code constants and functions.
unsigned int bxc_errno_t
Definition errno.h:22
void OSLeaveCriticalSection(bxc_cs_t *cs)
Leave/release a critical section.
struct bxc_event_s bxc_event_t
Event descriptor type.
Definition threading.h:170
bool OSResumeThread(bxc_thread_t *thr)
Start/restart a previously suspended thread.
bool OSSuspendThread(bxc_thread_t *thr)
Suspend a thread from outside of that thread.
bxc_wait_reason_e
Thread wait reason enum.
Definition threading.h:24
@ BXC_WAIT_ON_NONE
Nothing.
Definition threading.h:28
@ BXC_WAIT_ON_SUSPEND
Waiting to be unsuspended by OSResumeThread().
Definition threading.h:44
@ BXC_WAIT_ON_SLEEP
Deprecated name of BXC_WAIT_ON_TIMEOUT.
Definition threading.h:53
@ BXC_WAIT_ON_YIELD
Waiting to take back control after a yield/timeout.
Definition threading.h:59
@ BXC_WAIT_ON_QUEUE
Waiting for a message queue push.
Definition threading.h:40
@ BXC_WAIT_ON_CRITICAL_SECTION
Waiting for a critical section to be released.
Definition threading.h:48
@ BXC_WAIT_ON_SEMAPHORE
Waiting on a semaphore.
Definition threading.h:32
@ BXC_WAIT_ON_EVENT
Waiting on an event.
Definition threading.h:36
bxc_wait_result_e
Result of waitables.
Definition threading.h:87
@ BXC_WAIT_RESULT_ERROR
An error occurred.
Definition threading.h:99
@ BXC_WAIT_RESULT_TIMEOUT
Timeout before the event is set.
Definition threading.h:91
@ BXC_WAIT_RESULT_RESOLVED
The event is set.
Definition threading.h:95
bxc_event_t * OSCreateEvent(short latch_on, int flag)
Create an event descriptor.
int OSTerminateThread(bxc_thread_t *thr, int exit_code)
Terminate a thread.
bool OSGetMsgQue(bxc_queue_t *queue, bxc_queue_message_t *message)
Pop a message from the queue.
struct bxc_thread_s bxc_thread_t
Thread descriptor type.
Definition threading.h:162
bool OSPeekMsgQue(bxc_queue_t *queue, bxc_queue_message_t *message)
Pop a message from the queue asynchronously.
bool OSResetEvent(bxc_event_t *event)
Reset the event flag.
struct bxc_queue_s bxc_queue_t
Message queue descriptor type.
Definition threading.h:178
void OSSleep(short time_units)
Sleep for number of scheduler time_units .
enum bxc_wait_result_e bxc_wait_result_t
Result of waitables.
bxc_threading_kind_e
Runtime threading descriptor kind code.
Definition threading.h:65
@ BXC_THREADING_KIND_THREAD
Thread.
Definition threading.h:69
@ BXC_THREADING_KIND_SEMAPHORE
Semaphore.
Definition threading.h:73
@ BXC_THREADING_KIND_EVENT
Event.
Definition threading.h:77
@ BXC_THREADING_KIND_CS_QUEUE
Critical section or queue.
Definition threading.h:81
bool OSSetEvent(bxc_event_t *event)
Set the event flag.
bxc_thread_t * OSCreateThread(bxc_thread_func_t func, void *user_data, size_t stack_size, bool defer_start)
Create a new thread.
bool OSReleaseSemaphore(bxc_semaphore_t *semaphore)
Release a semaphore.
bxc_semaphore_t * OSCreateSemaphore(short init_ctr)
Create an semaphore descriptor.
bool OSCloseSemaphore(bxc_semaphore_t *semaphore)
Destroy a semaphore.
void OSDeleteCriticalSection(bxc_cs_t *cs)
Destroy a critical section descriptor.
int(*) bxc_thread_func_t(void *user_data)
Thread function type.
Definition threading.h:105
bxc_wait_result_t OSWaitForEvent(bxc_event_t *event, short timeout)
Wait for an event.
bool OSPostMsgQue(bxc_queue_t *queue, const bxc_queue_message_t *message)
Push a message into the queue.
struct bxc_semaphore_s bxc_semaphore_t
Semaphore descriptor type.
Definition threading.h:166
bxc_wait_result_t OSWaitForSemaphore(bxc_semaphore_t *semaphore, short timeout)
Wait and acquire a semaphore.
short OSGetCurrentlyRunningTCBPrio(void)
Get the current running thread's priority (slot number).
bool OSCloseEvent(bxc_event_t *event)
Destroy the event descriptor.
bool OSCloseMsgQue(bxc_queue_t *queue)
Destroy a message queue descriptor.
bool OSSetThreadPriority(bxc_thread_t *thr, short new_slot)
Set the thread priority (slot number).
void OSEnterCriticalSection(bxc_cs_t *cs)
Enter/aquire a critical section.
bool OSSendMsgQue(bxc_queue_t *queue, const bxc_queue_message_t *message)
Push a message into the queue and reschedule immediately.
short OSGetThreadPriority(bxc_thread_t *thr)
Get the thread priority (slot number).
union bxc_waitable_desc_u bxc_waitable_desc_t
Waitable object union used by bxc_thread_t.
Definition threading.h:182
bool OSWakeUpThread(bxc_thread_t *thr)
Force wake up a sleeping thread.
bxc_queue_t * OSCreateMsgQue(unsigned short size)
Create a message queue descriptor.
void OSInitCriticalSection(bxc_cs_t *cs)
Initialize a critical section descriptor.
struct bxc_cs_s bxc_cs_t
Critical section descriptor type.
Definition threading.h:174
int OSExitThread(int exit_code)
Terminate current thread.
unsigned char bxc_queue_message_t[16]
Message type for message queues.
Definition threading.h:129
Critical section descriptor structure.
Definition threading.h:349
unsigned short refcount
Reference counter.
Definition threading.h:363
int magic
Magic. Always 0x202.
Definition threading.h:355
bxc_waitable_t wait_state
Wait state of the current critical section.
Definition threading.h:368
bxc_thread_t * thr
Thread descriptor that currently holds the CS.
Definition threading.h:359
char _padding_0x13
Unknown. Probably padding bytes.
Definition threading.h:368
Event descriptor structure.
Definition threading.h:320
char _padding_0x13
Unknown. Probably padding bytes.
Definition threading.h:339
int flag
Flag value. 1 is set and 0 is clear.
Definition threading.h:329
int magic
Magic. Always 0x201.
Definition threading.h:325
short latch_on
Latch on after event wait.
Definition threading.h:333
bxc_waitable_t wait_state
Wait state of the current event.
Definition threading.h:338
Nonatomic backend storage for message queues.
Definition threading.h:135
bxc_queue_message_t * messages
Message body.
Definition threading.h:139
short pop_idx
Pop index.
Definition threading.h:147
short _padding_0xa
Unknown. Probably padding bytes.
Definition threading.h:155
short push_idx
Push index.
Definition threading.h:151
unsigned short size
Number of chunks.
Definition threading.h:143
Message queue descriptor structure.
Definition threading.h:379
int magic
Magic. Always 0x202.
Definition threading.h:385
char _padding_0x13
Unknown. Probably padding bytes.
Definition threading.h:398
bxc_queue_nonatomic_t * storage
Storage structure.
Definition threading.h:390
short _padding_0x8
Unknown. Probably padding bytes.
Definition threading.h:389
bxc_waitable_t wait_state
Wait state of the current event.
Definition threading.h:394
Semaphore descriptor structure.
Definition threading.h:291
int magic
Magic. Always 0x200.
Definition threading.h:296
char _padding_0x13
Unknown. Probably padding bytes.
Definition threading.h:311
short ctr
Counter.
Definition threading.h:303
int _padding_0x4
Unknown. Probably padding bytes.
Definition threading.h:299
bxc_waitable_t wait_state
Wait state of the current semaphore.
Definition threading.h:307
Thread descriptor structure.
Definition threading.h:187
short slot
Slot number. For scheduler.
Definition threading.h:241
unsigned char slot_low3b_bit
Lower 3 bit bitmask of the slot number. For scheduler.
Definition threading.h:253
bxc_thread_t * prev
Previous thread descriptor.
Definition threading.h:265
int magic
Magic. Always 0x100.
Definition threading.h:192
int exit_code
Exit code of the thread. Initializes to 0.
Definition threading.h:205
bxc_thread_t * next
Next thread descriptor.
Definition threading.h:269
bxc_waitable_desc_t * event
Waitable descriptor (excluding critical sections) that the thread is waiting for.
Definition threading.h:261
bxc_thread_func_t thread_func
Thread function entrypoint.
Definition threading.h:217
uintptr_t unk_0x14
Unknown. Initializes to 0x80000000.
Definition threading.h:213
char slot_high3b
Upper 3 bit of the slot number. For scheduler.
Definition threading.h:249
short wait_reason
Current wait reason of the thread.
Definition threading.h:237
void * stack
Allocated stack memory.
Definition threading.h:201
bxc_errno_t kerrno
Error code.
Definition threading.h:209
unsigned char slot_high3b_bit
Upper 3 bit bitmask of the slot number. For scheduler.
Definition threading.h:257
uintptr_t * sp
Stack pointer.
Definition threading.h:197
short timeout
Thread execution timeout in number of scheduler ticks.
Definition threading.h:227
short sleep_counter
Number of scheduler time units left to sleep.
Definition threading.h:232
char slot_low3b
Lower 3 bit of the slot number. For scheduler.
Definition threading.h:245
bxc_waitable_t wait_state
Wait state of the current descriptor.
short user_data1
Defined by synchronization primitive.
char user_data2
Defined by synchronization primitive.
intptr_t user_data0
Defined by synchronization primitive.
Common data structure for waitables.
Definition threading.h:112
unsigned char active_bytes
Bitfield that indicates which waiting_by bytes are currently active.
Definition threading.h:116
unsigned char waiting_by[8]
Bitfield that tracks threads that are waiting for this waitable.
Definition threading.h:121
char name[0x20]
Name of the thread. For debugging purposes.
uintptr_t ktls[8]
Kernel TLS (Muteki-specific).
char unk_0x34[0x20]
Old placeholder name.
Generic waitable descriptor.
Definition threading.h:411
bxc_semaphore_t semaphore
Semaphore-specific reader.
Definition threading.h:441
bxc_event_t event
Event-specific reader.
Definition threading.h:446
bxc_cs_t cs
Critical section-specific reader.
Definition threading.h:456
bxc_queue_t queue
Queue-specific reader.
Definition threading.h:466