Darwin/Lion fixes.

Integrate Linux and Unicode fixes from Matthaus.
This commit is contained in:
castano 2012-03-01 03:48:05 +00:00
parent 2ecc05b504
commit 2ff73e271a
6 changed files with 80 additions and 54 deletions

View File

@ -18,7 +18,7 @@ SET(CORE_SRCS
Stream.h Stream.h
StdStream.h StdStream.h
TextWriter.h TextWriter.cpp TextWriter.h TextWriter.cpp
Timer.h Timer.h Timer.cpp
Utils.h) Utils.h)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})

View File

@ -763,19 +763,19 @@ bool debug::attachToDebugger()
if (isDebuggerPresent() == FALSE) { if (isDebuggerPresent() == FALSE) {
Path process(1024); Path process(1024);
process.copy("\""); process.copy("\"");
GetSystemDirectory(process.str() + 1, 1024 - 1); GetSystemDirectoryA(process.str() + 1, 1024 - 1);
process.appendSeparator(); process.appendSeparator();
process.appendFormat("VSJitDebugger.exe\" -p %lu", ::GetCurrentProcessId()); process.appendFormat("VSJitDebugger.exe\" -p %lu", ::GetCurrentProcessId());
STARTUPINFO sSi; STARTUPINFOA sSi;
memset(&sSi, 0, sizeof(sSi)); memset(&sSi, 0, sizeof(sSi));
PROCESS_INFORMATION sPi; PROCESS_INFORMATION sPi;
memset(&sPi, 0, sizeof(sPi)); memset(&sPi, 0, sizeof(sPi));
BOOL b = CreateProcess(NULL, process.str(), NULL, NULL, FALSE, 0, NULL, NULL, &sSi, &sPi); BOOL b = CreateProcessA(NULL, process.str(), NULL, NULL, FALSE, 0, NULL, NULL, &sSi, &sPi);
if (b != FALSE) { if (b != FALSE) {
::WaitForSingleObject(sPi.hProcess, INFINITE); ::WaitForSingleObject(sPi.hProcess, INFINITE);
@ -802,4 +802,4 @@ bool debug::attachToDebugger()
#endif // NV_OS_WIN32 #endif // NV_OS_WIN32
return true; return true;
} }

View File

@ -3,7 +3,7 @@
#endif #endif
#include <stdint.h> // uint8_t, int8_t, ... uintptr_t #include <stdint.h> // uint8_t, int8_t, ... uintptr_t
#include <cstddef> // operator new, size_t, NULL //#include <cstddef> // operator new, size_t, NULL
// Function linkage // Function linkage
#define DLL_IMPORT #define DLL_IMPORT

View File

@ -0,0 +1,44 @@
// This code is in the public domain -- castano@gmail.com
#include "Timer.h"
using namespace nv;
#if NV_OS_WIN32
#define WINDOWS_LEAN_AND_MEAN
#define VC_EXTRALEAN
#define NOMINMAX
#include <windows.h> // QueryPerformanceFrequency, QueryPerformanceCounter
uint64 nv::systemClockFrequency()
{
uint64 frequency;
QueryPerformanceFrequency((LARGE_INTEGER*) &frequency);
return frequency;
}
uint64 nv::systemClock()
{
uint64 counter;
QueryPerformanceCounter((LARGE_INTEGER*) &counter);
return counter;
}
#else
#include <time.h> // clock
uint64 nv::systemClockFrequency()
{
return CLOCKS_PER_SEC;
}
uint64 nv::systemClock()
{
return clock();
}
#endif

View File

@ -6,60 +6,44 @@
#include "nvcore.h" #include "nvcore.h"
#if 1
#include <time.h> //clock
namespace nv { namespace nv {
#if NV_CC_MSVC
NV_FORCEINLINE uint64 fastCpuClock() { return rdtsc(); }
#elif NV_CC_GNUC && NV_CPU_X86
NV_FORCEINLINE uint64 fastCpuClock() {
uint64 val;
__asm__ volatile (".byte 0x0f, 0x31" : "=A" (val));
return val;
}
#elif NV_CC_GNUC && NV_CPU_X86_64
NV_FORCEINLINE uint64 fastCpuClock() {
uint hi, lo;
__asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
return uint64(lo) | (uint64(hi) << 32);
}
#else
NV_FORCEINLINE uint64 fastCpuClock() { return 0; }
#endif
uint64 systemClockFrequency();
uint64 systemClock();
class NVCORE_CLASS Timer class NVCORE_CLASS Timer
{ {
public: public:
Timer() {} Timer() {}
void start() { m_start = clock(); } void start() { m_start = systemClock(); }
void stop() { m_stop = clock(); } void stop() { m_stop = systemClock(); }
float elapsed() const { return float(m_stop - m_start) / CLOCKS_PER_SEC; } float elapsed() const { return float(m_stop - m_start) / systemClockFrequency(); }
private: private:
clock_t m_start; uint64 m_start;
clock_t m_stop; uint64 m_stop;
}; };
} // nv namespace } // nv namespace
#else
#define WINDOWS_LEAN_AND_MEAN
#define VC_EXTRALEAN
#define NOMINMAX
#include <windows.h>
class NVCORE_CLASS Timer
{
public:
Timer() {
// get the tick frequency from the OS
QueryPerformanceFrequency((LARGE_INTEGER*) &m_frequency);
}
void start() { QueryPerformanceCounter((LARGE_INTEGER*) &m_start); }
void stop() { QueryPerformanceCounter((LARGE_INTEGER*) &m_stop); }
int elapsed() const {
return (int)1000 * ((double)m_stop.QuadPart - (double)m_start.QuadPart) / (double)m_frequency.QuadPart;
}
private:
LARGE_INTEGER m_frequency;
LARGE_INTEGER m_start;
LARGE_INTEGER m_stop;
};
#endif // 0
#endif // NV_CORE_TIMER_H #endif // NV_CORE_TIMER_H

View File

@ -84,9 +84,7 @@
// Compiler: // Compiler:
// NV_CC_GNUC // NV_CC_GNUC
// NV_CC_MSVC // NV_CC_MSVC
// @@ NV_CC_MSVC6 // NV_CC_CLANG
// @@ NV_CC_MSVC7
// @@ NV_CC_MSVC8
#if defined POSH_COMPILER_CLANG #if defined POSH_COMPILER_CLANG
# define NV_CC_CLANG 1 # define NV_CC_CLANG 1
@ -148,7 +146,7 @@ typedef uint32 uint;
#define NV_FORBID_COPY(C) \ #define NV_FORBID_COPY(C) \
private: \ private: \
C( const C & ); \ C( const C & ); \
C &operator=( const C & ); C &operator=( const C & )
// Disable dynamic allocation on the heap. // Disable dynamic allocation on the heap.
@ -156,7 +154,7 @@ typedef uint32 uint;
#define NV_FORBID_HEAPALLOC() \ #define NV_FORBID_HEAPALLOC() \
private: \ private: \
void *operator new(size_t size); \ void *operator new(size_t size); \
void *operator new[](size_t size); void *operator new[](size_t size)
//static void *operator new(size_t size); \ //static void *operator new(size_t size); \
//static void *operator new[](size_t size); //static void *operator new[](size_t size);
@ -218,7 +216,7 @@ NV_COMPILER_CHECK(sizeof(uint32) == 4);
NV_STRING_JOIN2(AtStartup_, __LINE__)() { some_code; } \ NV_STRING_JOIN2(AtStartup_, __LINE__)() { some_code; } \
} \ } \
NV_STRING_JOIN3(AtStartup_, __LINE__, Instance); \ NV_STRING_JOIN3(AtStartup_, __LINE__, Instance); \
}; }
// Indicate the compiler that the parameter is not used to suppress compier warnings. // Indicate the compiler that the parameter is not used to suppress compier warnings.
#define NV_UNUSED(a) ((a)=(a)) #define NV_UNUSED(a) ((a)=(a))