From 7be46ce487e2f3c6e145b9bc56cc37d8de97df9e Mon Sep 17 00:00:00 2001 From: s_nakamoto Date: Thu, 29 Oct 2009 20:10:46 +0000 Subject: better wallet.dat flush, consolidated QueryPerformanceCounter, PRI64d printf portability --- util.h | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) (limited to 'util.h') diff --git a/util.h b/util.h index 436281c90a..1c7215d29d 100644 --- a/util.h +++ b/util.h @@ -13,7 +13,6 @@ typedef unsigned long long uint64; #if defined(_MSC_VER) && _MSC_VER < 1300 #define for if (false) ; else for #endif - #ifndef _MSC_VER #define __forceinline inline #endif @@ -25,25 +24,22 @@ typedef unsigned long long uint64; #define UBEGIN(a) ((unsigned char*)&(a)) #define UEND(a) ((unsigned char*)&((&(a))[1])) #define ARRAYLEN(array) (sizeof(array)/sizeof((array)[0])) - -#ifdef _WINDOWS #define printf OutputDebugStringF -#endif #ifdef snprintf #undef snprintf #endif #define snprintf my_snprintf -#ifndef PRId64 +#ifndef PRI64d #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MSVCRT__) -#define PRId64 "I64d" -#define PRIu64 "I64u" -#define PRIx64 "I64x" +#define PRI64d "I64d" +#define PRI64u "I64u" +#define PRI64x "I64x" #else -#define PRId64 "lld" -#define PRIu64 "llu" -#define PRIx64 "llx" +#define PRI64d "lld" +#define PRI64u "llu" +#define PRI64x "llx" #endif #endif @@ -64,8 +60,6 @@ inline T& REF(const T& val) - - extern bool fDebug; extern bool fPrintToDebugger; extern bool fPrintToConsole; @@ -101,9 +95,7 @@ void AddTimeData(unsigned int ip, int64 nTime); - -// Wrapper to automatically initialize critical section -// Could use wxCriticalSection for portability, but it doesn't support TryEnterCriticalSection +// Wrapper to automatically initialize critical sections class CCriticalSection { #ifdef __WXMSW__ @@ -191,6 +183,7 @@ inline int OutputDebugStringF(const char* pszFormat, ...) } } +#ifdef __WXMSW__ if (fPrintToDebugger) { // accumulate a line at a time @@ -230,6 +223,7 @@ inline int OutputDebugStringF(const char* pszFormat, ...) pend -= (p1 - pszBuffer); } } +#endif #endif if (fPrintToConsole) @@ -254,7 +248,7 @@ inline int OutputDebugStringF(const char* pszFormat, ...) inline string i64tostr(int64 n) { - return strprintf("%"PRId64, n); + return strprintf("%"PRI64d, n); } inline string itostr(int n) @@ -328,6 +322,20 @@ inline void PrintHex(vector vch, const char* pszFormat="%s", bool printf(pszFormat, HexStr(vch, fSpaces).c_str()); } +inline int64 PerformanceCounter() +{ + int64 nCounter = 0; + QueryPerformanceCounter((LARGE_INTEGER*)&nCounter); + return nCounter; +} + +#ifndef __WXMSW__ +inline void Sleep(unsigned int nMilliseconds) +{ + wxMilliSleep(nMilliseconds); +} +#endif + @@ -370,6 +378,7 @@ inline void heapchk() + template inline uint256 Hash(const T1 pbegin, const T1 pend) { -- cgit v1.2.3