99#define PRIO_DEFAULT 10
106#define KTHREAD_LABEL_SIZE 256
113#define KTHREAD_PWD_SIZE 256
119TAILQ_HEAD(ktqueue, kthread);
131#define THD_DEFAULTS 0x0
133#define THD_QUEUED 0x2
134#define THD_DETACHED 0x4
135#define THD_OWNS_STACK 0x8
136#define THD_DISABLE_TLS 0x10
146typedef enum kthread_state {
164typedef __attribute__((aligned(32))) struct kthread {
211 void (*wait_callback)(
void *obj);
249 struct _reent thd_reent;
255 struct kthread_tls_kv_list tls_list;
279typedef struct kthread_attr {
308typedef enum kthread_mode {
424 void *(*routine)(
void *param),
void *param);
803void thd_shutdown(
void);
Various common macros used throughout the codebase.
irq_context_t * thd_choose_new(void)
Find a new thread to swap in.
kthread_mode_t thd_get_mode(void) __deprecated
Fetch the current threading mode.
int thd_set_hz(unsigned int hertz)
Set the scheduler's frequency.
int thd_each(int(*cb)(kthread_t *thd, void *user_data), void *data)
Iterate all threads and call the passed callback for each.
tid_t thd_get_id(const kthread_t *thd)
Retrieve a thread's numeric identifier.
void thd_exit(void *rv) __noreturn
Exit the current thread.
int thd_remove_from_runnable(kthread_t *thd)
Removes a thread from the runnable queue, if it's there.
int prio_t
Priority value type.
Definition thread.h:156
uint64_t thd_get_total_cpu_time(void)
Retrieves all thread's elapsed CPU time.
struct _reent * thd_get_reent(kthread_t *thd)
Retrieve a pointer to the thread reent struct.
int thd_destroy(kthread_t *thd)
Brutally kill the given thread.
int thd_block_now(irq_context_t *mycxt)
Block the current thread.
unsigned thd_get_hz(void)
Fetch the scheduler's current frequency.
uint64_t thd_get_cpu_time(kthread_t *thd)
Retrieves the thread's elapsed CPU time.
const char * thd_get_pwd(const kthread_t *thd)
Retrieve the thread's current working directory.
void thd_set_pwd(kthread_t *__RESTRICT thd, const char *__RESTRICT pwd)
Set the thread's current working directory.
void thd_add_to_runnable(kthread_t *t, bool front_of_line)
Enqueue a process in the runnable queue.
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.
void thd_schedule_next(kthread_t *thd)
Force a given thread to the front of the queue.
kthread_t * thd_create(bool detach, void *(*routine)(void *param), void *param)
Create a new thread.
int tid_t
Thread ID type.
Definition thread.h:155
void thd_set_label(kthread_t *__RESTRICT thd, const char *__RESTRICT label)
Set the thread's label.
#define KTHREAD_LABEL_SIZE
Size of a kthread's label.
Definition thread.h:106
kthread_state_t
Kernel thread state.
Definition thread.h:146
int thd_join(kthread_t *thd, void **value_ptr)
Wait for a thread to exit.
kthread_mode_t
kthread mode values
Definition thread.h:308
int * thd_get_errno(kthread_t *thd)
Retrieve a pointer to the thread errno.
kthread_t * thd_by_tid(tid_t tid)
Given a thread ID, locates the thread structure.
kthread_t * thd_get_current(void)
Retrieve the current thread's kthread struct.
uint8_t kthread_flags_t
Kernel thread flags type.
Definition thread.h:140
const char * thd_get_label(const kthread_t *thd)
Retrieve the thread's label.
kthread_t * thd_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_pslist_queue(int(*pf)(const char *fmt,...))
Print a list of all queued threads using the given print function.
prio_t thd_get_prio(const kthread_t *thd)
Retrieve a thread's priority value.
int thd_pslist(int(*pf)(const char *fmt,...))
Print a list of all threads using the given print function.
int thd_set_mode(kthread_mode_t mode) __deprecated
Change threading modes.
#define KTHREAD_PWD_SIZE
Size of a kthread's current directory.
Definition thread.h:113
void thd_schedule(bool front_of_line)
Force a thread reschedule.
void thd_pass(void)
Throw away the current thread's timeslice.
@ STATE_READY
Ready to be scheduled.
Definition thread.h:149
@ STATE_FINISHED
Finished execution.
Definition thread.h:151
@ STATE_WAIT
Blocked on a genwait.
Definition thread.h:150
@ STATE_RUNNING
Process is "current".
Definition thread.h:148
@ STATE_ZOMBIE
Waiting to die.
Definition thread.h:147
@ THD_MODE_NONE
Threads not running.
Definition thread.h:309
@ THD_MODE_PREEMPT
Preemptive threading mode.
Definition thread.h:311
@ THD_MODE_COOP
Cooperative mode.
Definition thread.h:310
#define __deprecated
Mark something as deprecated.
Definition cdefs.h:56
#define __noreturn
Identify a function that will never return.
Definition cdefs.h:49
#define __RESTRICT
Definition cdefs.h:98
typedef LIST_HEAD(nmmgr_list, nmmgr_handler) nmmgr_list_t
Name handler list type.
Do not use use thd_sleep() instead") static inline void timer_spin_sleep(unsigned int ms)
Definition timer.h:202
Interrupt and exception handling.
Architecture-specific structure for holding the processor state.
Definition irq.h:91
Thread creation attributes.
Definition thread.h:279
prio_t prio
Set the thread's priority.
Definition thread.h:291
void * stack_ptr
Pre-allocate a stack for the thread.
Definition thread.h:288
const char * label
Thread label.
Definition thread.h:294
bool create_detached
1 for a detached thread.
Definition thread.h:281
size_t stack_size
Set the size of the stack to be created.
Definition thread.h:284
bool disable_tls
1 if the thread doesn't use thread_local variables.
Definition thread.h:297
Structure describing one running thread.
Definition thread.h:164
irq_context_t context
Register store – used to save thread context.
Definition thread.h:166
tid_t tid
Kernel thread id.
Definition thread.h:178
kthread_flags_t flags
Thread flags.
Definition thread.h:187
int thd_errno
Thread errno variable.
Definition thread.h:246
uint64_t wait_timeout
Next scheduled time.
Definition thread.h:219
uint64_t scheduled
time when the thread became active
Definition thread.h:223
uint64_t total
total running CPU time for thread
Definition thread.h:224
kthread_state_t state
Process state.
Definition thread.h:190
void * stack
Thread private stack.
Definition thread.h:240
void * rv
Return value of the thread function.
Definition thread.h:264
void * wait_obj
Generic wait target, if waiting.
Definition thread.h:196
TAILQ_ENTRY(kthread) timerq
Timer queue handle (if applicable).
prio_t prio
Dynamic priority.
Definition thread.h:181
LIST_ENTRY(kthread) t_list
Thread list handle.
void * tls_hnd
Compiler-level thread-local storage.
Definition thread.h:258
TAILQ_ENTRY(kthread) thdq
Run/Wait queue handle.
const char * wait_msg
Generic wait message, if waiting.
Definition thread.h:202
prio_t real_prio
Static priority: 0..PRIO_MAX (higher means lower priority).
Definition thread.h:184
size_t stack_size
Size of the thread's stack, in bytes.
Definition thread.h:243
Thread-local storage support.