00001
00002
00003 #ifndef _CORE_THREAD_THREAD_HPP
00004 #define _CORE_THREAD_THREAD_HPP
00005
00006
00007 #include "src/common/blist.hpp"
00008 #include "src/arch/x86/context.hpp"
00009 #include "src/arch/x86/interr.hpp"
00010 #include "src/arch/x86/except_c.hpp"
00011 #include "src/ipc/msg.hpp"
00012 #include "src/ipc/sem.hpp"
00013 #include "src/memory/pager.hpp"
00014
00015
00016
00017 struct threnv_t
00018 {
00019
00020
00021
00022 struct Arch::x86::Interr::except2_t *cd;
00023 };
00024
00025 namespace Thread {
00026
00027
00028
00029 const uint32 THREAD_NAME = 0x20;
00030 const uint32 THREAD_QUEUES = 32;
00031 const uint32 LOWEST_PRIORITY = 31;
00032
00033 const uint32 TH_BUSY = 0x0004;
00034 const uint32 TH_ACTIVE = 0x0008;
00035 const uint32 TH_ASLEEP = 0x0010;
00036 const uint32 TH_DYING = 0x0020;
00037 const uint32 TH_BLOCKED = 0x0040;
00038 const uint32 TH_IDLE = 0x0080;
00039
00040
00041 extern class IPC::Lock::lock_t lock_queues;
00042 extern class IPC::Lock::lock_t lock_sleep;
00043 extern class blist_t threads_queue[THREAD_QUEUES];
00044
00045 extern class blist_t threads_sleep;
00046 extern class blist_t threads_dead;
00047 extern class Memory::Heap::heapbox heap;
00048
00049
00050 struct thread_t
00051 {
00052 context_t context;
00053
00054 class process_t *proc;
00055 IPC::Message::mailbox inbox;
00056 struct threnv_t env;
00057 char name[THREAD_NAME];
00058
00059 int no;
00060
00061
00062 uint32 state;
00063 uint32 priority;
00064 uint32 worst_priority;
00065 uint32 best_priority;
00066 int prior_diff;
00067 uint64 awake_time;
00068 uint64 work_time;
00069 uint64 creation_time;
00070 uint64 running_time;
00071 uint64 save1_time;
00072 uint64 run1_time;
00073 uint64 save2_time;
00074 uint64 run2_time;
00075 uint32 load;
00076
00077
00078 struct sem_t volatile *sem_id;
00079 uint64 volatile sem_dt;
00080 };
00081
00082
00083 void allocate_context(Thread::thread_t *obj, bool supervisor, uint32 stack, uint32 proc_addr);
00084
00085 int enqueue_thread(thread_t *thread, blist_t *queue);
00086 int unqueue_thread(thread_t *thread, blist_t *queue);
00087
00088 uint32 thread_load(thread_t *thread);
00089
00090 int sleepcompar(const void *a, const void *b);
00091 int sleep(thread_t *thread, uint64 time);
00092 int sleep(uint64 time);
00093 int awake(thread_t *thread);
00094 int wake_threads();
00095
00096 int sem_sleep(thread_t *thread, struct sem_t *sem_id, uint64 sem_dt);
00097 int sem_sleep(struct sem_t *sem_id, uint64 sem_dt);
00098 int sem_awake(thread_t *thread);
00099
00100 thread_t *ThreadGet(int procno, int threadno);
00101 int ThreadKill(thread_t *thread);
00102 int ThreadKill(int procno, int threadno);
00103
00104 #define ThreadFail(...) do { complain(__VA_ARGS__); ::Thread::ThreadKill(current_thread); } while (0)
00105
00106 };
00107 extern volatile struct ::Thread::thread_t *current_thread;
00108
00109 #endif