Kohi Game Engine
kthread.h File Reference
#include "defines.h"

Go to the source code of this file.

Data Structures

struct  kthread
 

Typedefs

typedef struct kthread kthread
 
typedef u32(* pfn_thread_start) (void *)
 

Functions

KAPI b8 kthread_create (pfn_thread_start start_function_ptr, void *params, b8 auto_detach, kthread *out_thread)
 
KAPI void kthread_destroy (kthread *thread)
 
KAPI void kthread_detach (kthread *thread)
 
KAPI void kthread_cancel (kthread *thread)
 
KAPI b8 kthread_is_active (kthread *thread)
 
KAPI void kthread_sleep (kthread *thread, u64 ms)
 
KAPI u64 platform_current_thread_id (void)
 Obtains the identifier for the current thread. More...
 

Typedef Documentation

◆ kthread

typedef struct kthread kthread

Represents a process thread in the system to be used for work. Generally should not be created directly in user code. This calls to the platform-specific thread implementation.

◆ pfn_thread_start

typedef u32(* pfn_thread_start) (void *)

Function Documentation

◆ kthread_cancel()

KAPI void kthread_cancel ( kthread thread)

Cancels work on the thread, if possible, and releases resources when possible.

◆ kthread_create()

KAPI b8 kthread_create ( pfn_thread_start  start_function_ptr,
void *  params,
b8  auto_detach,
kthread out_thread 
)

Creates a new thread, immediately calling the function pointed to.

Parameters
start_function_ptrThe pointer to the function to be invoked immediately. Required.
paramsA pointer to any data to be passed to the start_function_ptr. Optional. Pass 0/NULL if not used.
auto_detachIndicates if the thread should immediately release its resources when the work is complete. If true, out_thread is not set.
out_threadA pointer to hold the created thread, if auto_detach is false.
Returns
true if successfully created; otherwise false.

◆ kthread_destroy()

KAPI void kthread_destroy ( kthread thread)

Destroys the given thread.

◆ kthread_detach()

KAPI void kthread_detach ( kthread thread)

Detaches the thread, automatically releasing resources when work is complete.

◆ kthread_is_active()

KAPI b8 kthread_is_active ( kthread thread)

Indicates if the thread is currently active.

Returns
True if active; otherwise false.

◆ kthread_sleep()

KAPI void kthread_sleep ( kthread thread,
u64  ms 
)

Sleeps on the given thread for a given number of milliseconds. Should be called from the thread requiring the sleep.

◆ platform_current_thread_id()

KAPI u64 platform_current_thread_id ( void  )

Obtains the identifier for the current thread.