KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
kthread_t Struct Reference

Structure describing one running thread. More...

#include <thread.h>

Public Member Functions

 LIST_ENTRY (kthread) t_list
 Thread list handle.
 
 TAILQ_ENTRY (kthread) thdq
 Run/Wait queue handle.
 
 TAILQ_ENTRY (kthread) timerq
 Timer queue handle (if applicable).
 

Data Fields

irq_context_t context
 Register store – used to save thread context.
 
tid_t tid
 Kernel thread id.
 
prio_t prio
 Dynamic priority.
 
prio_t real_prio
 Static priority: 0..PRIO_MAX (higher means lower priority).
 
kthread_flags_t flags
 Thread flags.
 
kthread_state_t state
 Process state.
 
void * wait_obj
 Generic wait target, if waiting.
 
const char * wait_msg
 Generic wait message, if waiting.
 
void(* wait_callback )(void *obj)
 Wait timeout callback.
 
uint64_t wait_timeout
 Next scheduled time.
 
struct { 
 
   uint64_t   scheduled 
 time when the thread became active More...
 
   uint64_t   total 
 total running CPU time for thread More...
 
cpu_time 
 Per-Thread CPU Time.
 
char label [KTHREAD_LABEL_SIZE]
 Thread label.
 
char pwd [KTHREAD_PWD_SIZE]
 Current file system path.
 
void * stack
 Thread private stack.
 
size_t stack_size
 Size of the thread's stack, in bytes.
 
int thd_errno
 Thread errno variable.
 
struct _reent thd_reent
 Our reent struct for newlib.
 
struct kthread_tls_kv_list tls_list
 OS-level thread-local storage.
 
tcbhead_ttcbhead
 Compiler-level thread-local storage.
 
void * rv
 Return value of the thread function.
 

Related Symbols

(Note that these are not member symbols.)

kthread_tthd_by_tid (tid_t tid)
 Given a thread ID, locates the thread structure.
 
void thd_add_to_runnable (kthread_t *t, bool front_of_line)
 Enqueue a process in the runnable queue.
 
int thd_remove_from_runnable (kthread_t *thd)
 Removes a thread from the runnable queue, if it's there.
 
kthread_tthd_create (bool detach, void *(*routine)(void *param), void *param)
 Create a new thread.
 
kthread_tthd_create_ex (const kthread_attr_t *__RESTRICT attr, void *(*routine)(void *param), void *param)
 Create a new thread with the specified set of attributes.
 
int thd_destroy (kthread_t *thd)
 Brutally kill the given thread.
 
void thd_schedule_next (kthread_t *thd)
 Force a given thread to the front of the queue.
 
int thd_set_prio (kthread_t *thd, prio_t prio)
 Set a thread's priority value.
 
kthread_tthd_get_current (void)
 Retrieve the current thread's kthread struct.
 
const char * thd_get_label (kthread_t *thd)
 Retrieve the thread's label.
 
void thd_set_label (kthread_t *thd, const char *__RESTRICT label)
 Set the thread's label.
 
const char * thd_get_pwd (kthread_t *thd)
 Retrieve the thread's current working directory.
 
void thd_set_pwd (kthread_t *thd, const char *__RESTRICT pwd)
 Set the thread's current working directory.
 
int * thd_get_errno (kthread_t *thd)
 Retrieve a pointer to the thread errno.
 
struct _reent * thd_get_reent (kthread_t *thd)
 Retrieve a pointer to the thread reent struct.
 
uint64_t thd_get_cpu_time (kthread_t *thd)
 Retrieves the thread's elapsed CPU time.
 
int thd_join (kthread_t *thd, void **value_ptr)
 Wait for a thread to exit.
 
int thd_detach (kthread_t *thd)
 Detach a joinable thread.
 
int thd_each (int(*cb)(kthread_t *thd, void *user_data), void *data)
 Iterate all threads and call the passed callback for each.
 

Detailed Description

Structure describing one running thread.

Each thread has one of these structures assigned to it, which holds all the data associated with the thread. There are various functions to manipulate the data in here, so you shouldn't generally do so manually.

Member Function Documentation

◆ LIST_ENTRY()

kthread_t::LIST_ENTRY ( kthread )

Thread list handle.

Not a function.

◆ TAILQ_ENTRY() [1/2]

kthread_t::TAILQ_ENTRY ( kthread )

Run/Wait queue handle.

Once again, not a function.

◆ TAILQ_ENTRY() [2/2]

kthread_t::TAILQ_ENTRY ( kthread )

Timer queue handle (if applicable).

Also not a function.

Field Documentation

◆ context

irq_context_t kthread_t::context

Register store – used to save thread context.

◆ [struct]

struct { ... } kthread_t::cpu_time

Per-Thread CPU Time.

◆ flags

kthread_flags_t kthread_t::flags

Thread flags.

◆ label

char kthread_t::label[KTHREAD_LABEL_SIZE]

Thread label.

This value is used when printing out a user-readable process listing.

◆ prio

prio_t kthread_t::prio

Dynamic priority.

◆ pwd

char kthread_t::pwd[KTHREAD_PWD_SIZE]

Current file system path.

◆ real_prio

prio_t kthread_t::real_prio

Static priority: 0..PRIO_MAX (higher means lower priority).

◆ rv

void* kthread_t::rv

Return value of the thread function.

This is only used in joinable threads.

◆ scheduled

uint64_t kthread_t::scheduled

time when the thread became active

◆ stack

void* kthread_t::stack

Thread private stack.

This should be a pointer to the base of a stack page.

◆ stack_size

size_t kthread_t::stack_size

Size of the thread's stack, in bytes.

◆ state

kthread_state_t kthread_t::state

Process state.

◆ tcbhead

tcbhead_t* kthread_t::tcbhead

Compiler-level thread-local storage.

◆ thd_errno

int kthread_t::thd_errno

Thread errno variable.

◆ thd_reent

struct _reent kthread_t::thd_reent

Our reent struct for newlib.

◆ tid

tid_t kthread_t::tid

Kernel thread id.

◆ tls_list

struct kthread_tls_kv_list kthread_t::tls_list

OS-level thread-local storage.

See also
kos/tls.h

◆ total

uint64_t kthread_t::total

total running CPU time for thread

◆ wait_callback

void(* kthread_t::wait_callback) (void *obj)

Wait timeout callback.

If the genwait times out while waiting, this function will be called. This allows hooks for things like fixing up semaphore count values, etc.

Parameters
objThe object that we were waiting on.

◆ wait_msg

const char* kthread_t::wait_msg

Generic wait message, if waiting.

See also
kos/genwait.h

◆ wait_obj

void* kthread_t::wait_obj

Generic wait target, if waiting.

See also
kos/genwait.h

◆ wait_timeout

uint64_t kthread_t::wait_timeout

Next scheduled time.

This value is used for sleep and timed block operations. This value is in milliseconds since the start of timer_ms_gettime(). This should be enough for something like 2 million years of wait time. ;)


The documentation for this struct was generated from the following file: