2002-07-09 16:24:59 +04:00
|
|
|
/*
|
|
|
|
** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
|
|
|
|
** Distributed under the terms of the NewOS License.
|
|
|
|
*/
|
|
|
|
#ifndef _THREAD_H
|
|
|
|
#define _THREAD_H
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <thread_types.h>
|
|
|
|
#include <arch/thread.h>
|
|
|
|
|
2002-08-16 17:14:29 +04:00
|
|
|
// Uncomment the line below to compile the single-queue scheduler
|
|
|
|
//#define NEW_SCHEDULER
|
|
|
|
|
2002-08-04 03:39:50 +04:00
|
|
|
void resched(void);
|
|
|
|
void start_scheduler(void);
|
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
void thread_enqueue(struct thread *t, struct thread_queue *q);
|
|
|
|
struct thread *thread_lookat_queue(struct thread_queue *q);
|
|
|
|
struct thread *thread_dequeue(struct thread_queue *q);
|
|
|
|
struct thread *thread_dequeue_id(struct thread_queue *q, thread_id thr_id);
|
2002-08-16 17:14:29 +04:00
|
|
|
#ifndef NEW_SCHEDULER
|
2002-07-09 16:24:59 +04:00
|
|
|
struct thread *thread_lookat_run_q(int priority);
|
2002-08-16 17:14:29 +04:00
|
|
|
#endif /* not NEW_SCHEDULER */
|
2002-07-09 16:24:59 +04:00
|
|
|
void thread_enqueue_run_q(struct thread *t);
|
2002-08-16 17:14:29 +04:00
|
|
|
#ifndef NEW_SCHEDULER
|
2002-07-09 16:24:59 +04:00
|
|
|
struct thread *thread_dequeue_run_q(int priority);
|
2002-08-16 17:14:29 +04:00
|
|
|
#endif /* not NEW_SCHEDULER */
|
2002-07-09 16:24:59 +04:00
|
|
|
void thread_atkernel_entry(void); // called when the thread enters the kernel on behalf of the thread
|
|
|
|
void thread_atkernel_exit(void);
|
|
|
|
|
|
|
|
int thread_suspend_thread(thread_id id);
|
|
|
|
int thread_resume_thread(thread_id id);
|
2002-08-16 17:14:29 +04:00
|
|
|
#ifndef NEW_SCHEDULER
|
2002-07-09 16:24:59 +04:00
|
|
|
int thread_set_priority(thread_id id, int priority);
|
2002-08-16 17:14:29 +04:00
|
|
|
#else /* NEW_SCHEDULER */
|
|
|
|
status_t thread_set_priority(thread_id id, int32 priority);
|
|
|
|
#endif /* NEW_SCHEDULER */
|
2002-07-09 16:24:59 +04:00
|
|
|
int thread_init(kernel_args *ka);
|
|
|
|
int thread_init_percpu(int cpu_num);
|
|
|
|
void thread_exit(int retcode);
|
|
|
|
int thread_kill_thread(thread_id id);
|
|
|
|
int thread_kill_thread_nowait(thread_id id);
|
|
|
|
|
|
|
|
#define thread_get_current_thread arch_thread_get_current_thread
|
|
|
|
|
|
|
|
struct thread *thread_get_thread_struct(thread_id id);
|
2002-08-16 17:14:29 +04:00
|
|
|
#ifdef NEW_SCHEDULER
|
|
|
|
struct thread *thread_get_thread_struct_locked(thread_id id);
|
|
|
|
#endif /* NEW_SCHEDULER */
|
2002-07-09 16:24:59 +04:00
|
|
|
thread_id thread_get_current_thread_id(void);
|
|
|
|
|
|
|
|
extern inline thread_id thread_get_current_thread_id(void) {
|
|
|
|
struct thread *t = thread_get_current_thread(); return t ? t->id : 0;
|
|
|
|
}
|
|
|
|
int thread_wait_on_thread(thread_id id, int *retcode);
|
|
|
|
|
2002-08-03 04:41:27 +04:00
|
|
|
thread_id thread_create_user_thread(char *name, team_id tid, addr entry, void *args);
|
2002-07-09 16:24:59 +04:00
|
|
|
thread_id thread_create_kernel_thread(const char *name, int (*func)(void *args), void *args);
|
2002-08-04 03:39:50 +04:00
|
|
|
thread_id thread_create_kernel_thread_etc(const char *name, int (*func)(void *), void *args, struct team *p);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2002-08-04 03:39:50 +04:00
|
|
|
int team_init(kernel_args *ka);
|
2002-08-03 04:41:27 +04:00
|
|
|
struct team *team_get_kernel_team(void);
|
|
|
|
team_id team_create_team(const char *path, const char *name, char **args, int argc, char **envp, int envc, int priority);
|
|
|
|
int team_kill_team(team_id);
|
|
|
|
int team_wait_on_team(team_id id, int *retcode);
|
2002-08-04 03:39:50 +04:00
|
|
|
void team_remove_team_from_hash(struct team *team);
|
2002-08-03 04:41:27 +04:00
|
|
|
team_id team_get_kernel_team_id(void);
|
|
|
|
team_id team_get_current_team_id(void);
|
|
|
|
char **user_team_get_arguments(void);
|
|
|
|
int user_team_get_arg_count(void);
|
2002-08-04 06:04:37 +04:00
|
|
|
struct team *team_get_team_struct(team_id id);
|
2002-08-04 03:39:50 +04:00
|
|
|
struct team *team_get_team_struct_locked(team_id id);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
// used in syscalls.c
|
|
|
|
int user_thread_wait_on_thread(thread_id id, int *uretcode);
|
2002-08-03 04:41:27 +04:00
|
|
|
team_id user_team_create_team(const char *path, const char *name, char **args, int argc, char **envp, int envc, int priority);
|
|
|
|
int user_team_wait_on_team(team_id id, int *uretcode);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2002-08-03 04:41:27 +04:00
|
|
|
thread_id user_thread_create_user_thread(addr, team_id, const char*,
|
2002-07-09 16:24:59 +04:00
|
|
|
int, void *);
|
|
|
|
|
2002-08-19 12:28:39 +04:00
|
|
|
status_t user_send_data(thread_id thread, int32 code, const void *buffer, size_t buffer_size);
|
|
|
|
status_t user_receive_data(thread_id *sender, void *buffer, size_t buffer_size);
|
|
|
|
|
2002-08-04 06:04:37 +04:00
|
|
|
status_t user_get_thread_info(thread_id id, thread_info *info);
|
|
|
|
status_t user_get_next_thread_info(team_id team, int32 *cookie, thread_info *info);
|
2002-08-04 03:39:50 +04:00
|
|
|
status_t user_get_team_info(team_id id, team_info *info);
|
|
|
|
status_t user_get_next_team_info(int32 *cookie, team_info *info);
|
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
int user_getrlimit(int resource, struct rlimit * rlp);
|
|
|
|
int user_setrlimit(int resource, const struct rlimit * rlp);
|
|
|
|
|
2002-07-18 17:59:03 +04:00
|
|
|
int user_setenv(const char *name, const char *value, int overwrite);
|
|
|
|
int user_getenv(const char *name, char **value);
|
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
#if 1
|
|
|
|
// XXX remove later
|
|
|
|
int thread_test(void);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* _THREAD_H */
|