bunch of changes
This commit is contained in:
83
src/util.cpp
83
src/util.cpp
@@ -3,14 +3,23 @@
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "util.h"
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
#include <config/bitcoin-config.h>
|
||||
#endif
|
||||
|
||||
#include "chainparamsbase.h"
|
||||
#include "random.h"
|
||||
#include "serialize.h"
|
||||
#include "sync.h"
|
||||
#include "utilstrencodings.h"
|
||||
#include "utiltime.h"
|
||||
#include <util.h>
|
||||
|
||||
#include <chainparamsbase.h>
|
||||
#include <main.h>
|
||||
#include <miner.h>
|
||||
#include <net.h>
|
||||
#include <random.h>
|
||||
#include <serialize.h>
|
||||
#include <sync.h>
|
||||
#include <utilstrencodings.h>
|
||||
#include <utiltime.h>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
@@ -36,6 +45,10 @@
|
||||
#include <sys/resource.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
// We need this for __getch function
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#else
|
||||
|
||||
#ifdef _MSC_VER
|
||||
@@ -62,6 +75,10 @@
|
||||
|
||||
#include <io.h> /* for _commit */
|
||||
#include <shlobj.h>
|
||||
|
||||
// We need this for ReadConsoleA
|
||||
// and other windows cli functions
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_PRCTL_H
|
||||
@@ -73,7 +90,6 @@
|
||||
#include <boost/algorithm/string/predicate.hpp> // for startswith() and endswith()
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/program_options/detail/config_file.hpp>
|
||||
#include <boost/program_options/parsers.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
@@ -188,8 +204,8 @@ static boost::once_flag debugPrintInitFlag = BOOST_ONCE_INIT;
|
||||
* the OS/libc. When the shutdown sequence is fully audited and
|
||||
* tested, explicit destruction of these objects can be implemented.
|
||||
*/
|
||||
static FILE* fileout = NULL;
|
||||
static boost::mutex* mutexDebugLog = NULL;
|
||||
static FILE* fileout = nullptr;
|
||||
static boost::mutex* mutexDebugLog = nullptr;
|
||||
static list<string> *vMsgsBeforeOpenLog;
|
||||
|
||||
static int FileWriteStr(const std::string &str, FILE *fp)
|
||||
@@ -199,7 +215,7 @@ static int FileWriteStr(const std::string &str, FILE *fp)
|
||||
|
||||
static void DebugPrintInit()
|
||||
{
|
||||
assert(mutexDebugLog == NULL);
|
||||
assert(mutexDebugLog == nullptr);
|
||||
mutexDebugLog = new boost::mutex();
|
||||
vMsgsBeforeOpenLog = new list<string>;
|
||||
}
|
||||
@@ -209,11 +225,11 @@ void OpenDebugLog()
|
||||
boost::call_once(&DebugPrintInit, debugPrintInitFlag);
|
||||
boost::mutex::scoped_lock scoped_lock(*mutexDebugLog);
|
||||
|
||||
assert(fileout == NULL);
|
||||
assert(fileout == nullptr);
|
||||
assert(vMsgsBeforeOpenLog);
|
||||
boost::filesystem::path pathDebug = GetDataDir() / "debug.log";
|
||||
fileout = fopen(pathDebug.string().c_str(), "a");
|
||||
if (fileout) setbuf(fileout, NULL); // unbuffered
|
||||
if (fileout) setbuf(fileout, nullptr); // unbuffered
|
||||
|
||||
// dump buffered messages from before we opened the log
|
||||
while (!vMsgsBeforeOpenLog->empty()) {
|
||||
@@ -222,12 +238,12 @@ void OpenDebugLog()
|
||||
}
|
||||
|
||||
delete vMsgsBeforeOpenLog;
|
||||
vMsgsBeforeOpenLog = NULL;
|
||||
vMsgsBeforeOpenLog = nullptr;
|
||||
}
|
||||
|
||||
bool LogAcceptCategory(const char* category)
|
||||
{
|
||||
if (category != NULL)
|
||||
if (category != nullptr)
|
||||
{
|
||||
if (!fDebug)
|
||||
return false;
|
||||
@@ -237,7 +253,7 @@ bool LogAcceptCategory(const char* category)
|
||||
// where mapMultiArgs might be deleted before another
|
||||
// global destructor calls LogPrint()
|
||||
static boost::thread_specific_ptr<set<string> > ptrCategory;
|
||||
if (ptrCategory.get() == NULL)
|
||||
if (ptrCategory.get() == nullptr)
|
||||
{
|
||||
const vector<string>& categories = mapMultiArgs["-debug"];
|
||||
ptrCategory.reset(new set<string>(categories.begin(), categories.end()));
|
||||
@@ -251,6 +267,7 @@ bool LogAcceptCategory(const char* category)
|
||||
setCategories.count(string(category)) == 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -302,7 +319,7 @@ int LogPrintStr(const std::string &str)
|
||||
boost::mutex::scoped_lock scoped_lock(*mutexDebugLog);
|
||||
|
||||
// buffer if we haven't opened the log yet
|
||||
if (fileout == NULL) {
|
||||
if (fileout == nullptr) {
|
||||
assert(vMsgsBeforeOpenLog);
|
||||
ret = strTimestamped.length();
|
||||
vMsgsBeforeOpenLog->push_back(strTimestamped);
|
||||
@@ -313,8 +330,8 @@ int LogPrintStr(const std::string &str)
|
||||
if (fReopenDebugLog) {
|
||||
fReopenDebugLog = false;
|
||||
boost::filesystem::path pathDebug = GetDataDir() / "debug.log";
|
||||
if (freopen(pathDebug.string().c_str(),"a",fileout) != NULL)
|
||||
setbuf(fileout, NULL); // unbuffered
|
||||
if (freopen(pathDebug.string().c_str(),"a",fileout) != nullptr)
|
||||
setbuf(fileout, nullptr); // unbuffered
|
||||
}
|
||||
|
||||
ret = FileWriteStr(strTimestamped, fileout);
|
||||
@@ -532,14 +549,14 @@ void ReadConfigFile(map<string, string>& mapSettingsRet,
|
||||
{
|
||||
boost::filesystem::ifstream streamConfig(GetConfigFile());
|
||||
if (!streamConfig.good())
|
||||
return; // No bitcoin.conf file is OK
|
||||
return; // No blackmore.conf file is OK
|
||||
|
||||
set<string> setOptions;
|
||||
setOptions.insert("*");
|
||||
|
||||
for (boost::program_options::detail::config_file_iterator it(streamConfig, setOptions), end; it != end; ++it)
|
||||
{
|
||||
// Don't overwrite existing settings so command line settings override bitcoin.conf
|
||||
// Don't overwrite existing settings so command line settings override blackmore.conf
|
||||
string strKey = string("-") + it->string_key;
|
||||
string strValue = it->value[0];
|
||||
InterpretNegativeSetting(strKey, strValue);
|
||||
@@ -600,19 +617,19 @@ bool TryCreateDirectory(const boost::filesystem::path& p)
|
||||
return false;
|
||||
}
|
||||
|
||||
void FileCommit(FILE *fileout)
|
||||
void FileCommit(FILE *file)
|
||||
{
|
||||
fflush(fileout); // harmless if redundantly called
|
||||
fflush(file); // harmless if redundantly called
|
||||
#ifdef WIN32
|
||||
HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(fileout));
|
||||
HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(file));
|
||||
FlushFileBuffers(hFile);
|
||||
#else
|
||||
#if defined(__linux__) || defined(__NetBSD__)
|
||||
fdatasync(fileno(fileout));
|
||||
fdatasync(fileno(file));
|
||||
#elif defined(__APPLE__) && defined(F_FULLFSYNC)
|
||||
fcntl(fileno(fileout), F_FULLFSYNC, 0);
|
||||
fcntl(fileno(file), F_FULLFSYNC, 0);
|
||||
#else
|
||||
fsync(fileno(fileout));
|
||||
fsync(fileno(file));
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
@@ -714,7 +731,7 @@ void ShrinkDebugFile()
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
else if (file != NULL)
|
||||
else if (file != nullptr)
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
@@ -791,15 +808,17 @@ bool SetupNetworking()
|
||||
|
||||
void SetThreadPriority(int nPriority)
|
||||
{
|
||||
// It's unclear if it's even possible to change thread priorities on Linux,
|
||||
// but we really and truly need it for the generation threads.
|
||||
#ifdef WIN32
|
||||
SetThreadPriority(GetCurrentThread(), nPriority);
|
||||
#else // WIN32
|
||||
#else
|
||||
#ifdef PRIO_THREAD
|
||||
setpriority(PRIO_THREAD, 0, nPriority);
|
||||
#else // PRIO_THREAD
|
||||
#else
|
||||
setpriority(PRIO_PROCESS, 0, nPriority);
|
||||
#endif // PRIO_THREAD
|
||||
#endif // WIN32
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
int GetNumCores()
|
||||
|
||||
Reference in New Issue
Block a user