|
muteki
|
Native threading API. More...
Go to the source code of this file.
Data Structures | |
| struct | threading_waitable_t |
| Common data structure for waitables. More... | |
| struct | message_queue_nonatomic_t |
| Nonatomic backend storage for message queues. More... | |
| struct | thread_s |
| Thread descriptor structure. More... | |
| struct | semaphore_s |
| Semaphore descriptor structure. More... | |
| struct | event_s |
| Event descriptor structure. More... | |
| struct | critical_section_s |
| Critical section descriptor structure. More... | |
| struct | message_queue_s |
| Message queue descriptor structure. More... | |
Typedefs | |
| typedef enum wait_result_e | wait_result_t |
| Result of waitables. | |
| typedef int(* | thread_func_t) (void *user_data) |
| Thread function type. | |
| typedef char | message_queue_message_t[16] |
| Message type for message queues. | |
| typedef struct thread_s | thread_t |
| Thread descriptor type. | |
| typedef struct semaphore_s | semaphore_t |
| Semaphore descriptor type. | |
| typedef struct event_s | event_t |
| Event descriptor type. | |
| typedef struct critical_section_s | critical_section_t |
| Critical section descriptor type. | |
| typedef struct message_queue_s | message_queue_t |
| Message queue descriptor type. | |
Enumerations | |
| enum | thread_wait_reason_e { WAIT_ON_NONE = 0x0 , WAIT_ON_SEMAPHORE = 0x1 , WAIT_ON_EVENT = 0x2 , WAIT_ON_QUEUE = 0x4 , WAIT_ON_SUSPEND = 0x8 , WAIT_ON_CRITICAL_SECTION = 0x10 , WAIT_ON_SLEEP = 0x20 } |
| Thread wait reason enum. More... | |
| enum | wait_result_e { WAIT_RESULT_TIMEOUT = 0x82 , WAIT_RESULT_RESOLVED , WAIT_RESULT_ERROR } |
| Result of waitables. More... | |
Functions | |
| thread_t * | OSCreateThread (thread_func_t func, void *user_data, size_t stack_size, bool defer_start) |
| Create a new thread. | |
| int | OSTerminateThread (thread_t *thr, int exit_code) |
| Terminate a thread. | |
| bool | OSSetThreadPriority (thread_t *thr, short new_slot) |
| Set the thread priority (slot number). | |
| short | OSGetThreadPriority (thread_t *thr) |
| Get the thread priority (slot number). | |
| bool | OSSuspendThread (thread_t *thr) |
| Suspend a thread from outside of that thread. | |
| bool | OSResumeThread (thread_t *thr) |
| Start/restart a previously suspended thread. | |
| bool | OSWakeUpThread (thread_t *thr) |
| Force wake up a sleeping thread. | |
| int | OSExitThread (int exit_code) |
| Terminate current thread. | |
| void | OSSleep (short millis) |
Sleep for millis milliseconds. | |
| semaphore_t * | OSCreateSemaphore (short init_ctr) |
| Create an semaphore descriptor. | |
| wait_result_t | OSWaitForSemaphore (semaphore_t *semaphore, short timeout) |
| Wait and acquire a semaphore. | |
| bool | OSReleaseSemaphore (semaphore_t *semaphore) |
| Release a semaphore. | |
| bool | OSCloseSemaphore (semaphore_t *semaphore) |
| Destroy a semaphore. | |
| event_t * | OSCreateEvent (short latch_on, int flag) |
| Create an event descriptor. | |
| wait_result_t | OSWaitForEvent (event_t *event, short timeout) |
| Wait for an event. | |
| bool | OSSetEvent (event_t *event) |
| Set the event flag. | |
| bool | OSResetEvent (event_t *event) |
| Reset the event flag. | |
| bool | OSCloseEvent (event_t *event) |
| Destroy the event descriptor. | |
| void | OSInitCriticalSection (critical_section_t *cs) |
| Initialize a critical section descriptor. | |
| void | OSEnterCriticalSection (critical_section_t *cs) |
| Enter/aquire a critical section. | |
| void | OSLeaveCriticalSection (critical_section_t *cs) |
| Leave/release a critical section. | |
| void | OSDeleteCriticalSection (critical_section_t *cs) |
| Destroy a critical section descriptor. | |
| message_queue_t * | OSCreateMsgQue (unsigned short size) |
| Create a message queue descriptor. | |
| bool | OSPostMsgQue (message_queue_t *queue, const message_queue_message_t *message) |
| Push a message into the queue. | |
| bool | OSSendMsgQue (message_queue_t *queue, const message_queue_message_t *message) |
| Push a message into the queue and reschedule immediately. | |
| bool | OSPeekMsgQue (message_queue_t *queue, message_queue_message_t *message) |
| Peek the bottom of the queue without popping the message. | |
| bool | OSGetMsgQue (message_queue_t *queue, message_queue_message_t *message) |
| Pop a message from the queue. | |
| bool | OSCloseMsgQue (message_queue_t *queue) |
| Destroy a message queue descriptor. | |
| short | OSGetCurrentlyRunningTCBPrio (void) |
| Get the current running thread's priority (slot number). | |
Native threading API.
| typedef char message_queue_message_t[16] |
Message type for message queues.
This needs to be 4 byte aligned since the inline memcpy in the internal FIFO queue routines use hardcoded ldm/stm.
| enum thread_wait_reason_e |
Thread wait reason enum.
| Enumerator | |
|---|---|
| WAIT_ON_NONE | Nothing |
| WAIT_ON_SEMAPHORE | Waiting on a semaphore. |
| WAIT_ON_EVENT | Waiting on an event. |
| WAIT_ON_QUEUE | Waiting for a message queue push. |
| WAIT_ON_SUSPEND | Waiting to be unsuspended by OSResumeThread(). |
| WAIT_ON_CRITICAL_SECTION | Waiting for a critical section to be released. |
| WAIT_ON_SLEEP | Waiting for sleep counter to expire. |
| enum wait_result_e |
|
extern |
Destroy the event descriptor.
0x10011 | event | The event context. |
| true | The operation was completed successfully. |
| false | The operation failed with error. |
|
extern |
Destroy a message queue descriptor.
0x1001d | queue | The message queue descriptor. |
| true | The operation was completed successfully. |
| false | The operation failed with error. |
|
extern |
Destroy a semaphore.
0x1000c | semaphore | The semaphore context. |
| true | The operation was completed successfully. |
| false | The operation failed with error. |
|
extern |
Create an event descriptor.
0x1000d | latch_on | Set to non-0 will inhibit the event from getting cleared after a OSWaitForEvent() is resolved. |
| flag | The initial flag value. Can be either 0 or 1. |
|
extern |
Create a message queue descriptor.
0x10018 | size | Size of the queue in number of messages (will use sizeof(message_queue_message_t) * size bytes of memory). |
|
extern |
Create an semaphore descriptor.
0x10009 | init_ctr | Initial counter value. |
|
extern |
Create a new thread.
0x10000 | func | Function to execute in the new thread. |
| user_data | User data for the thread. |
| stack_size | The size of the thread stack. |
| defer_start | Do not immediately schedule this thread and create it as suspended. |
|
extern |
Destroy a critical section descriptor.
0x10015 | [in,out] | cs | The critical section descriptor. |
|
extern |
Enter/aquire a critical section.
Besta critical sections behave like recursive mutexes. Therefore this will block when multiple threads are trying to enter the same context, but it will let repeated entry attempts initiated by the same thread to pass through. The context is released when all of the entries are reverted by a OSLeaveCriticalSection() call.
0x10013 | [in,out] | cs | The critical section descriptor. |
|
extern |
Terminate current thread.
0x10007This calls OSTerminateThread() with the descriptor of current thread as thr.
| exit_code | The exit code. |
| 0 | The operation was completed successfully. |
|
extern |
Get the current running thread's priority (slot number).
So far only Pocket Challenge implements this syscall. Calling it on other devices will very likely cause the NOSYS handler to be called, which in turn will crash the system.
On other devices, this can be simulated using mutekix:
Requires -lkrnllib when dynamically linking with the shims.
0x200a2
|
extern |
Pop a message from the queue.
0x1001c | queue | The message queue descriptor. |
| message | The result message. |
| true | The operation was completed successfully. |
| false | The operation failed with error. |
|
extern |
Get the thread priority (slot number).
0x10003 | thr | The thread descriptor. |
|
extern |
Initialize a critical section descriptor.
0x10012 | [out] | cs | The critical section descriptor. |
|
extern |
Leave/release a critical section.
0x10014 | [in,out] | cs | The critical section descriptor. |
|
extern |
Peek the bottom of the queue without popping the message.
0x1001b | queue | The message queue descriptor. |
| message | The result message. |
| true | The operation was completed successfully. |
| false | The operation failed with error. |
|
extern |
Push a message into the queue.
0x10019 | queue | The message queue descriptor. |
| message | The message being pushed. |
| true | The operation was completed successfully. |
| false | The operation failed with error. |
|
extern |
Release a semaphore.
0x1000b | semaphore | The semaphore context. |
| true | The operation was completed successfully. |
| false | The operation failed with error. |
|
extern |
Reset the event flag.
This sets the event_t::flag to 0.
0x10010 | event | The event context. |
| true | The operation was completed successfully. |
| false | The operation failed with error. |
|
extern |
Start/restart a previously suspended thread.
0x10005 | thr | The thread descriptor. |
| true | The operation was completed successfully. |
| false | The operation failed with error. |
|
extern |
Push a message into the queue and reschedule immediately.
0x1001a | queue | The message queue descriptor. |
| message | The message being pushed. |
| true | The operation was completed successfully. |
| false | The operation failed with error. |
|
extern |
Set the event flag.
This sets the event_t::flag to 1.
0x1000f | event | The event context. |
| true | The operation was completed successfully. |
| false | The operation failed with error. |
|
extern |
Set the thread priority (slot number).
On Besta RTOS, priority is implied in the natural order of the threads in the global thread table. Some slots in the table seem to be reserved (8 for the top and 18 for the bottom) and are not accessible by just allocating the thread with OSCreateThread(). User can move threads to these reserved slots by calling the OSSetThreadPriority() function.
0x10002 | thr | The thread descriptor. |
| new_slot | The new slot number. |
| true | The operation was completed successfully. |
| false | The operation failed with error. |
|
extern |
Sleep for millis milliseconds.
0x10008 | millis | Time to sleep in milliseconds. |
|
extern |
Suspend a thread from outside of that thread.
0x10004 | thr | The thread descriptor. |
| true | The operation was completed successfully. |
| false | The operation failed with error. |
|
extern |
Terminate a thread.
0x10001 | thr | Thread to terminate. |
| exit_code | The exit code. |
| 0 | The operation was completed successfully. |
|
extern |
Wait for an event.
0x1000e | event | The event context. |
| timeout | Timeout in OSSleep() units. |
|
extern |
Wait and acquire a semaphore.
0x1000a | semaphore | The semaphore context. |
| timeout | Timeout in OSSleep() units. |
|
extern |
Force wake up a sleeping thread.
0x10006This expire the sleep counter of a thread immediately and reschedule if the thread is not suspended.
| thr | The thread descriptor. |
| true | The operation was completed successfully. |
| false | The operation failed with error. |