Browse Source

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

replaced some wxBase dependencies: wxMutex, wxFileExists, wxStandardPaths, wxGetLocalTimeMillis
0.8
s_nakamoto 15 years ago
parent
commit
a280b4e661
  1. 4
      headers.h
  2. 64
      init.cpp
  3. BIN
      locale/de/LC_MESSAGES/bitcoin.mo
  4. 4
      locale/de/LC_MESSAGES/bitcoin.po
  5. BIN
      locale/it/LC_MESSAGES/bitcoin.mo
  6. 4
      locale/it/LC_MESSAGES/bitcoin.po
  7. BIN
      locale/nl/LC_MESSAGES/bitcoin.mo
  8. 4
      locale/nl/LC_MESSAGES/bitcoin.po
  9. 26
      main.cpp
  10. 6
      makefile.unix
  11. 10
      rpc.cpp
  12. 2
      serialize.h
  13. 2
      uibase.cpp
  14. 2
      uibase.h
  15. 4
      uiproject.fbp
  16. 80
      util.cpp
  17. 18
      util.h

4
headers.h

@ -59,6 +59,10 @@ @@ -59,6 +59,10 @@
#include <boost/function.hpp>
#include <boost/filesystem.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__
#include <windows.h>

64
init.cpp

@ -4,6 +4,8 @@ @@ -4,6 +4,8 @@
#include "headers.h"
extern string GetDefaultDataDir(); /// todo: delete this later, just used by debug test
@ -59,40 +61,6 @@ void Shutdown(void* parg) @@ -59,40 +61,6 @@ void Shutdown(void* parg)
//
#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()
{
return MyGetSpecialFolderPath(CSIDL_STARTUP, true) + "\\Bitcoin.lnk";
@ -100,7 +68,7 @@ string StartupShortcutPath() @@ -100,7 +68,7 @@ string StartupShortcutPath()
bool GetStartOnSystemStartup()
{
return wxFileExists(StartupShortcutPath());
return filesystem::exists(StartupShortcutPath().c_str());
}
void SetStartOnSystemStartup(bool fAutoStart)
@ -166,7 +134,7 @@ void SetStartOnSystemStartup(bool fAutoStart) { } @@ -166,7 +134,7 @@ void SetStartOnSystemStartup(bool fAutoStart) { }
//
// Define a new application
class CMyApp: public wxApp
class CMyApp : public wxApp
{
public:
wxLocale m_locale;
@ -216,7 +184,10 @@ bool CMyApp::Initialize(int& argc, wxChar** argv) @@ -216,7 +184,10 @@ bool CMyApp::Initialize(int& argc, wxChar** argv)
#ifdef __WXMSW__
if (str.size() >= 1 && str[0] == '/')
str[0] = '-';
str = str.MakeLower();
char pszLower[MAX_PATH];
strlcpy(pszLower, str.c_str(), sizeof(pszLower));
strlwr(pszLower);
str = pszLower;
#endif
// haven't decided which argument to use for this yet
if (str == "-daemon" || str == "-d" || str == "start")
@ -356,18 +327,14 @@ bool CMyApp::OnInit2() @@ -356,18 +327,14 @@ bool CMyApp::OnInit2()
" -daemon \t " + _("Run in the background as a daemon and accept commands\n") +
" -? \t " + _("This help message\n");
if (fWindows && fGUI)
{
#if defined(__WXMSW__) && wxUSE_GUI
// Tabs make the columns line up in the message box
wxMessageBox(strUsage, "Bitcoin", wxOK);
}
else
{
#else
// Remove tabs
strUsage.Replace("\t", "");
fprintf(stderr, "%s", ((string)strUsage).c_str());
}
#endif
return false;
}
@ -387,6 +354,15 @@ bool CMyApp::OnInit2() @@ -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("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"))
{
CTxDB txdb("r");

BIN
locale/de/LC_MESSAGES/bitcoin.mo

Binary file not shown.

4
locale/de/LC_MESSAGES/bitcoin.po

@ -692,6 +692,8 @@ msgstr "Version" @@ -692,6 +692,8 @@ msgstr "Version"
msgid ""
"Copyright (c) 2009-2010 Satoshi Nakamoto.\n"
"\n"
"This is experimental software.\n"
"\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"
"\n"
@ -701,6 +703,8 @@ msgid "" @@ -701,6 +703,8 @@ msgid ""
msgstr ""
"Copyright (c) 2009-2010 Satoshi Nakamoto.\n"
"\n"
"Dies ist experimentelle Software.\n"
"\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"
"\n"

BIN
locale/it/LC_MESSAGES/bitcoin.mo

Binary file not shown.

4
locale/it/LC_MESSAGES/bitcoin.po

@ -690,6 +690,8 @@ msgstr "versione" @@ -690,6 +690,8 @@ msgstr "versione"
msgid ""
"Copyright (c) 2009-2010 Satoshi Nakamoto.\n"
"\n"
"This is experimental software.\n"
"\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"
"\n"
@ -699,6 +701,8 @@ msgid "" @@ -699,6 +701,8 @@ msgid ""
msgstr ""
"Copyright (c) 2009-2010 Satoshi Nakamoto.\n"
"\n"
"Questo è un software sperimentale.\n"
"\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"
"\n"

BIN
locale/nl/LC_MESSAGES/bitcoin.mo

Binary file not shown.

4
locale/nl/LC_MESSAGES/bitcoin.po

@ -691,6 +691,8 @@ msgstr "versie" @@ -691,6 +691,8 @@ msgstr "versie"
msgid ""
"Copyright (c) 2009-2010 Satoshi Nakamoto.\n"
"\n"
"This is experimental software.\n"
"\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"
"\n"
@ -700,6 +702,8 @@ msgid "" @@ -700,6 +702,8 @@ msgid ""
msgstr ""
"Copyright (c) 2009-2010 Satoshi Nakamoto.\n"
"\n"
"Dit is experimentele software.\n"
"\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"
"\n"

26
main.cpp

@ -1477,7 +1477,10 @@ bool CheckDiskSpace(int64 nAdditionalBytes) @@ -1477,7 +1477,10 @@ bool CheckDiskSpace(int64 nAdditionalBytes)
if (nFreeBytesAvailable < (int64)15000000 + nAdditionalBytes)
{
fShutdown = true;
printf("*** %s***\n", _("Warning: Disk space is low "));
#if wxUSE_GUI
ThreadSafeMessageBox(_("Warning: Disk space is low "), "Bitcoin", wxOK | wxICON_EXCLAMATION);
#endif
CreateThread(Shutdown, NULL);
return false;
}
@ -2713,16 +2716,21 @@ void BitcoinMiner() @@ -2713,16 +2716,21 @@ void BitcoinMiner()
if ((++tmp.block.nNonce & nMask) == 0)
{
// Meter hashes/sec
static int64 nHashCounter;
static int64 nLastTick;
if (nLastTick == 0)
nLastTick = GetTimeMillis();
static int64 nTimerStart;
static int nHashCounter;
if (nTimerStart == 0)
nTimerStart = GetTimeMillis();
else
nHashCounter += nMask + 1;
if (GetTimeMillis() - nLastTick > 4000)
nHashCounter++;
if (GetTimeMillis() - nTimerStart > 4000)
{
double dHashesPerSec = 1000.0 * nHashCounter / (GetTimeMillis() - nLastTick);
nLastTick = GetTimeMillis();
static CCriticalSection cs;
CRITICAL_BLOCK(cs)
{
if (GetTimeMillis() - nTimerStart > 4000)
{
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));
@ -2734,6 +2742,8 @@ void BitcoinMiner() @@ -2734,6 +2742,8 @@ void BitcoinMiner()
printf("hashmeter %3d CPUs %6.0f khash/s\n", vnThreadsRunning[3], dHashesPerSec/1000.0);
}
}
}
}
// Check for stop or if block needs to be rebuilt
if (fShutdown)

6
makefile.unix

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

10
rpc.cpp

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

2
serialize.h

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

2
uibase.cpp

@ -554,7 +554,7 @@ CAboutDialogBase::CAboutDialogBase( wxWindow* parent, wxWindowID id, const wxStr @@ -554,7 +554,7 @@ CAboutDialogBase::CAboutDialogBase( wxWindow* parent, wxWindowID id, const wxStr
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 );
bSizer631->Add( m_staticTextMain, 0, wxALL, 5 );

2
uibase.h

@ -227,7 +227,7 @@ class CAboutDialogBase : public wxDialog @@ -227,7 +227,7 @@ class CAboutDialogBase : public wxDialog
public:
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();
};

4
uiproject.fbp

@ -2866,7 +2866,7 @@ @@ -2866,7 +2866,7 @@
<property name="minimum_size"></property>
<property name="name">CAboutDialogBase</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="subclass"></property>
<property name="title">About Bitcoin</property>
@ -3130,7 +3130,7 @@ @@ -3130,7 +3130,7 @@
<property name="font"></property>
<property name="hidden">0</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="minimum_size"></property>
<property name="name">m_staticTextMain</property>

80
util.cpp

@ -20,13 +20,13 @@ bool fCommandLine = false; @@ -20,13 +20,13 @@ bool fCommandLine = false;
// 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)
{
if (mode & CRYPTO_LOCK)
ppmutexOpenSSL[i]->Lock();
ppmutexOpenSSL[i]->lock();
else
ppmutexOpenSSL[i]->Unlock();
ppmutexOpenSSL[i]->unlock();
}
// Init
@ -36,9 +36,9 @@ public: @@ -36,9 +36,9 @@ public:
CInit()
{
// 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++)
ppmutexOpenSSL[i] = new wxMutex();
ppmutexOpenSSL[i] = new boost::interprocess::interprocess_mutex();
CRYPTO_set_locking_callback(locking_callback);
#ifdef __WXMSW__
@ -152,7 +152,7 @@ inline int OutputDebugStringF(const char* pszFormat, ...) @@ -152,7 +152,7 @@ inline int OutputDebugStringF(const char* pszFormat, ...)
if (fileout)
{
//// Debug print useful for profiling
//fprintf(fileout, " %"PRI64d" ", wxGetLocalTimeMillis().GetValue());
//fprintf(fileout, " %"PRI64d" ", GetTimeMillis());
va_list arg_ptr;
va_start(arg_ptr, pszFormat);
ret = vfprintf(fileout, pszFormat, arg_ptr);
@ -521,6 +521,69 @@ void PrintException(std::exception* pex, const char* pszThread) @@ -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)
{
// pszDir must be at least MAX_PATH length.
@ -538,11 +601,6 @@ void GetDataDir(char* pszDir) @@ -538,11 +601,6 @@ void GetDataDir(char* pszDir)
{
// This can be called during exceptions by printf, so we cache the
// 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];
if (pszCachedDir[0] == 0)
{

18
util.h

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

Loading…
Cancel
Save