From 12c18b9ba50da63bc965f8d7584250e619ce62db Mon Sep 17 00:00:00 2001 From: enWILLYado Date: Sun, 18 Feb 2018 17:23:03 +0100 Subject: [PATCH] Improve unix compilation --- src/api/NetworkState.h | 1 + src/crypto/CryptoNight.h | 1 + src/crypto/CryptoNight_x86.h | 4 ++-- src/crypto/soft_aes.h | 2 +- src/interfaces/IConsoleListener.h | 1 + src/interfaces/interface.h | 8 +++++--- src/log/Log.h | 19 ++++++++++--------- src/net/Url.h | 2 ++ src/workers/DoubleWorker.cpp | 3 ++- src/workers/Handle.h | 1 + src/workers/SingleWorker.cpp | 3 ++- src/workers/Workers.h | 1 + 12 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/api/NetworkState.h b/src/api/NetworkState.h index e8160997..dfbe6c2d 100644 --- a/src/api/NetworkState.h +++ b/src/api/NetworkState.h @@ -27,6 +27,7 @@ #include #include +#include class SubmitResult; diff --git a/src/crypto/CryptoNight.h b/src/crypto/CryptoNight.h index b4a88cff..d57474d8 100644 --- a/src/crypto/CryptoNight.h +++ b/src/crypto/CryptoNight.h @@ -28,6 +28,7 @@ #include #include +#include "interfaces/interface.h" #include "align.h" diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index 12dd0524..33899a5d 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -75,7 +75,7 @@ void (* const extra_hashes[4])(const void*, size_t, char*) = {do_blake_hash, do_ -#if defined(__x86_64__) || defined(_M_AMD64) +#if (defined(__x86_64__) || defined(_M_AMD64)) && __cplusplus > 199711L # define EXTRACT64(X) _mm_cvtsi128_si64(X) # ifdef __GNUC__ @@ -88,7 +88,7 @@ static inline uint64_t __umul128(uint64_t a, uint64_t b, uint64_t* hi) # else #define __umul128 _umul128 # endif -#elif defined(__i386__) || defined(_M_IX86) +#elif defined(__i386__) || defined(_M_IX86) || __cplusplus <= 199711L # define HI32(X) \ _mm_srli_si128((X), 4) diff --git a/src/crypto/soft_aes.h b/src/crypto/soft_aes.h index 7fa5fb25..50f301f6 100644 --- a/src/crypto/soft_aes.h +++ b/src/crypto/soft_aes.h @@ -117,7 +117,7 @@ static inline uint32_t sub_word(uint32_t key) saes_sbox[key & 0xff]; } -#if defined(__clang__) || defined(XMRIG_ARM) +#if defined(__clang__) || defined(XMRIG_ARM) || __cplusplus <= 199711L static inline uint32_t _rotr(uint32_t value, uint32_t amount) { return (value >> amount) | (value << ((32 - amount) & 31)); diff --git a/src/interfaces/IConsoleListener.h b/src/interfaces/IConsoleListener.h index 51aaf50c..af624ace 100644 --- a/src/interfaces/IConsoleListener.h +++ b/src/interfaces/IConsoleListener.h @@ -24,6 +24,7 @@ #ifndef __ICONSOLELISTENER_H__ #define __ICONSOLELISTENER_H__ +#include "interfaces/interface.h" class IConsoleListener { diff --git a/src/interfaces/interface.h b/src/interfaces/interface.h index 25c76abc..987b75d4 100644 --- a/src/interfaces/interface.h +++ b/src/interfaces/interface.h @@ -16,12 +16,14 @@ #ifndef __INTERFACE_H__ #define __INTERFACE_H__ +#if __cplusplus <= 199711L +#define override +#define nullptr NULL +#endif + #ifdef _WIN32 #if defined(_MSC_VER) && _MSC_VER < 1900 -// C++-11 -#define override - // VS #include #include diff --git a/src/log/Log.h b/src/log/Log.h index 41b0fdef..adf30021 100644 --- a/src/log/Log.h +++ b/src/log/Log.h @@ -89,9 +89,10 @@ public: static inline std::string TO_STRING(const std::basic_ostream & i) { - const std::stringstream & stream = static_cast(i); + const std::ostringstream & stream = static_cast(i); return stream.str(); } + private: inline Log() {} ~Log(); @@ -101,22 +102,22 @@ private: }; -#define PRINT_MSG(x) Log::i()->text(Log::TO_STRING(std::stringstream() << x)) +#define PRINT_MSG(x) Log::i()->text(Log::TO_STRING(std::ostringstream() << " " << x)) -#define LOG_ERR(x) Log::i()->message(ILogBackend::ERR, Log::TO_STRING(std::stringstream() << x)) -#define LOG_WARN(x) Log::i()->message(ILogBackend::WARNING, Log::TO_STRING(std::stringstream() << x)) -#define LOG_NOTICE(x) Log::i()->message(ILogBackend::NOTICE, Log::TO_STRING(std::stringstream() << x)) -#define LOG_INFO(x) Log::i()->message(ILogBackend::INFO, Log::TO_STRING(std::stringstream() << x)) +#define LOG_ERR(x) Log::i()->message(ILogBackend::ERR, Log::TO_STRING(std::ostringstream() << " " << x)) +#define LOG_WARN(x) Log::i()->message(ILogBackend::WARNING, Log::TO_STRING(std::ostringstream() << " " << x)) +#define LOG_NOTICE(x) Log::i()->message(ILogBackend::NOTICE, Log::TO_STRING(std::ostringstream() << " " << x)) +#define LOG_INFO(x) Log::i()->message(ILogBackend::INFO, Log::TO_STRING(std::ostringstream() << " " << x)) #ifdef APP_DEBUG -#define LOG_DEBUG(x) Log::i()->message(ILogBackend::DEBUG, Log::TO_STRING(std::stringstream() << x)) +#define LOG_DEBUG(x) Log::i()->message(ILogBackend::DEBUG, Log::TO_STRING(std::ostringstream() << " " << x)) #else #define LOG_DEBUG(x) #endif #if defined(APP_DEBUG) || defined(APP_DEVEL) -#define LOG_DEBUG_ERR(x) Log::i()->message(ILogBackend::ERR, Log::TO_STRING(std::stringstream() << x)) -#define LOG_DEBUG_WARN(x) Log::i()->message(ILogBackend::WARNING, Log::TO_STRING(std::stringstream() << x)) +#define LOG_DEBUG_ERR(x) Log::i()->message(ILogBackend::ERR, Log::TO_STRING(std::ostringstream() << " " << x)) +#define LOG_DEBUG_WARN(x) Log::i()->message(ILogBackend::WARNING, Log::TO_STRING(std::ostringstream() << " " << x)) #else #define LOG_DEBUG_ERR(x) #define LOG_DEBUG_WARN(x) diff --git a/src/net/Url.h b/src/net/Url.h index 9e0b9257..2b01e0f8 100644 --- a/src/net/Url.h +++ b/src/net/Url.h @@ -28,6 +28,8 @@ #include +#include "interfaces/interface.h" + class Url { public: diff --git a/src/workers/DoubleWorker.cpp b/src/workers/DoubleWorker.cpp index 9992d679..7ea6e3f8 100644 --- a/src/workers/DoubleWorker.cpp +++ b/src/workers/DoubleWorker.cpp @@ -27,6 +27,7 @@ #ifndef _WIN32 #include +#include #endif class DoubleWorker::State @@ -70,7 +71,7 @@ void DoubleWorker::start() #ifdef _WIN32 Sleep(200); #else - std::this_thread::sleep_for(std::chrono::milliseconds(200)); + usleep(200 * 1000); #endif } while(Workers::isPaused()); diff --git a/src/workers/Handle.h b/src/workers/Handle.h index f95dfdda..5479b26d 100644 --- a/src/workers/Handle.h +++ b/src/workers/Handle.h @@ -28,6 +28,7 @@ #include #include +#include "interfaces/interface.h" class IWorker; diff --git a/src/workers/SingleWorker.cpp b/src/workers/SingleWorker.cpp index e359b2ed..48fdd4b1 100644 --- a/src/workers/SingleWorker.cpp +++ b/src/workers/SingleWorker.cpp @@ -27,6 +27,7 @@ #ifndef _WIN32 #include +#include #endif SingleWorker::SingleWorker(Handle* handle) @@ -46,7 +47,7 @@ void SingleWorker::start() #ifdef _WIN32 Sleep(200); #else - std::this_thread::sleep_for(std::chrono::milliseconds(200)); + usleep(200 * 1000); #endif } while(Workers::isPaused()); diff --git a/src/workers/Workers.h b/src/workers/Workers.h index e2ee5d65..333558ed 100644 --- a/src/workers/Workers.h +++ b/src/workers/Workers.h @@ -31,6 +31,7 @@ #include "net/Job.h" #include "net/JobResult.h" +#include "interfaces/interface.h" class Handle; class Hashrate;