forked from LeenkxTeam/LNXSDK
Update Files
This commit is contained in:
9
Kha/Kinc/Sources/kinc/threads/atomic.h
Normal file
9
Kha/Kinc/Sources/kinc/threads/atomic.h
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <kinc/global.h>
|
||||
|
||||
#include <kinc/backend/atomic.h>
|
||||
|
||||
/*! \file atomic.h
|
||||
\brief Provides atomics aka interlocked operations.
|
||||
*/
|
62
Kha/Kinc/Sources/kinc/threads/event.h
Normal file
62
Kha/Kinc/Sources/kinc/threads/event.h
Normal file
@ -0,0 +1,62 @@
|
||||
#pragma once
|
||||
|
||||
#include <kinc/global.h>
|
||||
|
||||
#include <kinc/backend/event.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
/*! \file event.h
|
||||
\brief An event is a simple threading-object that allows a thread to wait for something to happen on another thread.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct kinc_event {
|
||||
kinc_event_impl_t impl;
|
||||
} kinc_event_t;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes an event-object.
|
||||
/// </summary>
|
||||
/// <param name="event">The event to initialize</param>
|
||||
/// <param name="auto_clear">When auto-clear is true, the event is automatically reset to an unsignaled state after a successful wait-operation</param>
|
||||
KINC_FUNC void kinc_event_init(kinc_event_t *event, bool auto_clear);
|
||||
|
||||
/// <summary>
|
||||
/// Destroys an event-object.
|
||||
/// </summary>
|
||||
/// <param name="event">The event to destroy</param>
|
||||
KINC_FUNC void kinc_event_destroy(kinc_event_t *event);
|
||||
|
||||
/// <summary>
|
||||
/// Signals an event which allows threads which are waiting for the event to continue.
|
||||
/// </summary>
|
||||
/// <param name="event">The event to signal</param>
|
||||
KINC_FUNC void kinc_event_signal(kinc_event_t *event);
|
||||
|
||||
/// <summary>
|
||||
/// Waits for an event to be signaled.
|
||||
/// </summary>
|
||||
/// <param name="event">The event to wait for</param>
|
||||
KINC_FUNC void kinc_event_wait(kinc_event_t *event);
|
||||
|
||||
/// <summary>
|
||||
/// Waits for an event to be signaled or the provided timeout to run out - whatever happens first.
|
||||
/// </summary>
|
||||
/// <param name="event">The event to wait for</param>
|
||||
/// <param name="timeout">The timeout in seconds after which the function returns if the event hasn't been signaled</param>
|
||||
/// <returns>Whether the event has been signaled</returns>
|
||||
KINC_FUNC bool kinc_event_try_to_wait(kinc_event_t *event, double timeout);
|
||||
|
||||
/// <summary>
|
||||
/// Resets an event to an unsignaled state.
|
||||
/// </summary>
|
||||
/// <param name="event">The event to reset</param>
|
||||
KINC_FUNC void kinc_event_reset(kinc_event_t *event);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
47
Kha/Kinc/Sources/kinc/threads/fiber.h
Normal file
47
Kha/Kinc/Sources/kinc/threads/fiber.h
Normal file
@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include <kinc/global.h>
|
||||
|
||||
#include <kinc/backend/fiber.h>
|
||||
|
||||
/*! \file fiber.h
|
||||
\brief The fiber-API is experimental and only supported on a few system.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct kinc_fiber {
|
||||
kinc_fiber_impl_t impl;
|
||||
} kinc_fiber_t;
|
||||
|
||||
/// <summary>
|
||||
/// Uses the current thread as a fiber.
|
||||
/// </summary>
|
||||
/// <param name="fiber">The fiber-object to initialize using the current thread</param>
|
||||
KINC_FUNC void kinc_fiber_init_current_thread(kinc_fiber_t *fiber);
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a fiber.
|
||||
/// </summary>
|
||||
/// <param name="fiber">The fiber-object to initialize</param>
|
||||
/// <param name="func">The function to be run in the fiber-context</param>
|
||||
/// <param name="param">A parameter to be provided to the fiber-function when it starts running</param>
|
||||
KINC_FUNC void kinc_fiber_init(kinc_fiber_t *fiber, void (*func)(void *param), void *param);
|
||||
|
||||
/// <summary>
|
||||
/// Destroys a fiber.
|
||||
/// </summary>
|
||||
/// <param name="fiber">The fiber to destroy</param>
|
||||
KINC_FUNC void kinc_fiber_destroy(kinc_fiber_t *fiber);
|
||||
|
||||
/// <summary>
|
||||
/// Switch the current thread to a different fiber.
|
||||
/// </summary>
|
||||
/// <param name="fiber">The fiber to switch to</param>
|
||||
KINC_FUNC void kinc_fiber_switch(kinc_fiber_t *fiber);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
86
Kha/Kinc/Sources/kinc/threads/mutex.h
Normal file
86
Kha/Kinc/Sources/kinc/threads/mutex.h
Normal file
@ -0,0 +1,86 @@
|
||||
#pragma once
|
||||
|
||||
#include <kinc/global.h>
|
||||
|
||||
#include <kinc/backend/mutex.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
/*! \file mutex.h
|
||||
\brief Provides mutexes which are used to synchronize threads and uber-mutexes which are used to synchronize processes.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct kinc_mutex {
|
||||
kinc_mutex_impl_t impl;
|
||||
} kinc_mutex_t;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a mutex-object.
|
||||
/// </summary>
|
||||
/// <param name="mutex">The mutex to initialize</param>
|
||||
KINC_FUNC void kinc_mutex_init(kinc_mutex_t *mutex);
|
||||
|
||||
/// <summary>
|
||||
/// Destroys a mutex-object.
|
||||
/// </summary>
|
||||
/// <param name="mutex">The mutex to destroy</param>
|
||||
KINC_FUNC void kinc_mutex_destroy(kinc_mutex_t *mutex);
|
||||
|
||||
/// <summary>
|
||||
/// Locks a mutex. A mutex can only be locked from one thread - when other threads attempt to lock the mutex the function will only return once the mutex has
|
||||
/// been unlocked.
|
||||
/// </summary>
|
||||
/// <param name="mutex">The mutex to lock</param>
|
||||
KINC_FUNC void kinc_mutex_lock(kinc_mutex_t *mutex);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to lock the mutex which will only succeed if no other thread currently holds the lock.
|
||||
/// </summary>
|
||||
/// <param name="mutex">The mutex to lock</param>
|
||||
/// <returns>Whether the mutex could be locked</returns>
|
||||
KINC_FUNC bool kinc_mutex_try_to_lock(kinc_mutex_t *mutex);
|
||||
|
||||
/// <summary>
|
||||
/// Unlocks the mutex which then allows other threads to lock it.
|
||||
/// </summary>
|
||||
/// <param name="mutex">The mutex to unlock</param>
|
||||
KINC_FUNC void kinc_mutex_unlock(kinc_mutex_t *mutex);
|
||||
|
||||
typedef struct kinc_uber_mutex {
|
||||
kinc_uber_mutex_impl_t impl;
|
||||
} kinc_uber_mutex_t;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes an uber-mutex-object.
|
||||
/// </summary>
|
||||
/// <param name="mutex">The uber-mutex to initialize</param>
|
||||
/// <param name="name">A name assigned to the uber-mutex - uber-mutex-creation fails if an uber-mutex of that name already exists</param>
|
||||
/// <returns>Whether the uber-mutex could be created</returns>
|
||||
KINC_FUNC bool kinc_uber_mutex_init(kinc_uber_mutex_t *mutex, const char *name);
|
||||
|
||||
/// <summary>
|
||||
/// Destroys an uber-mutex-obejct.
|
||||
/// </summary>
|
||||
/// <param name="mutex">The uber-mutex to destroy</param>
|
||||
KINC_FUNC void kinc_uber_mutex_destroy(kinc_uber_mutex_t *mutex);
|
||||
|
||||
/// <summary>
|
||||
/// Locks an uber-mutex.
|
||||
/// </summary>
|
||||
/// <param name="mutex">The uber-mutex to lock</param>
|
||||
KINC_FUNC void kinc_uber_mutex_lock(kinc_uber_mutex_t *mutex);
|
||||
|
||||
/// <summary>
|
||||
/// Unlocks an uber-mutex.
|
||||
/// </summary>
|
||||
/// <param name="mutex">The uber-mutex to unlock</param>
|
||||
/// <returns></returns>
|
||||
KINC_FUNC void kinc_uber_mutex_unlock(kinc_uber_mutex_t *mutex);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
58
Kha/Kinc/Sources/kinc/threads/semaphore.h
Normal file
58
Kha/Kinc/Sources/kinc/threads/semaphore.h
Normal file
@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include <kinc/global.h>
|
||||
|
||||
#include <kinc/backend/semaphore.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
/*! \file semaphore.h
|
||||
\brief A semaphore is a fancier version of an event that includes a counter to control how many threads are allowed to work on a task.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct kinc_semaphore {
|
||||
kinc_semaphore_impl_t impl;
|
||||
} kinc_semaphore_t;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a semaphore.
|
||||
/// </summary>
|
||||
/// <param name="semaphore">The semaphore to initialize</param>
|
||||
/// <param name="current">The current count of the semaphore</param>
|
||||
/// <param name="max">The maximum allowed count of the semaphore</param>
|
||||
KINC_FUNC void kinc_semaphore_init(kinc_semaphore_t *semaphore, int current, int max);
|
||||
|
||||
/// <summary>
|
||||
/// Destroys a semaphore.
|
||||
/// </summary>
|
||||
/// <param name="semaphore">The semaphore to destroy</param>
|
||||
KINC_FUNC void kinc_semaphore_destroy(kinc_semaphore_t *semaphore);
|
||||
|
||||
/// <summary>
|
||||
/// Increases the current count of the semaphore, therefore allowing more acquires to succeed.
|
||||
/// </summary>
|
||||
/// <param name="semaphore">The semaphore to increase the count on</param>
|
||||
/// <param name="count">The amount by which the count will be increased</param>
|
||||
KINC_FUNC void kinc_semaphore_release(kinc_semaphore_t *semaphore, int count);
|
||||
|
||||
/// <summary>
|
||||
/// Decreases the count of the semaphore by one. Blocks until it is possible to decrease the count if it already reached zero.
|
||||
/// </summary>
|
||||
/// <param name="semaphore">The semaphore to acquire</param>
|
||||
KINC_FUNC void kinc_semaphore_acquire(kinc_semaphore_t *semaphore);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to decrease the count of the semaphore by one.
|
||||
/// </summary>
|
||||
/// <param name="semaphore">The semaphore to acquire</param>
|
||||
/// <param name="timeout">The timeout in seconds after which the function returns if the semaphore-count could not be decreased</param>
|
||||
/// <returns>Whether the semaphore-count could be decreased</returns>
|
||||
KINC_FUNC bool kinc_semaphore_try_to_acquire(kinc_semaphore_t *semaphore, double timeout);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
66
Kha/Kinc/Sources/kinc/threads/thread.h
Normal file
66
Kha/Kinc/Sources/kinc/threads/thread.h
Normal file
@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
#include <kinc/global.h>
|
||||
|
||||
#include <kinc/backend/thread.h>
|
||||
|
||||
/*! \file thread.h
|
||||
\brief Supports the creation and destruction of threads.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct kinc_thread {
|
||||
kinc_thread_impl_t impl;
|
||||
} kinc_thread_t;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the threading system. This has to be called before calling any kinc_thread functions.
|
||||
/// </summary>
|
||||
KINC_FUNC void kinc_threads_init(void);
|
||||
|
||||
/// <summary>
|
||||
/// Shuts down the threading system.
|
||||
/// </summary>
|
||||
/// <param name=""></param>
|
||||
/// <returns></returns>
|
||||
KINC_FUNC void kinc_threads_quit(void);
|
||||
|
||||
/// <summary>
|
||||
/// Starts a thread via the provided function.
|
||||
/// </summary>
|
||||
/// <param name="thread">The thread-object to initialize with the new thread</param>
|
||||
/// <param name="func">The function used to start a new thread</param>
|
||||
/// <param name="param">A parameter that is passed to the thread-function when the thread starts running</param>
|
||||
KINC_FUNC void kinc_thread_init(kinc_thread_t *thread, void (*func)(void *param), void *param);
|
||||
|
||||
/// <summary>
|
||||
/// Waits for the thread to complete execution and then destroys it.
|
||||
/// </summary>
|
||||
/// <param name="thread">The thread to destroy</param>
|
||||
KINC_FUNC void kinc_thread_wait_and_destroy(kinc_thread_t *thread);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to destroy a thread.
|
||||
/// </summary>
|
||||
/// <param name="thread">The thread to destroy</param>
|
||||
/// <returns>Returns if the thread is still running and therefore couldn't be destroyed</returns>
|
||||
KINC_FUNC bool kinc_thread_try_to_destroy(kinc_thread_t *thread);
|
||||
|
||||
/// <summary>
|
||||
/// Assigns a name to the current thread which will then show up in debuggers and profilers.
|
||||
/// </summary>
|
||||
/// <param name="name">The name to assign to the thread</param>
|
||||
KINC_FUNC void kinc_thread_set_name(const char *name);
|
||||
|
||||
/// <summary>
|
||||
/// Puts the current thread to sleep.
|
||||
/// </summary>
|
||||
/// <param name="milliseconds">How long to sleep</param>
|
||||
KINC_FUNC void kinc_thread_sleep(int milliseconds);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
46
Kha/Kinc/Sources/kinc/threads/threadlocal.h
Normal file
46
Kha/Kinc/Sources/kinc/threads/threadlocal.h
Normal file
@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include <kinc/global.h>
|
||||
|
||||
#include <kinc/backend/threadlocal.h>
|
||||
|
||||
/*! \file threadlocal.h
|
||||
\brief Provides storage-slots for thread-specific data.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct kinc_thread_local {
|
||||
kinc_thread_local_impl_t impl;
|
||||
} kinc_thread_local_t;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a thread-specific storage-slot.
|
||||
/// </summary>
|
||||
/// <param name="local">The storage-slot to initialize</param>
|
||||
KINC_FUNC void kinc_thread_local_init(kinc_thread_local_t *local);
|
||||
|
||||
/// <summary>
|
||||
/// Destroys a storage-slot.
|
||||
/// </summary>
|
||||
/// <param name="local">The storage-slot to destroy</param>
|
||||
KINC_FUNC void kinc_thread_local_destroy(kinc_thread_local_t *local);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the data in the storage-slot.
|
||||
/// </summary>
|
||||
/// <param name="local">The slot to query</param>
|
||||
KINC_FUNC void *kinc_thread_local_get(kinc_thread_local_t *local);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the data in the storage-slot.
|
||||
/// </summary>
|
||||
/// <param name="local">The slot to put the data into</param>
|
||||
/// <param name="data">The data to put in the slot</param>
|
||||
KINC_FUNC void kinc_thread_local_set(kinc_thread_local_t *local, void *data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user