00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 typedef void (*dll_func)(...);
00027
00028 class Thread;
00029 class Event;
00030 class DLL;
00031
00032 class os {
00033 private:
00034 static int _vm_page_size;
00035 static void initialize_system_info();
00036 friend void os_init();
00037 public:
00038 static int getenv(char* name,char* buffer,int len);
00039
00040
00041 static int updateTimes();
00042 static double userTime();
00043 static double systemTime();
00044
00045 static double currentTime();
00046
00047
00048 static double user_time_for(Thread* thread);
00049 static double system_time_for(Thread* thread);
00050
00051
00052 static double elapsedTime();
00053
00054
00055 static long_int elapsed_counter();
00056 static long_int elapsed_frequency();
00057
00058 static void timerStart();
00059 static void timerStop();
00060 static void timerPrintBuffer();
00061
00062 static void* get_hInstance();
00063 static void* get_prevInstance();
00064 static int get_nCmdShow();
00065
00066
00067 static int vm_page_size() { return _vm_page_size; }
00068 static char* reserve_memory(int size);
00069 static bool commit_memory(char* addr, int size);
00070 static bool uncommit_memory(char* addr, int size);
00071 static bool release_memory(char* addr, int size);
00072 static bool guard_memory(char* addr, int size);
00073
00074
00075 static Thread* starting_thread(int* id_addr);
00076 static Thread* create_thread(int main(void* parameter), void* parameter, int* id_addr);
00077 static Event* create_event(bool initial_state);
00078
00079 static int current_thread_id();
00080 static void wait_for_event(Event* event);
00081 static void transfer(Thread* from_thread, Event* from_event, Thread* to_thread, Event* to_event);
00082 static void transfer_and_continue(Thread* from_thread, Event* from_event, Thread* to_thread, Event* to_event);
00083 static void terminate_thread(Thread* thread);
00084 static void delete_event(Event* event);
00085
00086 static void reset_event(Event* event);
00087 static void signal_event(Event* event);
00088 static bool wait_for_event_or_timer(Event* event, int timeout_in_ms);
00089
00090 static void sleep(int ms);
00091
00092
00093 static void suspend_thread(Thread* thread);
00094 static void resume_thread(Thread* thread);
00095 static void fetch_top_frame(Thread* thread, int** sp, int** fp, char** pc);
00096
00097 static void breakpoint();
00098
00099 static int message_box(char* title, char* message);
00100
00101 static void fatalExit(int num);
00102
00103 static bool move_file(char* from, char* to);
00104 static bool check_directory(char* dir_name);
00105
00106
00107 static dll_func dll_lookup(char* name, DLL* library);
00108 static DLL* dll_load(char* name);
00109 static bool dll_unload(DLL* library);
00110 };
00111
00112
00113
00114 class ThreadCritical {
00115 private:
00116 friend void os_init();
00117 friend void os_exit();
00118 static void intialize();
00119 static void release();
00120 public:
00121 ThreadCritical();
00122 ~ThreadCritical();
00123 };