Laszlo's fix to make generate threads idle priority on Linux,

replaced some wxBase dependencies: wxMutex, wxFileExists, wxStandardPaths, wxGetLocalTimeMillis

git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@99 1a98c847-1fd6-4fd8-948a-caf3550aa51b
This commit is contained in:
s_nakamoto 2010-07-08 16:14:56 +00:00
parent d77eac25b2
commit d882773789
17 changed files with 167 additions and 101 deletions

View File

@ -59,6 +59,10 @@
#include <boost/function.hpp> #include <boost/function.hpp>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/interprocess/sync/interprocess_mutex.hpp>
#include <boost/interprocess/sync/interprocess_recursive_mutex.hpp>
#include <boost/date_time/gregorian/gregorian_types.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#ifdef __WXMSW__ #ifdef __WXMSW__
#include <windows.h> #include <windows.h>

View File

@ -4,6 +4,8 @@
#include "headers.h" #include "headers.h"
extern string GetDefaultDataDir(); /// todo: delete this later, just used by debug test
@ -59,40 +61,6 @@ void Shutdown(void* parg)
// //
#ifdef __WXMSW__ #ifdef __WXMSW__
typedef WINSHELLAPI BOOL (WINAPI *PSHGETSPECIALFOLDERPATHA)(HWND hwndOwner, LPSTR lpszPath, int nFolder, BOOL fCreate);
string MyGetSpecialFolderPath(int nFolder, bool fCreate)
{
char pszPath[MAX_PATH+100] = "";
// SHGetSpecialFolderPath is not usually available on NT 4.0
HMODULE hShell32 = LoadLibraryA("shell32.dll");
if (hShell32)
{
PSHGETSPECIALFOLDERPATHA pSHGetSpecialFolderPath =
(PSHGETSPECIALFOLDERPATHA)GetProcAddress(hShell32, "SHGetSpecialFolderPathA");
if (pSHGetSpecialFolderPath)
(*pSHGetSpecialFolderPath)(NULL, pszPath, nFolder, fCreate);
FreeModule(hShell32);
}
// Backup option
if (pszPath[0] == '\0')
{
if (nFolder == CSIDL_STARTUP)
{
strcpy(pszPath, getenv("USERPROFILE"));
strcat(pszPath, "\\Start Menu\\Programs\\Startup");
}
else if (nFolder == CSIDL_APPDATA)
{
strcpy(pszPath, getenv("APPDATA"));
}
}
return pszPath;
}
string StartupShortcutPath() string StartupShortcutPath()
{ {
return MyGetSpecialFolderPath(CSIDL_STARTUP, true) + "\\Bitcoin.lnk"; return MyGetSpecialFolderPath(CSIDL_STARTUP, true) + "\\Bitcoin.lnk";
@ -100,7 +68,7 @@ string StartupShortcutPath()
bool GetStartOnSystemStartup() bool GetStartOnSystemStartup()
{ {
return wxFileExists(StartupShortcutPath()); return filesystem::exists(StartupShortcutPath().c_str());
} }
void SetStartOnSystemStartup(bool fAutoStart) void SetStartOnSystemStartup(bool fAutoStart)
@ -166,7 +134,7 @@ void SetStartOnSystemStartup(bool fAutoStart) { }
// //
// Define a new application // Define a new application
class CMyApp: public wxApp class CMyApp : public wxApp
{ {
public: public:
wxLocale m_locale; wxLocale m_locale;
@ -216,7 +184,10 @@ bool CMyApp::Initialize(int& argc, wxChar** argv)
#ifdef __WXMSW__ #ifdef __WXMSW__
if (str.size() >= 1 && str[0] == '/') if (str.size() >= 1 && str[0] == '/')
str[0] = '-'; str[0] = '-';
str = str.MakeLower(); char pszLower[MAX_PATH];
strlcpy(pszLower, str.c_str(), sizeof(pszLower));
strlwr(pszLower);
str = pszLower;
#endif #endif
// haven't decided which argument to use for this yet // haven't decided which argument to use for this yet
if (str == "-daemon" || str == "-d" || str == "start") if (str == "-daemon" || str == "-d" || str == "start")
@ -356,18 +327,14 @@ bool CMyApp::OnInit2()
" -daemon \t " + _("Run in the background as a daemon and accept commands\n") + " -daemon \t " + _("Run in the background as a daemon and accept commands\n") +
" -? \t " + _("This help message\n"); " -? \t " + _("This help message\n");
#if defined(__WXMSW__) && wxUSE_GUI
if (fWindows && fGUI) // Tabs make the columns line up in the message box
{ wxMessageBox(strUsage, "Bitcoin", wxOK);
// Tabs make the columns line up in the message box #else
wxMessageBox(strUsage, "Bitcoin", wxOK); // Remove tabs
} strUsage.Replace("\t", "");
else fprintf(stderr, "%s", ((string)strUsage).c_str());
{ #endif
// Remove tabs
strUsage.Replace("\t", "");
fprintf(stderr, "%s", ((string)strUsage).c_str());
}
return false; return false;
} }
@ -387,6 +354,15 @@ bool CMyApp::OnInit2()
printf("System default language is %d %s\n", m_locale.GetSystemLanguage(), ((string)m_locale.GetSysName()).c_str()); printf("System default language is %d %s\n", m_locale.GetSystemLanguage(), ((string)m_locale.GetSysName()).c_str());
printf("Language file %s (%s)\n", (string("locale/") + (string)m_locale.GetCanonicalName() + "/LC_MESSAGES/bitcoin.mo").c_str(), ((string)m_locale.GetLocale()).c_str()); printf("Language file %s (%s)\n", (string("locale/") + (string)m_locale.GetCanonicalName() + "/LC_MESSAGES/bitcoin.mo").c_str(), ((string)m_locale.GetLocale()).c_str());
/// debug - for now, just watching if these match
if (pszSetDataDir[0] == 0)
{
if (GetDefaultDataDir() != GetDataDir())
printf("**** GetDefaultDataDir() %s != %s\n", GetDefaultDataDir().c_str(), GetDataDir().c_str());
else
printf("OK GetDefaultDataDir() %s == %s\n", GetDefaultDataDir().c_str(), GetDataDir().c_str());
}
if (mapArgs.count("-loadblockindextest")) if (mapArgs.count("-loadblockindextest"))
{ {
CTxDB txdb("r"); CTxDB txdb("r");

Binary file not shown.

View File

@ -692,6 +692,8 @@ msgstr "Version"
msgid "" msgid ""
"Copyright (c) 2009-2010 Satoshi Nakamoto.\n" "Copyright (c) 2009-2010 Satoshi Nakamoto.\n"
"\n" "\n"
"This is experimental software.\n"
"\n"
"Distributed under the MIT/X11 software license, see the accompanying file \n" "Distributed under the MIT/X11 software license, see the accompanying file \n"
"license.txt or http://www.opensource.org/licenses/mit-license.php.\n" "license.txt or http://www.opensource.org/licenses/mit-license.php.\n"
"\n" "\n"
@ -701,6 +703,8 @@ msgid ""
msgstr "" msgstr ""
"Copyright (c) 2009-2010 Satoshi Nakamoto.\n" "Copyright (c) 2009-2010 Satoshi Nakamoto.\n"
"\n" "\n"
"Dies ist experimentelle Software.\n"
"\n"
"Lizensiert unter der MIT/X11 Software-Lizenz. Beachten Sie die beiliegende\n" "Lizensiert unter der MIT/X11 Software-Lizenz. Beachten Sie die beiliegende\n"
"Datei license.txt oder http://www.opensource.org/licenses/mit-license.php.\n" "Datei license.txt oder http://www.opensource.org/licenses/mit-license.php.\n"
"\n" "\n"

Binary file not shown.

View File

@ -690,6 +690,8 @@ msgstr "versione"
msgid "" msgid ""
"Copyright (c) 2009-2010 Satoshi Nakamoto.\n" "Copyright (c) 2009-2010 Satoshi Nakamoto.\n"
"\n" "\n"
"This is experimental software.\n"
"\n"
"Distributed under the MIT/X11 software license, see the accompanying file \n" "Distributed under the MIT/X11 software license, see the accompanying file \n"
"license.txt or http://www.opensource.org/licenses/mit-license.php.\n" "license.txt or http://www.opensource.org/licenses/mit-license.php.\n"
"\n" "\n"
@ -699,6 +701,8 @@ msgid ""
msgstr "" msgstr ""
"Copyright (c) 2009-2010 Satoshi Nakamoto.\n" "Copyright (c) 2009-2010 Satoshi Nakamoto.\n"
"\n" "\n"
"Questo è un software sperimentale.\n"
"\n"
"Distribuito sotto la licenza software MIT/X11, guarda il file license.txt\n" "Distribuito sotto la licenza software MIT/X11, guarda il file license.txt\n"
"incluso oppure su http://www.opensource.org/licenses/mit-license.php.\n" "incluso oppure su http://www.opensource.org/licenses/mit-license.php.\n"
"\n" "\n"

Binary file not shown.

View File

@ -691,6 +691,8 @@ msgstr "versie"
msgid "" msgid ""
"Copyright (c) 2009-2010 Satoshi Nakamoto.\n" "Copyright (c) 2009-2010 Satoshi Nakamoto.\n"
"\n" "\n"
"This is experimental software.\n"
"\n"
"Distributed under the MIT/X11 software license, see the accompanying file \n" "Distributed under the MIT/X11 software license, see the accompanying file \n"
"license.txt or http://www.opensource.org/licenses/mit-license.php.\n" "license.txt or http://www.opensource.org/licenses/mit-license.php.\n"
"\n" "\n"
@ -700,6 +702,8 @@ msgid ""
msgstr "" msgstr ""
"Copyright (c) 2009-2010 Satoshi Nakamoto.\n" "Copyright (c) 2009-2010 Satoshi Nakamoto.\n"
"\n" "\n"
"Dit is experimentele software.\n"
"\n"
"Gedistributeerd onder de MIT/X11 software licentie, see het bijbehorende bestand \n" "Gedistributeerd onder de MIT/X11 software licentie, see het bijbehorende bestand \n"
"license.txt of http://www.opensource.org/licenses/mit-license.php.\n" "license.txt of http://www.opensource.org/licenses/mit-license.php.\n"
"\n" "\n"

View File

@ -1477,7 +1477,10 @@ bool CheckDiskSpace(int64 nAdditionalBytes)
if (nFreeBytesAvailable < (int64)15000000 + nAdditionalBytes) if (nFreeBytesAvailable < (int64)15000000 + nAdditionalBytes)
{ {
fShutdown = true; fShutdown = true;
printf("*** %s***\n", _("Warning: Disk space is low "));
#if wxUSE_GUI
ThreadSafeMessageBox(_("Warning: Disk space is low "), "Bitcoin", wxOK | wxICON_EXCLAMATION); ThreadSafeMessageBox(_("Warning: Disk space is low "), "Bitcoin", wxOK | wxICON_EXCLAMATION);
#endif
CreateThread(Shutdown, NULL); CreateThread(Shutdown, NULL);
return false; return false;
} }
@ -2713,25 +2716,32 @@ void BitcoinMiner()
if ((++tmp.block.nNonce & nMask) == 0) if ((++tmp.block.nNonce & nMask) == 0)
{ {
// Meter hashes/sec // Meter hashes/sec
static int64 nHashCounter; static int64 nTimerStart;
static int64 nLastTick; static int nHashCounter;
if (nLastTick == 0) if (nTimerStart == 0)
nLastTick = GetTimeMillis(); nTimerStart = GetTimeMillis();
else else
nHashCounter += nMask + 1; nHashCounter++;
if (GetTimeMillis() - nLastTick > 4000) if (GetTimeMillis() - nTimerStart > 4000)
{ {
double dHashesPerSec = 1000.0 * nHashCounter / (GetTimeMillis() - nLastTick); static CCriticalSection cs;
nLastTick = GetTimeMillis(); CRITICAL_BLOCK(cs)
nHashCounter = 0;
string strStatus = strprintf(" %.0f khash/s", dHashesPerSec/1000.0);
UIThreadCall(bind(CalledSetStatusBar, strStatus, 0));
static int64 nLogTime;
if (GetTime() - nLogTime > 30 * 60)
{ {
nLogTime = GetTime(); if (GetTimeMillis() - nTimerStart > 4000)
printf("%s ", DateTimeStrFormat("%x %H:%M", GetTime()).c_str()); {
printf("hashmeter %3d CPUs %6.0f khash/s\n", vnThreadsRunning[3], dHashesPerSec/1000.0); double dHashesPerSec = 1000.0 * (nMask+1) * nHashCounter / (GetTimeMillis() - nTimerStart);
nTimerStart = GetTimeMillis();
nHashCounter = 0;
string strStatus = strprintf(" %.0f khash/s", dHashesPerSec/1000.0);
UIThreadCall(bind(CalledSetStatusBar, strStatus, 0));
static int64 nLogTime;
if (GetTime() - nLogTime > 30 * 60)
{
nLogTime = GetTime();
printf("%s ", DateTimeStrFormat("%x %H:%M", GetTime()).c_str());
printf("hashmeter %3d CPUs %6.0f khash/s\n", vnThreadsRunning[3], dHashesPerSec/1000.0);
}
}
} }
} }

View File

@ -68,6 +68,6 @@ bitcoind: $(OBJS:obj/%=obj/nogui/%) obj/sha.o
clean: clean:
-rm obj/*.o -rm -f obj/*.o
-rm obj/nogui/*.o -rm -f obj/nogui/*.o
-rm headers.h.gch -rm -f headers.h.gch

22
rpc.cpp
View File

@ -927,20 +927,22 @@ int CommandLineRPC(int argc, char *argv[])
string strResult = (result.type() == str_type ? result.get_str() : write_string(result, true)); string strResult = (result.type() == str_type ? result.get_str() : write_string(result, true));
if (result.type() != null_type) if (result.type() != null_type)
{ {
if (fWindows && fGUI) #if defined(__WXMSW__) && wxUSE_GUI
// Windows GUI apps can't print to command line, // Windows GUI apps can't print to command line,
// so settle for a message box yuck // so settle for a message box yuck
MyMessageBox(strResult.c_str(), "Bitcoin", wxOK); MyMessageBox(strResult.c_str(), "Bitcoin", wxOK);
else #else
fprintf(stdout, "%s\n", strResult.c_str()); fprintf(stdout, "%s\n", strResult.c_str());
#endif
} }
return 0; return 0;
} }
catch (std::exception& e) { catch (std::exception& e) {
if (fWindows && fGUI) #if defined(__WXMSW__) && wxUSE_GUI
MyMessageBox(strprintf("error: %s\n", e.what()).c_str(), "Bitcoin", wxOK); MyMessageBox(strprintf("error: %s\n", e.what()).c_str(), "Bitcoin", wxOK);
else #else
fprintf(stderr, "error: %s\n", e.what()); fprintf(stderr, "error: %s\n", e.what());
#endif
} catch (...) { } catch (...) {
PrintException(NULL, "CommandLineRPC()"); PrintException(NULL, "CommandLineRPC()");
} }

View File

@ -20,7 +20,7 @@ class CDataStream;
class CAutoFile; class CAutoFile;
static const int VERSION = 300; static const int VERSION = 300;
static const char* pszSubVer = ""; static const char* pszSubVer = ".1";

View File

@ -554,7 +554,7 @@ CAboutDialogBase::CAboutDialogBase( wxWindow* parent, wxWindowID id, const wxStr
bSizer631->Add( 0, 4, 0, wxEXPAND, 5 ); bSizer631->Add( 0, 4, 0, wxEXPAND, 5 );
m_staticTextMain = new wxStaticText( this, wxID_ANY, _("Copyright (c) 2009-2010 Satoshi Nakamoto.\n\nDistributed under the MIT/X11 software license, see the accompanying file \nlicense.txt or http://www.opensource.org/licenses/mit-license.php.\n\nThis product includes software developed by the OpenSSL Project for use in the \nOpenSSL Toolkit (http://www.openssl.org/) and cryptographic software written by \nEric Young (eay@cryptsoft.com)."), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextMain = new wxStaticText( this, wxID_ANY, _("Copyright (c) 2009-2010 Satoshi Nakamoto.\n\nThis is experimental software.\n\nDistributed under the MIT/X11 software license, see the accompanying file \nlicense.txt or http://www.opensource.org/licenses/mit-license.php.\n\nThis product includes software developed by the OpenSSL Project for use in the \nOpenSSL Toolkit (http://www.openssl.org/) and cryptographic software written by \nEric Young (eay@cryptsoft.com)."), wxDefaultPosition, wxDefaultSize, 0 );
m_staticTextMain->Wrap( -1 ); m_staticTextMain->Wrap( -1 );
bSizer631->Add( m_staticTextMain, 0, wxALL, 5 ); bSizer631->Add( m_staticTextMain, 0, wxALL, 5 );

View File

@ -227,7 +227,7 @@ class CAboutDialogBase : public wxDialog
public: public:
wxStaticText* m_staticTextVersion; wxStaticText* m_staticTextVersion;
CAboutDialogBase( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("About Bitcoin"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 532,315 ), long style = wxDEFAULT_DIALOG_STYLE ); CAboutDialogBase( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("About Bitcoin"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 532,329 ), long style = wxDEFAULT_DIALOG_STYLE );
~CAboutDialogBase(); ~CAboutDialogBase();
}; };

View File

@ -2866,7 +2866,7 @@
<property name="minimum_size"></property> <property name="minimum_size"></property>
<property name="name">CAboutDialogBase</property> <property name="name">CAboutDialogBase</property>
<property name="pos"></property> <property name="pos"></property>
<property name="size">532,315</property> <property name="size">532,329</property>
<property name="style">wxDEFAULT_DIALOG_STYLE</property> <property name="style">wxDEFAULT_DIALOG_STYLE</property>
<property name="subclass"></property> <property name="subclass"></property>
<property name="title">About Bitcoin</property> <property name="title">About Bitcoin</property>
@ -3130,7 +3130,7 @@
<property name="font"></property> <property name="font"></property>
<property name="hidden">0</property> <property name="hidden">0</property>
<property name="id">wxID_ANY</property> <property name="id">wxID_ANY</property>
<property name="label">Copyright (c) 2009-2010 Satoshi Nakamoto.&#x0A;&#x0A;Distributed under the MIT/X11 software license, see the accompanying file &#x0A;license.txt or http://www.opensource.org/licenses/mit-license.php.&#x0A;&#x0A;This product includes software developed by the OpenSSL Project for use in the &#x0A;OpenSSL Toolkit (http://www.openssl.org/) and cryptographic software written by &#x0A;Eric Young (eay@cryptsoft.com).</property> <property name="label">Copyright (c) 2009-2010 Satoshi Nakamoto.&#x0A;&#x0A;This is experimental software.&#x0A;&#x0A;Distributed under the MIT/X11 software license, see the accompanying file &#x0A;license.txt or http://www.opensource.org/licenses/mit-license.php.&#x0A;&#x0A;This product includes software developed by the OpenSSL Project for use in the &#x0A;OpenSSL Toolkit (http://www.openssl.org/) and cryptographic software written by &#x0A;Eric Young (eay@cryptsoft.com).</property>
<property name="maximum_size"></property> <property name="maximum_size"></property>
<property name="minimum_size"></property> <property name="minimum_size"></property>
<property name="name">m_staticTextMain</property> <property name="name">m_staticTextMain</property>

View File

@ -20,13 +20,13 @@ bool fCommandLine = false;
// Init openssl library multithreading support // Init openssl library multithreading support
static wxMutex** ppmutexOpenSSL; static boost::interprocess::interprocess_mutex** ppmutexOpenSSL;
void locking_callback(int mode, int i, const char* file, int line) void locking_callback(int mode, int i, const char* file, int line)
{ {
if (mode & CRYPTO_LOCK) if (mode & CRYPTO_LOCK)
ppmutexOpenSSL[i]->Lock(); ppmutexOpenSSL[i]->lock();
else else
ppmutexOpenSSL[i]->Unlock(); ppmutexOpenSSL[i]->unlock();
} }
// Init // Init
@ -36,9 +36,9 @@ public:
CInit() CInit()
{ {
// Init openssl library multithreading support // Init openssl library multithreading support
ppmutexOpenSSL = (wxMutex**)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(wxMutex*)); ppmutexOpenSSL = (boost::interprocess::interprocess_mutex**)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(boost::interprocess::interprocess_mutex*));
for (int i = 0; i < CRYPTO_num_locks(); i++) for (int i = 0; i < CRYPTO_num_locks(); i++)
ppmutexOpenSSL[i] = new wxMutex(); ppmutexOpenSSL[i] = new boost::interprocess::interprocess_mutex();
CRYPTO_set_locking_callback(locking_callback); CRYPTO_set_locking_callback(locking_callback);
#ifdef __WXMSW__ #ifdef __WXMSW__
@ -152,7 +152,7 @@ inline int OutputDebugStringF(const char* pszFormat, ...)
if (fileout) if (fileout)
{ {
//// Debug print useful for profiling //// Debug print useful for profiling
//fprintf(fileout, " %"PRI64d" ", wxGetLocalTimeMillis().GetValue()); //fprintf(fileout, " %"PRI64d" ", GetTimeMillis());
va_list arg_ptr; va_list arg_ptr;
va_start(arg_ptr, pszFormat); va_start(arg_ptr, pszFormat);
ret = vfprintf(fileout, pszFormat, arg_ptr); ret = vfprintf(fileout, pszFormat, arg_ptr);
@ -521,6 +521,69 @@ void PrintException(std::exception* pex, const char* pszThread)
#ifdef __WXMSW__
typedef WINSHELLAPI BOOL (WINAPI *PSHGETSPECIALFOLDERPATHA)(HWND hwndOwner, LPSTR lpszPath, int nFolder, BOOL fCreate);
string MyGetSpecialFolderPath(int nFolder, bool fCreate)
{
char pszPath[MAX_PATH+100] = "";
// SHGetSpecialFolderPath isn't always available on old Windows versions
HMODULE hShell32 = LoadLibraryA("shell32.dll");
if (hShell32)
{
PSHGETSPECIALFOLDERPATHA pSHGetSpecialFolderPath =
(PSHGETSPECIALFOLDERPATHA)GetProcAddress(hShell32, "SHGetSpecialFolderPathA");
if (pSHGetSpecialFolderPath)
(*pSHGetSpecialFolderPath)(NULL, pszPath, nFolder, fCreate);
FreeModule(hShell32);
}
// Backup option
if (pszPath[0] == '\0')
{
if (nFolder == CSIDL_STARTUP)
{
strcpy(pszPath, getenv("USERPROFILE"));
strcat(pszPath, "\\Start Menu\\Programs\\Startup");
}
else if (nFolder == CSIDL_APPDATA)
{
strcpy(pszPath, getenv("APPDATA"));
}
}
return pszPath;
}
#endif
string GetDefaultDataDir()
{
// Windows: C:\Documents and Settings\username\Application Data\Appname
// Mac: ~/Library/Application Support/Appname
// Unix: ~/.appname
#ifdef __WXMSW__
// Windows
return MyGetSpecialFolderPath(CSIDL_APPDATA, true) + "\\Bitcoin";
#else
char* pszHome = getenv("HOME");
if (pszHome == NULL || strlen(pszHome) == 0)
pszHome = (char*)"/";
string strHome = pszHome;
if (strHome[strHome.size()-1] != '/')
strHome += '/';
#ifdef __WXOSX__
// Mac
strHome += "Library/Application Support/";
_mkdir(strHome.c_str());
return strHome + "Bitcoin";
#else
// Unix
return strHome + ".bitcoin";
#endif
#endif
}
void GetDataDir(char* pszDir) void GetDataDir(char* pszDir)
{ {
// pszDir must be at least MAX_PATH length. // pszDir must be at least MAX_PATH length.
@ -538,11 +601,6 @@ void GetDataDir(char* pszDir)
{ {
// This can be called during exceptions by printf, so we cache the // This can be called during exceptions by printf, so we cache the
// value so we don't have to do memory allocations after that. // value so we don't have to do memory allocations after that.
// wxStandardPaths::GetUserDataDir
// Return the directory for the user-dependent application data files:
// Unix: ~/.appname
// Windows: C:\Documents and Settings\username\Application Data\appname
// Mac: ~/Library/Application Support/appname
static char pszCachedDir[MAX_PATH]; static char pszCachedDir[MAX_PATH];
if (pszCachedDir[0] == 0) if (pszCachedDir[0] == 0)
{ {

18
util.h
View File

@ -141,6 +141,9 @@ void ParseParameters(int argc, char* argv[]);
const char* wxGetTranslation(const char* psz); const char* wxGetTranslation(const char* psz);
int GetFilesize(FILE* file); int GetFilesize(FILE* file);
void GetDataDir(char* pszDirRet); void GetDataDir(char* pszDirRet);
#ifdef __WXMSW__
string MyGetSpecialFolderPath(int nFolder, bool fCreate);
#endif
string GetDataDir(); string GetDataDir();
void ShrinkDebugFile(); void ShrinkDebugFile();
uint64 GetRand(uint64 nMax); uint64 GetRand(uint64 nMax);
@ -174,13 +177,13 @@ public:
bool TryEnter() { return TryEnterCriticalSection(&cs); } bool TryEnter() { return TryEnterCriticalSection(&cs); }
#else #else
protected: protected:
wxMutex mutex; boost::interprocess::interprocess_recursive_mutex mutex;
public: public:
explicit CCriticalSection() : mutex(wxMUTEX_RECURSIVE) { } explicit CCriticalSection() { }
~CCriticalSection() { } ~CCriticalSection() { }
void Enter() { mutex.Lock(); } void Enter() { mutex.lock(); }
void Leave() { mutex.Unlock(); } void Leave() { mutex.unlock(); }
bool TryEnter() { return mutex.TryLock() == wxMUTEX_NO_ERROR; } bool TryEnter() { return mutex.try_lock(); }
#endif #endif
public: public:
const char* pszFile; const char* pszFile;
@ -324,7 +327,8 @@ inline int64 PerformanceCounter()
inline int64 GetTimeMillis() inline int64 GetTimeMillis()
{ {
return wxGetLocalTimeMillis().GetValue(); return (posix_time::ptime(posix_time::microsec_clock::universal_time()) -
posix_time::ptime(gregorian::date(1970,1,1))).total_milliseconds();
} }
inline string DateTimeStrFormat(const char* pszFormat, int64 nTime) inline string DateTimeStrFormat(const char* pszFormat, int64 nTime)
@ -513,7 +517,7 @@ inline pthread_t CreateThread(void(*pfn)(void*), void* parg, bool fWantHandle=fa
return hthread; return hthread;
} }
#define THREAD_PRIORITY_LOWEST PRIO_MIN #define THREAD_PRIORITY_LOWEST PRIO_MAX
#define THREAD_PRIORITY_BELOW_NORMAL 2 #define THREAD_PRIORITY_BELOW_NORMAL 2
#define THREAD_PRIORITY_NORMAL 0 #define THREAD_PRIORITY_NORMAL 0
#define THREAD_PRIORITY_ABOVE_NORMAL 0 #define THREAD_PRIORITY_ABOVE_NORMAL 0