Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

System.d

Go to the documentation of this file.
00001 /*******************************************************************************
00002 
00003         @file System.d
00004         
00005         Copyright (c) 2004 Kris Bell
00006         
00007         This software is provided 'as-is', without any express or implied
00008         warranty. In no event will the authors be held liable for damages
00009         of any kind arising from the use of this software.
00010         
00011         Permission is hereby granted to anyone to use this software for any 
00012         purpose, including commercial applications, and to alter it and/or 
00013         redistribute it freely, subject to the following restrictions:
00014         
00015         1. The origin of this software must not be misrepresented; you must 
00016            not claim that you wrote the original software. If you use this 
00017            software in a product, an acknowledgment within documentation of 
00018            said product would be appreciated but is not required.
00019 
00020         2. Altered source versions must be plainly marked as such, and must 
00021            not be misrepresented as being the original software.
00022 
00023         3. This notice may not be removed or altered from any distribution
00024            of the source.
00025 
00026         4. Derivative works are permitted, but they must carry this notice
00027            in full and credit the original source.
00028 
00029 
00030                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00031 
00032 
00033         @version        Initial version, March 2004      
00034 
00035         @author         Kris
00036                         Regan Heath (Win32 error msgs)
00037                         Anders F Bjorklund (Darwin patches)
00038 
00039 
00040 *******************************************************************************/
00041 
00042 module mango.sys.System;
00043 
00044 private import std.thread;     
00045 
00046 private import mango.sys.OS,
00047                mango.sys.Epoch;
00048 
00049 /*******************************************************************************
00050 
00051         Stuff for sysError(), kindly provided by Regan Heath. 
00052 
00053 *******************************************************************************/
00054 
00055 version (Win32)
00056         {
00057         extern (Windows) VOID Sleep (DWORD millisecs);
00058         }
00059 version (Posix)
00060         {
00061         extern (C) void usleep(uint);
00062         }
00063 
00064 /*******************************************************************************
00065 
00066         Some system-specific functionality that doesn't belong anywhere 
00067         else. This needs some further thought and refinement.
00068 
00069 *******************************************************************************/
00070 
00071 struct System
00072 {       
00073         /***********************************************************************
00074                 
00075                 Time interval multipliers. All Mango intervals are based
00076                 upon microseconds.
00077 
00078         ***********************************************************************/
00079 
00080         enum Interval   {
00081                         Microsec = 1, 
00082                         Millisec = 1000, 
00083                         Second   = 1_000_000, 
00084                         Minute   = 60_000_000
00085                         };
00086 
00087         /***********************************************************************
00088                 
00089                 Return the number of milliseconds since January 1st 1970
00090 
00091         ***********************************************************************/
00092 
00093         final static ulong getMillisecs ()
00094         {
00095                 return Epoch.utcMilli;
00096         }
00097 
00098         /***********************************************************************
00099         
00100                 Send this thread to sleep for a while. The time interval
00101                 is measured in microseconds. Specifying a period value of
00102                 uint.max will cause the calling thread to sleep forever.
00103 
00104         ***********************************************************************/
00105 
00106         final static void sleep (uint interval = uint.max)
00107         {
00108                 do {
00109                    version (Posix)
00110                             usleep (interval);
00111 
00112                    version (Win32)
00113                             Sleep (interval / 1000);
00114                    } while (interval == uint.max);
00115         }
00116 
00117         /***********************************************************************
00118               
00119                 Create a thread for the given delegate, and optionally start 
00120                 it up.
00121                   
00122         ***********************************************************************/
00123         version (Ares)
00124                  typedef void delegate() ThreadDelegate;
00125               else
00126                  typedef int delegate() ThreadDelegate;
00127 
00128         final static Thread createThread (ThreadDelegate dg, bool start = false)
00129         {
00130                 Thread t = new Thread (dg);
00131                 if (start)
00132                     t.start ();
00133                 return t;
00134         }
00135 }

Generated on Sat Dec 24 17:28:33 2005 for Mango by  doxygen 1.4.0