TrinityCore
|
OS and processor abstraction. More...
#include <System.h>
Public Types | |
typedef bool(* | OutOfMemoryCallback )(size_t size, bool recoverable) |
Static Public Member Functions | |
static void | cleanup () |
static int | cpuSpeedMHz () |
static int | numCores () |
static bool | hasCPUID () |
static bool | hasRDTSC () |
static bool | hasSSE () |
static bool | hasSSE2 () |
static bool | hasSSE3 () |
static bool | hasMMX () |
static bool | has3DNow () |
static const std::string & | cpuVendor () |
static G3DEndian | machineEndian () |
static const std::string & | operatingSystem () |
static const std::string & | cpuArchitecture () |
static std::string | currentDateString () |
static std::string | currentTimeString () |
static void * | malloc (size_t bytes) |
static void * | calloc (size_t n, size_t x) |
static void * | realloc (void *block, size_t bytes) |
static std::string | mallocPerformance () |
static void | resetMallocPerformanceCounters () |
static std::string | mallocStatus () |
static void | free (void *p) |
static void * | alignedMalloc (size_t bytes, size_t alignment) |
static void | alignedFree (void *ptr) |
static void | memcpy (void *dst, const void *src, size_t numBytes) |
static void | memset (void *dst, uint8 value, size_t numBytes) |
static std::string | currentProgramFilename () |
static std::string & | appName () |
static const std::string & | version () |
static const std::string & | build () |
The optimization status of the G3D library (not the program compiled against it) More... | |
static void | sleep (RealTime t) |
static void | consoleClearScreen () |
static bool | consoleKeyPressed () |
static int | consoleReadKey () |
static RealTime | time () |
static void | beginCycleCount (uint64 &cycleCount) |
static void | endCycleCount (uint64 &cycleCount) |
static uint64 | getCycleCount () |
static void | setOutOfMemoryCallback (OutOfMemoryCallback c) |
static OutOfMemoryCallback | outOfMemoryCallback () |
static void | setEnv (const std::string &name, const std::string &value) |
static const char * | getEnv (const std::string &name) |
static void | describeSystem (class TextOutput &t) |
static void | describeSystem (std::string &s) |
static std::string | findDataFile (const std::string &full, bool exceptionIfNotFound=true, bool caseSensitive=true) |
static void | setAppDataDir (const std::string &path) |
Private Types | |
enum | CPUIDFunction { CPUID_VENDOR_ID = 0x00000000, CPUID_PROCESSOR_FEATURES = 0x00000001, CPUID_NUM_CORES = 0x00000004, CPUID_GET_HIGHEST_FUNCTION = 0x80000000, CPUID_EXTENDED_FEATURES = 0x80000001 } |
Private Member Functions | |
System () | |
Used for the singleton instance only. More... | |
void | getStandardProcessorExtensions () |
void | initTime () |
void | init () |
Static Private Member Functions | |
static System & | instance () |
The singleton instance. More... | |
static void | cpuid (CPUIDFunction func, uint32 &areg, uint32 &breg, uint32 &creg, uint32 &dreg) |
Private Attributes | |
bool | m_initialized |
int | m_cpuSpeed |
bool | m_hasCPUID |
bool | m_hasRDTSC |
bool | m_hasMMX |
bool | m_hasSSE |
bool | m_hasSSE2 |
bool | m_hasSSE3 |
bool | m_has3DNOW |
bool | m_has3DNOW2 |
bool | m_hasAMDMMX |
std::string | m_cpuVendor |
int | m_numCores |
std::string | m_appDataDir |
G3DEndian | m_machineEndian |
std::string | m_cpuArch |
std::string | m_operatingSystem |
struct timeval | m_start |
std::string | m_version |
OutOfMemoryCallback | m_outOfMemoryCallback |
RealTime | m_realWorldGetTickTime0 |
uint32 | m_highestCPUIDFunction |
OS and processor abstraction.
The first time any method is called the processor will be analyzed. Future calls are then fast.
Timing function overview: System::getCycleCount
System::getTick
System::getLocalTime
size | Size of memory that the system was trying to allocate |
recoverable | If true, the system will attempt to allocate again if the callback returns true. If false, malloc is going to return NULL and this invocation is just to notify the application. |
|
private |
|
private |
Used for the singleton instance only.
|
static |
Frees memory allocated with alignedMalloc.
|
static |
Guarantees that the start of the array is aligned to the specified number of bytes.
|
static |
Name of this program. Note that you can mutate this string to set your app name explicitly.
|
inlinestatic |
To count the number of cycles a given operation takes:
unsigned long count; System::beginCycleCount(count); ... System::endCycleCount(count); // count now contains the cycle count for the intervening operation.
|
static |
The optimization status of the G3D library (not the program compiled against it)
Either "Debug" or "Release", depending on whether _DEBUG was defined at compile-time for the library.
|
static |
|
static |
atexit handling code invoked from G3DCleanupHook.
|
static |
|
static |
Returns true if a key is waiting. Console programs only.
|
static |
Blocks until a key is read (use consoleKeyPressed to determine if a key is waiting to be read) then returns the character code for that key.
|
inlinestatic |
e.g., 80686
|
staticprivate |
Helper macro to call cpuid functions and return all values
See http://software.intel.com/en-us/articles/intel-64-architecture-processor-topology-enumeration/ or http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/25481.pdf
for description of the arguments.
|
inlinestatic |
Returns the speed of processor 0 in MHz. Always returns 0 on linux.
|
inlinestatic |
|
static |
Returns the current date as a string in the form YYYY-MM-DD
|
static |
Returns the fully qualified filename for the currently running executable.
This is more reliable than arg[0], which may be intentionally set to an incorrect value by a calling program, relative to a now non-current directory, or obfuscated by sym-links.
[Linux] version written by Nicolai Haehnle prefe, ct_@ gmx.n ethttp://www.flipcode.com/cgi-bin/msg.cgi?showThread=COTD-getexename&forum=cotd&id=-1
|
static |
Returns the current 24-hour local time as a string in the form HH:MM:SS
|
static |
Prints a human-readable description of this machine to the text output stream. Either argument may be NULL.
|
static |
|
inlinestatic |
|
static |
Tries to locate the resource by looking in related directories. If found, returns the full path to the resource, otherwise returns the empty string.
Looks in:
- Literal interpretation of full (i.e., if it contains a fully-qualified name) - Last directory in which a file was found - Current directory - System::appDataDir (which is usually GApp::Settings.dataDir, which defaults to the directory containing the program binary) - $G3D9DATA directory - System::appDataDir() + "data/" (note that this may be a zipfile named "data" with no extension) - System::appDataDir() + "data.zip/" - ../data-files/ (windows) - ../../data-files/ (windows) - ../../../data-files/ (windows)
Plus the following subdirectories of those:
exceptionIfNotFound | If true and the file is not found, throws G3D::FileNotFound. |
|
static |
Free data allocated with System::malloc.
Threadsafe on Win32.
|
static |
|
private |
Called from init()
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
private |
|
private |
Called from init()
|
staticprivate |
The singleton instance.
Used instead of a global variable to ensure that the order of intialization is correct, which is critical because other globals may allocate memory using System::malloc.
|
inlinestatic |
Returns the endianness of this machine.
|
static |
Uses pooled storage to optimize small allocations (1 byte to 5 kilobytes). Can be 10x to 100x faster than calling malloc
or new
.
The result must be freed with free.
Threadsafe on Win32.
|
static |
Returns a string describing how well System::malloc is using its internal pooled storage. "heap" memory was slow to allocate; the other data sizes are comparatively fast.
|
static |
Returns a string describing the current usage of the buffer pools used for optimizing System::malloc.
|
static |
An implementation of memcpy that may be up to 2x as fast as the C library one on some processors. Guaranteed to have the same behavior as memcpy in all cases.
|
static |
An implementation of memset that may be up to 2x as fast as the C library one on some processors. Guaranteed to have the same behavior as memset in all cases.
Michael Herf's fastest memset. n32 must be filled with the same character repeated.
|
inlinestatic |
Returns the number of logical processor cores (i.e., the number of execution units for threads)
|
inlinestatic |
e.g., "Windows", "GNU/Linux"
|
inlinestatic |
When System::malloc fails to allocate memory because the system is out of memory, it invokes this handler (if it is not NULL). The argument to the callback is the amount of memory that malloc was trying to allocate when it ran out. If the callback returns true, System::malloc will attempt to allocate the memory again. If the callback returns false, then System::malloc will return NULL.
You can use outOfMemoryCallback to free data structures or to register the failure.
|
static |
Version of realloc that works with System::malloc.
|
static |
|
static |
Sets the path that the application is using as its data directory. Used by findDataDir as an initial search location. GApp sets this upon constrution.
Set an environment variable for the current process
|
inlinestatic |
|
static |
Causes the current thread to yield for the specified duration and consume almost no CPU. The sleep will be extremely precise; it uses System::time() to calibrate the exact yeild time.
|
static |
The actual time (measured in seconds since Jan 1 1970 midnight).
Adjusted for local timezone and daylight savings time. This is as accurate and fast as getCycleCount().
|
inlinestatic |
G3D Version string
|
private |
this holds the data directory set by the application (currently GApp) for use by findDataFile
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
The Real-World time of System::getTick() time 0. Set by initTime
|
private |
|
private |