MOS Source Code
Loading...
Searching...
No Matches
kthread.c
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
4
6#include <mos/syslog/printk.h>
7#include <mos/tasks/kthread.h>
8#include <mos/tasks/process.h>
10#include <mos/tasks/thread.h>
11#include <mos_stdlib.h>
12
14
15typedef struct kthread_arg
16{
18 void *arg;
20
21static void kthread_entry(void *arg)
22{
23 kthread_arg_t *kthread_arg = arg;
24 kthread_arg->entry(kthread_arg->arg);
25 kfree(kthread_arg);
27}
28
29void kthread_init(void)
30{
31 kthreadd = process_allocate(NULL, "kthreadd");
32 MOS_ASSERT_X(kthreadd->pid == 2, "kthreadd should have pid 2");
34}
35
36thread_t *kthread_create(thread_entry_t entry, void *arg, const char *name)
37{
38 thread_t *thread = kthread_create_no_sched(entry, arg, name);
40 return thread;
41}
42
43thread_t *kthread_create_no_sched(thread_entry_t entry, void *arg, const char *name)
44{
45 MOS_ASSERT_X(kthreadd, "kthreadd not initialized");
46 pr_dinfo2(thread, "creating kernel thread '%s'", name);
47 kthread_arg_t *kthread_arg = kmalloc(sizeof(kthread_arg_t));
48 kthread_arg->entry = entry;
49 kthread_arg->arg = arg;
53 return thread;
54}
#define MOS_ASSERT_X(cond, msg,...)
Definition assert.h:15
MOSAPI void * hashmap_put(hashmap_t *map, uintn key, void *value)
Definition hashmap.c:68
@ THREAD_MODE_KERNEL
Definition task_types.h:21
void define_syscall thread_exit(void)
Definition ksyscall.c:170
thread_t * kthread_create_no_sched(thread_entry_t entry, void *arg, const char *name)
Create a kernel thread, but do not add it to the scheduler.
Definition kthread.c:43
static process_t * kthreadd
Definition kthread.c:13
thread_t * kthread_create(thread_entry_t entry, void *arg, const char *name)
Create a kernel-mode thread.
Definition kthread.c:36
static void kthread_entry(void *arg)
Definition kthread.c:21
void kthread_init(void)
Definition kthread.c:29
#define NULL
Definition pb_syshdr.h:46
#define current_thread
Definition platform.h:30
#define pr_dinfo2(feat, fmt,...)
Definition printk.h:27
hashmap_t process_table
Definition process.c:34
process_t * process_allocate(process_t *parent, const char *name)
Definition process.c:55
void platform_context_setup_child_thread(thread_t *thread, thread_entry_t entry, void *arg)
void scheduler_add_thread(thread_t *thread)
Add a thread to the scheduler, so that it can be scheduled.
Definition schedule.c:78
const char * name
Definition slab.c:31
thread_entry_t entry
Definition kthread.c:17
void * arg
Definition kthread.c:18
pid_t pid
Definition task_types.h:45
thread_t * thread_complete_init(thread_t *thread)
Definition thread.c:156
thread_t * thread_new(process_t *owner, thread_mode mode, const char *name, size_t stack_size, void *stack)
Definition thread.c:77
void(* thread_entry_t)(void *arg)
Definition types.h:109