98#define PRIO_DEFAULT 10
105#define KTHREAD_LABEL_SIZE 256
112#define KTHREAD_PWD_SIZE 256
118TAILQ_HEAD(ktqueue, kthread);
130#define THD_DEFAULTS 0
133#define THD_DETACHED 4
134#define THD_OWNS_STACK 8
144typedef enum kthread_state {
158typedef struct tcbhead {
169typedef __attribute__((aligned(32))) struct kthread {
216 void (*wait_callback)(
void *obj);
254 struct _reent thd_reent;
260 struct kthread_tls_kv_list tls_list;
284typedef struct kthread_attr {
310typedef enum kthread_mode {
426 void *(*routine)(
void *param),
void *param);
770void thd_shutdown(
void);
Definitions for builtin attributes and compiler directives.
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.
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.
void thd_schedule(bool front_of_line, uint64_t now)
Force a thread reschedule.
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(kthread_t *thd)
Retrieve 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.
#define KTHREAD_LABEL_SIZE
Size of a kthread's label.
Definition thread.h:105
kthread_state_t
Kernel thread state.
Definition thread.h:144
int thd_join(kthread_t *thd, void **value_ptr)
Wait for a thread to exit.
kthread_mode_t
kthread mode values
Definition thread.h:310
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.
void thd_sleep(unsigned ms)
Sleep for a given number of milliseconds.
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:138
void thd_set_pwd(kthread_t *thd, const char *__RESTRICT pwd)
Set the thread's current working directory.
const char * thd_get_label(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.
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:112
void thd_pass(void)
Throw away the current thread's timeslice.
void thd_set_label(kthread_t *thd, const char *__RESTRICT label)
Set the thread's label.
@ STATE_READY
Ready to be scheduled.
Definition thread.h:147
@ STATE_FINISHED
Finished execution.
Definition thread.h:149
@ STATE_WAIT
Blocked on a genwait.
Definition thread.h:148
@ STATE_RUNNING
Process is "current".
Definition thread.h:146
@ STATE_ZOMBIE
Waiting to die.
Definition thread.h:145
@ THD_MODE_NONE
Threads not running.
Definition thread.h:311
@ THD_MODE_PREEMPT
Preemptive threading mode.
Definition thread.h:313
@ THD_MODE_COOP
Cooperative mode.
Definition thread.h:312
#define __RESTRICT
Definition cdefs.h:176
#define __deprecated
Mark something as deprecated.
Definition cdefs.h:109
#define __noreturn
Identify a function that will never return.
Definition cdefs.h:45
typedef LIST_HEAD(nmmgr_list, nmmgr_handler) nmmgr_list_t
Name handler list type.
handle_t prio_t
Priority value type.
Definition types.h:86
handle_t tid_t
Thread ID type.
Definition types.h:85
Interrupt and exception handling.
Architecture-specific structure for holding the processor state.
Definition irq.h:86
Thread creation attributes.
Definition thread.h:284
prio_t prio
Set the thread's priority.
Definition thread.h:296
void * stack_ptr
Pre-allocate a stack for the thread.
Definition thread.h:293
const char * label
Thread label.
Definition thread.h:299
bool create_detached
1 for a detached thread.
Definition thread.h:286
size_t stack_size
Set the size of the stack to be created.
Definition thread.h:289
Structure describing one running thread.
Definition thread.h:169
irq_context_t context
Register store – used to save thread context.
Definition thread.h:171
tid_t tid
Kernel thread id.
Definition thread.h:183
kthread_flags_t flags
Thread flags.
Definition thread.h:192
int thd_errno
Thread errno variable.
Definition thread.h:251
uint64_t wait_timeout
Next scheduled time.
Definition thread.h:224
uint64_t scheduled
time when the thread became active
Definition thread.h:228
uint64_t total
total running CPU time for thread
Definition thread.h:229
kthread_state_t state
Process state.
Definition thread.h:195
void * stack
Thread private stack.
Definition thread.h:245
void * rv
Return value of the thread function.
Definition thread.h:269
void * wait_obj
Generic wait target, if waiting.
Definition thread.h:201
TAILQ_ENTRY(kthread) timerq
Timer queue handle (if applicable).
tcbhead_t * tcbhead
Compiler-level thread-local storage.
Definition thread.h:263
prio_t prio
Dynamic priority.
Definition thread.h:186
LIST_ENTRY(kthread) t_list
Thread list handle.
TAILQ_ENTRY(kthread) thdq
Run/Wait queue handle.
const char * wait_msg
Generic wait message, if waiting.
Definition thread.h:207
prio_t real_prio
Static priority: 0..PRIO_MAX (higher means lower priority).
Definition thread.h:189
size_t stack_size
Size of the thread's stack, in bytes.
Definition thread.h:248
Thread Control Block Header.
Definition thread.h:158
void * dtv
Dynamic TLS vector (unused)
Definition thread.h:159
uintptr_t pointer_guard
Pointer guard (unused)
Definition thread.h:160
Thread-local storage support.