os.hpp

Go to the documentation of this file.
00001 /* Copyright 1994, 1995 LongView Technologies L.L.C. $Revision: 1.24 $ */
00002 /* Copyright (c) 2006, Sun Microsystems, Inc.
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 
00006 following conditions are met:
00007 
00008     * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following 
00010           disclaimer in the documentation and/or other materials provided with the distribution.
00011     * Neither the name of Sun Microsystems nor the names of its contributors may be used to endorse or promote products derived 
00012           from this software without specific prior written permission.
00013 
00014 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 
00015 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
00016 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
00017 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00018 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
00019 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
00020 
00021 
00022 */
00023 
00024 // os defines the interface to operating system
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   // We must call updateTimes before calling userTime or currentTime.
00041   static int    updateTimes();
00042   static double userTime();
00043   static double systemTime();
00044 
00045   static double currentTime();
00046 
00047   // Timing opertaions for threads
00048   static double user_time_for(Thread* thread);
00049   static double system_time_for(Thread* thread);
00050 
00051   // Returns the elapsed time in seconds since the vm started.
00052   static double elapsedTime();
00053 
00054   // Interface to the win32 performance counter
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   // OS interface to Virtual Memory
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   // threads
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   // thread support for profiling
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   // DLL support
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 // A critial region for controling thread transfer at
00113 // interrupts
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 };

Generated on Mon Oct 9 13:37:21 2006 for Strongtalk VM by  doxygen 1.4.7