diff options
Diffstat (limited to 'include/rune/core/thread.h')
-rw-r--r-- | include/rune/core/thread.h | 72 |
1 files changed, 65 insertions, 7 deletions
diff --git a/include/rune/core/thread.h b/include/rune/core/thread.h index 698136c..976b7d3 100644 --- a/include/rune/core/thread.h +++ b/include/rune/core/thread.h @@ -25,30 +25,88 @@ #include <rune/util/types.h> #include <rune/util/list.h> +/** + * Platform-agnostic thread handle + */ struct thread { - int ID; - int detached; - void *thread_handle; - struct list_head list; + int ID; ///< In-engine thread ID + int detached; ///< 1 if thread has been detached, 0 otherwise + void *thread_handle; ///< System-defined thread handle, usually a pthread_t + struct list_head list; ///< Linked list of all threads, used internally }; +/** + * Platform-agnostic mutex handle + */ struct mutex { - int ID; - void *mutex_handle; - struct list_head list; + int ID; ///< In-engine mutex ID + void *mutex_handle; ///< System-defined mutex handle, usually a pthread_mutex_t + struct list_head list; ///< Linked list of all mutexes, used internally }; +/** + * \brief Initializes the engine's thread API, must be called before using any + * API function + */ RAPI void rune_init_thread_api(void); +/** + * \brief Creates and starts a new thread + * \param[in] thread_fn The function the thread will execute + * \param[in] data Arguments for the thread_fn + * \param[in] detached Whether the thread will start detached + * \return ID of created thread, or -1 if error + */ RAPI int rune_thread_init(void* (*thread_fn)(void *data), void *data, int detached); + +/** + * \brief Force-stops a thread + * \param[in] ID Thread to stop + * \return 0, or -1 if thread cannot be found + */ RAPI int rune_thread_cancel(int ID); + +/** + * \brief Joins a thread to the calling thread + * \param[in] ID Thread to wait on + * \param[out] retval Return value of thread_fn + */ RAPI int rune_thread_join(int ID, void **retval); + +/** + * \brief Gets the current thread ID + * \return Current in-engine ID of the calling thread, or -1 on error + */ RAPI int rune_thread_self(void); + +/** + * \brief Terminates the calling thread + * \param[in] retval Where to put the thread_fn return value + */ RAPI void rune_thread_exit(void *retval); +/** + * \brief Creates a new mutex + * \return ID of new mutex, or -1 on error + */ RAPI int rune_mutex_init(void); + +/** + * \brief Cleans up a mutex and releases its memory + * \param[in] ID Mutex to destroy + */ RAPI int rune_mutex_destroy(int ID); + +/** + * \brief Locks a mutex + * \param[in] ID Mutex to lock + */ RAPI int rune_mutex_lock(int ID); + +/** + * \brief Unlocks a mutex + * \param[in] ID Mutex to unlock + */ RAPI int rune_mutex_unlock(int ID); #endif |