10 #define __KOS_THREAD_H
12 #include <sys/cdefs.h>
19 #include <sys/queue.h>
20 #include <sys/reent.h>
72 #define PRIO_DEFAULT 10
176 #define THD_DEFAULTS 0
179 #define THD_DETACHED 4
188 #define STATE_ZOMBIE 0x0000
189 #define STATE_RUNNING 0x0001
190 #define STATE_READY 0x0002
191 #define STATE_WAIT 0x0003
192 #define STATE_FINISHED 0x0004
212 #define THD_MODE_NONE -1
213 #define THD_MODE_COOP 0
214 #define THD_MODE_PREEMPT 1
503 int thd_pslist(
int (*pf)(
const char *fmt, ...));
Thread-local storage support.
vuint32 jiffies
"Jiffy" count.
char pwd[256]
Current file system path.
Definition: thread.h:142
tid_t tid
Kernel thread id.
Definition: thread.h:101
void thd_add_to_runnable(kthread_t *t, int front_of_line)
Enqueue a process in the runnable queue.
typedef LIST_HEAD(nmmgr_list, nmmgr_handler) nmmgr_list_t
Name handler list type.
void * wait_obj
Generic wait target, if waiting.
Definition: thread.h:116
kthread_t * thd_get_current()
Retrieve the current thread's kthread struct.
struct kthread_tls_kv_list tls_list
Thread-local storage.
Definition: thread.h:162
void thd_set_label(kthread_t *thd, const char *label)
Set the thread's label.
void thd_schedule(int front_of_line, uint64 now)
Force a thread reschedule.
void thd_pass()
Throw away the current thread's timeslice.
void thd_set_pwd(kthread_t *thd, const char *pwd)
Set the thread's current working directory.
int thd_block_now(irq_context_t *mycxt)
Block the current thread.
char label[256]
Thread label. This value is used when printing out a user-readable process listing.
Definition: thread.h:139
prio_t prio
Static priority: 0..PRIO_MAX (higher means lower priority).
Definition: thread.h:104
Architecture-specific structure for holding the processor state.
Definition: irq.h:46
handle_t tid_t
Thread ID type.
Definition: types.h:80
int thd_set_mode(int mode)
Change threading modes.
const char * wait_msg
Generic wait message, if waiting.
Definition: thread.h:120
struct _reent thd_reent
Our reent struct for newlib.
Definition: thread.h:158
int thd_detach(kthread_t *thd)
Detach a joinable thread.
int thd_set_prio(kthread_t *thd, prio_t prio)
Set a thread's priority value.
unsigned long long uint64
64-bit unsigned integer
Definition: types.h:27
void * rv
Return value of the thread function. This is only used in joinable threads.
Definition: thread.h:166
int * thd_get_errno(kthread_t *thd)
Retrieve a pointer to the thread errno.
volatile uint32 vuint32
32-bit volatile unsigned type
Definition: types.h:38
void thd_schedule_next(kthread_t *thd)
Force a given thread to the front of the queue.
uint32 stack_size
Size of the thread's stack, in bytes.
Definition: thread.h:152
int thd_destroy(kthread_t *thd)
Brutally kill the given thread.
int thd_join(kthread_t *thd, void **value_ptr)
Wait for a thread to exit.
kthread_t * thd_by_tid(tid_t tid)
Given a thread ID, locates the thread structure.
int thd_pslist(int(*pf)(const char *fmt,...))
Print a list of all threads using the given print function.
void(* wait_callback)(void *obj)
Wait timeout callback.
Definition: thread.h:129
struct kthread kthread_t
Structure describing one running thread.
unsigned long uint32
32-bit unsigned integer
Definition: types.h:28
uint64 wait_timeout
Next scheduled time. This value is used for sleep and timed block operations. This value is in millis...
Definition: thread.h:135
void thd_exit(void *rv) __noreturn
Exit the current thread.
LIST_ENTRY(kthread) t_list
Thread list handle. Not a function.
Structure describing one running thread.
Definition: thread.h:90
const char * thd_get_pwd(kthread_t *thd)
Retrieve the thread's current working directory.
irq_context_t context
Register store – used to save thread context.
Definition: thread.h:145
int thd_remove_from_runnable(kthread_t *thd)
Removes a thread from the runnable queue, if it's there.
kthread_t * thd_current
The currently executing thread.
int state
Process state.
Definition: thread.h:112
kthread_t * thd_create(int detach, void *(*routine)(void *param), void *param)
Create a new thread.
#define __noreturn
Identify a function that will never return.
Definition: cdefs.h:37
uint32 flags
Thread flags.
Definition: thread.h:108
Dreamcast architecture specific options.
irq_context_t * thd_choose_new()
Find a new thread to swap in.
TAILQ_ENTRY(kthread) thdq
Run/Wait queue handle. Once again, not a function.
void thd_sleep(int ms)
Sleep for a given number of milliseconds.
Interrupt and exception handling.
const char * thd_get_label(kthread_t *thd)
Retrieve the thread's label.
int thd_errno
Thread errno variable.
Definition: thread.h:155
uint32 * stack
Thread private stack. This should be a pointer to the base of a stack page.
Definition: thread.h:149
struct _reent * thd_get_reent(kthread_t *thd)
Retrieve a pointer to the thread reent struct.
void thd_shutdown()
Shutdown the threading system.
handle_t prio_t
Priority value type.
Definition: types.h:81
int thd_mode
Are threads cooperative or preemptive?
int thd_pslist_queue(int(*pf)(const char *fmt,...))
Print a list of all queued threads using the given print function.
int thd_init(int mode)
Initialize the threading system.