1/*
2 * Copyright 2018, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5
6extern "C" {
7#include <sys/systm.h>
8#include <sys/kthread.h>
9}
10
11#include <thread.h>
12
13
14int
15kthread_add(void (*func)(void *), void *arg, void* p,
16	struct thread **newtdp, int flags, int pages, const char *fmt, ...)
17{
18	va_list ap;
19	char name[B_OS_NAME_LENGTH];
20	va_start(ap, fmt);
21	vsnprintf(name, sizeof(name), fmt, ap);
22	va_end(ap);
23
24	thread_id id = spawn_kernel_thread((status_t (*)(void *))func, /* HACK! */
25		name, B_NORMAL_PRIORITY, arg);
26	if (id < 0)
27		return id;
28	if (newtdp != NULL) {
29		intptr_t thread = id;
30		*newtdp = (struct thread*)thread;
31	}
32	return 0;
33}
34
35
36void
37sched_prio(struct thread* td, u_char prio)
38{
39	uintptr_t tdi = (uintptr_t)td;
40	set_thread_priority((thread_id)tdi, prio);
41}
42
43
44void
45sched_add(struct thread* td, int /* flags */)
46{
47	uintptr_t tdi = (uintptr_t)td;
48	resume_thread((thread_id)tdi);
49}
50
51
52void
53kthread_exit()
54{
55	thread_exit();
56}
57