123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- #ifndef KERN_TASK_H
- #define KERN_TASK_H
- #include <stdint.h>
- #include <kern/atomic.h>
- #include <kern/bulletin.h>
- #include <kern/cspace_types.h>
- #include <kern/init.h>
- #include <kern/kuid.h>
- #include <kern/list.h>
- #include <kern/log.h>
- #include <kern/spinlock.h>
- #include <kern/stream.h>
- #include <kern/thread.h>
- #include <vm/map.h>
- #define TASK_NAME_SIZE 32
- struct task
- {
- struct kuid_head kuid;
- struct spinlock lock;
- struct list node;
- struct list threads;
- struct vm_map *map;
- struct cspace caps;
- struct bulletin dead_subs;
- char name[TASK_NAME_SIZE];
- };
- struct task_ipc_msg
- {
- uint32_t size;
- int op;
- union
- {
- char name[TASK_NAME_SIZE];
- int id;
- };
- };
- enum
- {
- TASK_IPC_GET_NAME,
- TASK_IPC_SET_NAME,
- TASK_IPC_GET_ID,
- };
- static inline struct task*
- task_get_kernel_task (void)
- {
- extern struct task task_kernel_task;
- return (&task_kernel_task);
- }
- static inline uint32_t
- task_get_kuid (const struct task *task)
- {
- return (task->kuid.id);
- }
- static inline void
- task_ref (struct task *task)
- {
- size_t nr_refs = atomic_add_rlx (&task->kuid.nr_refs, 1);
- assert (nr_refs != (size_t)-1);
- }
- void task_destroy (struct task *task);
- static inline void
- task_unref (struct task *task)
- {
- size_t nr_refs = atomic_sub_acq_rel (&task->kuid.nr_refs, 1);
- assert (nr_refs);
- if (nr_refs == 1)
- task_destroy (task);
- }
- static inline struct vm_map*
- task_get_vm_map (const struct task *task)
- {
- return (task->map);
- }
- static inline struct task*
- task_self (void)
- {
- return (thread_self()->xtask);
- }
- static inline int
- task_id (const struct task *task)
- {
- return ((int)task->kuid.id);
- }
- int task_create (struct task **taskp, const char *name);
- int task_create2 (struct task **taskp, const char *name, struct vm_map *map);
- struct task* task_lookup (const char *name);
- void task_add_thread (struct task *task, struct thread *thread);
- void task_remove_thread (struct task *task, struct thread *thread);
- struct thread* task_lookup_thread (struct task *task, const char *name);
- static inline struct task*
- task_by_kuid (uint32_t kuid)
- {
- return (kuid_find_type (kuid, struct task, kuid, KUID_TASK));
- }
- void task_info (struct task *task, struct stream *stream);
- struct cap_iters;
- struct ipc_msg_data;
- ssize_t task_handle_msg (struct task *task, struct cap_iters *src,
- struct cap_iters *dst, struct ipc_msg_data *data);
- INIT_OP_DECLARE (task_setup);
- #endif
|