Fixed cppcheck issues

pull/226/head
SChernykh 1 year ago
parent a61966ed61
commit dffc8bcea0

@ -1,3 +1,4 @@
unmatchedSuppression
missingIncludeSystem missingIncludeSystem
unusedFunction unusedFunction
useStlAlgorithm useStlAlgorithm

@ -145,7 +145,7 @@ struct BlockCache::Impl : public nocopy_nomove
#else #else
// Not implemented on other platforms // Not implemented on other platforms
void flush() {} void flush() { m_data = nullptr; }
#endif #endif
uint8_t* m_data = nullptr; uint8_t* m_data = nullptr;
@ -155,6 +155,7 @@ BlockCache::BlockCache()
: m_impl(new Impl()) : m_impl(new Impl())
, m_flushRunning(0) , m_flushRunning(0)
, m_storeIndex(0) , m_storeIndex(0)
, m_loadingStarted(0)
{ {
} }
@ -188,6 +189,11 @@ void BlockCache::load_all(SideChain& side_chain, P2PServer& server)
return; return;
} }
// Can be only called once
if (m_loadingStarted.exchange(1)) {
return;
}
LOGINFO(1, "loading cached blocks"); LOGINFO(1, "loading cached blocks");
PoolBlock block; PoolBlock block;
@ -212,7 +218,7 @@ void BlockCache::load_all(SideChain& side_chain, P2PServer& server)
void BlockCache::flush() void BlockCache::flush()
{ {
if (m_flushRunning.exchange(1) == 0) { if (m_flushRunning.exchange(1)) {
m_impl->flush(); m_impl->flush();
m_flushRunning.store(0); m_flushRunning.store(0);
} }

@ -38,6 +38,7 @@ private:
Impl* m_impl; Impl* m_impl;
std::atomic<uint32_t> m_flushRunning; std::atomic<uint32_t> m_flushRunning;
std::atomic<uint32_t> m_storeIndex; std::atomic<uint32_t> m_storeIndex;
std::atomic<uint32_t> m_loadingStarted;
}; };
} // namespace p2pool } // namespace p2pool

@ -321,6 +321,7 @@ static Worker worker;
NOINLINE Writer::Writer(Severity severity) : Stream(m_stackBuf) NOINLINE Writer::Writer(Severity severity) : Stream(m_stackBuf)
{ {
m_stackBuf[BUF_SIZE] = '\0';
m_buf[0] = static_cast<char>(severity); m_buf[0] = static_cast<char>(severity);
m_pos = 3; m_pos = 3;

@ -35,7 +35,7 @@ class p2pool_api;
class ZMQReader; class ZMQReader;
struct PoolBlock; struct PoolBlock;
class p2pool : public MinerCallbackHandler class p2pool : public MinerCallbackHandler, public nocopy_nomove
{ {
public: public:
p2pool(int argc, char* argv[]); p2pool(int argc, char* argv[]);

@ -2024,7 +2024,7 @@ bool SideChain::load_config(const std::string& filename)
return true; return true;
} }
bool SideChain::check_config() bool SideChain::check_config() const
{ {
if (m_poolName.empty()) { if (m_poolName.empty()) {
LOGERR(1, "name can't be empty"); LOGERR(1, "name can't be empty");

@ -99,7 +99,7 @@ private:
void prune_old_blocks(); void prune_old_blocks();
bool load_config(const std::string& filename); bool load_config(const std::string& filename);
bool check_config(); bool check_config() const;
mutable uv_rwlock_t m_sidechainLock; mutable uv_rwlock_t m_sidechainLock;
std::atomic<PoolBlock*> m_chainTip; std::atomic<PoolBlock*> m_chainTip;

Loading…
Cancel
Save