From 02f19713355e01b5e680dd7ebde490a0bebc8578 Mon Sep 17 00:00:00 2001 From: fchn289 Date: Tue, 30 Jul 2024 20:29:25 +0800 Subject: [PATCH] using std: not hpp but cpp --- src/domino/DataDomino.hpp | 4 +- src/domino/Domino.cpp | 2 + src/domino/Domino.hpp | 22 +++++----- src/domino/FreeHdlrDomino.hpp | 2 +- src/domino/HdlrDomino.hpp | 4 +- src/domino/MultiHdlrDomino.hpp | 8 ++-- src/domino/PriDomino.hpp | 2 +- src/domino/RmEvDom.hpp | 4 +- src/domino/WbasicDatDom.hpp | 6 +-- src/log/StrCoutFSL.hpp | 8 ++-- src/log/UniBaseLog.hpp | 14 +++---- src/log/UniCoutLog.cpp | 2 + src/log/UniCoutLog.hpp | 8 ++-- src/log/UniSmartLog.cpp | 2 + src/log/UniSmartLog.hpp | 8 ++-- src/msg_self/MsgSelf.hpp | 10 ++--- src/obj_anywhere/DataStore.hpp | 6 +-- src/obj_anywhere/ObjAnywhere.cpp | 2 + src/obj_anywhere/ObjAnywhere.hpp | 6 +-- src/safe_mem/SafePtr.hpp | 63 ++++++++++++++--------------- src/safe_mem/UniPtr.hpp | 2 - src/thread/AsyncBack.cpp | 2 + src/thread/AsyncBack.hpp | 2 - src/thread/MT_Semaphore.hpp | 4 +- src/thread/MtInQueue.cpp | 2 + src/thread/MtInQueue.hpp | 28 ++++++------- src/thread/ThPoolBack.cpp | 2 + src/thread/ThPoolBack.hpp | 12 +++--- src/thread/ThreadBack.cpp | 2 + src/thread/ThreadBack.hpp | 12 +++--- src/thread/ThreadBackViaMsgSelf.hpp | 2 +- ut/log/UniLogTest.hpp | 1 + ut/msg_self/MsgSelfTest.cpp | 3 +- ut/obj_anywhere/DataStoreTest.cpp | 1 + ut/thread/MtInQueueTest.cpp | 1 + ut/thread/ThreadBackTest.hpp | 4 +- 36 files changed, 126 insertions(+), 137 deletions(-) diff --git a/src/domino/DataDomino.hpp b/src/domino/DataDomino.hpp index d819cd2..f1b1740 100644 --- a/src/domino/DataDomino.hpp +++ b/src/domino/DataDomino.hpp @@ -15,8 +15,6 @@ #include "DataStore.hpp" #include "UniLog.hpp" -using namespace std; - namespace RLib { // *********************************************************************************************** @@ -82,7 +80,7 @@ void DataDomino::rmEv_(const Domino::Event& aValidEv) template auto getData(aDataDominoType& aDom, const Domino::EvName& aEvName) { - return static_pointer_cast(aDom.getData(aEvName)); + return std::static_pointer_cast(aDom.getData(aEvName)); } // *********************************************************************************************** diff --git a/src/domino/Domino.cpp b/src/domino/Domino.cpp index d609635..98e86cc 100644 --- a/src/domino/Domino.cpp +++ b/src/domino/Domino.cpp @@ -7,6 +7,8 @@ #include "Domino.hpp" +using namespace std; + namespace RLib { static const Domino::Events defaultEVs; // internal use only diff --git a/src/domino/Domino.hpp b/src/domino/Domino.hpp index b631536..d3f959f 100644 --- a/src/domino/Domino.hpp +++ b/src/domino/Domino.hpp @@ -63,11 +63,11 @@ class Domino : public UniLog { public: using Event = size_t; // smaller size can save mem; larger size can support more events - using Events = set; - using EvName = string; - using SimuEvents = map; // not unordered-map since most traversal - using EvNames = unordered_map; // map is less mem than vector - using EvLinks = map; + using Events = std::set; + using EvName = std::string; + using SimuEvents = std::map; // not unordered-map since most traversal + using EvNames = std::unordered_map; // map is less mem than vector + using EvLinks = std::map; enum : Event { @@ -122,13 +122,13 @@ class Domino : public UniLog static const Events& findPeerEVs(const Event&, const EvLinks&); // ------------------------------------------------------------------------------------------- - vector states_; // bitmap & dyn expand, [event]=t/f + std::vector states_; // bitmap & dyn expand, [event]=t/f - EvLinks prev_[N_EVENT_STATE]; // not unordered-map since most traversal - EvLinks next_[N_EVENT_STATE]; // not unordered-map since most traversal - unordered_map en_ev_; // [evName]=event - EvNames ev_en_; // [event]=evName for easy debug - unordered_set effectEVs_; + EvLinks prev_[N_EVENT_STATE]; // not unordered-map since most traversal + EvLinks next_[N_EVENT_STATE]; // not unordered-map since most traversal + std::unordered_map en_ev_; // [evName]=event + EvNames ev_en_; // [event]=evName for easy debug + std::unordered_set effectEVs_; }; } // namespace diff --git a/src/domino/FreeHdlrDomino.hpp b/src/domino/FreeHdlrDomino.hpp index d101e55..438727d 100644 --- a/src/domino/FreeHdlrDomino.hpp +++ b/src/domino/FreeHdlrDomino.hpp @@ -43,7 +43,7 @@ class FreeHdlrDomino : public aDominoType private: // - bitmap & dyn expand, [event]=t/f // - don't know if repeated hdlrs are much less than non-repeated, so bitmap is simpler than set - vector isRepeatHdlr_; + std::vector isRepeatHdlr_; public: using aDominoType::oneLog; }; diff --git a/src/domino/HdlrDomino.hpp b/src/domino/HdlrDomino.hpp index e85cce8..5f23641 100644 --- a/src/domino/HdlrDomino.hpp +++ b/src/domino/HdlrDomino.hpp @@ -68,7 +68,7 @@ class HdlrDomino : public aDominoType // ------------------------------------------------------------------------------------------- private: - unordered_map ev_hdlr_S_; + std::unordered_map ev_hdlr_S_; protected: SafePtr msgSelf_ = ObjAnywhere::getObj(); public: @@ -166,7 +166,7 @@ Domino::Event HdlrDomino::setHdlr(const Domino::EvName& aEvName, co } // set - auto newHdlr = make_shared(aHdlr); + auto newHdlr = std::make_shared(aHdlr); ev_hdlr_S_.emplace(newEv, newHdlr); HID("(HdlrDom) Succeed for EvName=" << aEvName); diff --git a/src/domino/MultiHdlrDomino.hpp b/src/domino/MultiHdlrDomino.hpp index daf3098..434439c 100644 --- a/src/domino/MultiHdlrDomino.hpp +++ b/src/domino/MultiHdlrDomino.hpp @@ -32,8 +32,8 @@ template class MultiHdlrDomino : public aDominoType { public: - using HdlrName = string; - using HName_Hdlr_S = map; + using HdlrName = std::string; + using HName_Hdlr_S = std::map; explicit MultiHdlrDomino(const LogName& aUniLogName = ULN_DEFAULT) : aDominoType(aUniLogName) {} @@ -56,7 +56,7 @@ class MultiHdlrDomino : public aDominoType private: // ------------------------------------------------------------------------------------------- - unordered_map ev_hdlrs_S_; + std::unordered_map ev_hdlrs_S_; public: using aDominoType::oneLog; }; @@ -96,7 +96,7 @@ Domino::Event MultiHdlrDomino::multiHdlrOnSameEv(const Domino::EvNa } // set hdlr - auto&& newHdlr = make_shared(aHdlr); + auto&& newHdlr = std::make_shared(aHdlr); auto&& ev = this->getEventBy(aEvName); auto&& ev_hdlrs = ev_hdlrs_S_.find(ev); if (ev_hdlrs == ev_hdlrs_S_.end()) diff --git a/src/domino/PriDomino.hpp b/src/domino/PriDomino.hpp index ac79931..9fb4d4a 100644 --- a/src/domino/PriDomino.hpp +++ b/src/domino/PriDomino.hpp @@ -37,7 +37,7 @@ class PriDomino : public aDominoType private: // ------------------------------------------------------------------------------------------- - unordered_map ev_pri_S_; // [event]=priority + std::unordered_map ev_pri_S_; // [event]=priority public: using aDominoType::oneLog; }; diff --git a/src/domino/RmEvDom.hpp b/src/domino/RmEvDom.hpp index 2d61033..33e6843 100644 --- a/src/domino/RmEvDom.hpp +++ b/src/domino/RmEvDom.hpp @@ -31,8 +31,6 @@ #include -using namespace std; - namespace RLib { // *********************************************************************************************** @@ -53,7 +51,7 @@ class RmEvDom : public aDominoType // - REQ: min mem (so set is better than vector when almost empty // - REQ: fast (eg isRemoved(), insert, del) // - req: better FIFO - unordered_set isRemovedEv_; + std::unordered_set isRemovedEv_; public: using aDominoType::oneLog; diff --git a/src/domino/WbasicDatDom.hpp b/src/domino/WbasicDatDom.hpp index df0e20a..b83e231 100644 --- a/src/domino/WbasicDatDom.hpp +++ b/src/domino/WbasicDatDom.hpp @@ -13,8 +13,6 @@ #include "UniLog.hpp" -using namespace std; - namespace RLib { // *********************************************************************************************** @@ -41,7 +39,7 @@ class WbasicDatDom : public aDominoType using aDominoType::getData; using aDominoType::replaceData; // ------------------------------------------------------------------------------------------- - vector wrCtrl_; + std::vector wrCtrl_; public: using aDominoType::oneLog; @@ -135,7 +133,7 @@ bool WbasicDatDom::wrCtrlOk(const Domino::EvName& aEvName, const bo template SafePtr wbasic_getData(aDataDominoType& aDom, const Domino::EvName& aEvName) { - return static_pointer_cast(aDom.wbasic_getData(aEvName)); + return std::static_pointer_cast(aDom.wbasic_getData(aEvName)); } // *********************************************************************************************** diff --git a/src/log/StrCoutFSL.hpp b/src/log/StrCoutFSL.hpp index 07e618a..87bdd79 100644 --- a/src/log/StrCoutFSL.hpp +++ b/src/log/StrCoutFSL.hpp @@ -25,14 +25,12 @@ #include "BaseSL.hpp" -using namespace std; - namespace RLib { // *********************************************************************************************** -class StrCoutFSL // FSL = Formatted Smart Log +class StrCoutFSL // FSL = Formatted Smart Log : public BaseSL - , public stringstream // for operator<<(); must not ostringstream since dump need read it!!! + , public std::stringstream // for operator<<(); must not ostringstream since dump need read it!!! { public : ~StrCoutFSL(); @@ -56,7 +54,7 @@ StrCoutFSL::~StrCoutFSL() inline void StrCoutFSL::forceSave() const { - cout << rdbuf() << endl; // internet says rdbuf() is faster than str() + std::cout << rdbuf() << std::endl; // internet says rdbuf() is faster than str() } } // namespace diff --git a/src/log/UniBaseLog.hpp b/src/log/UniBaseLog.hpp index b134d7b..cab65d1 100644 --- a/src/log/UniBaseLog.hpp +++ b/src/log/UniBaseLog.hpp @@ -15,15 +15,12 @@ #include #include -using namespace std; -using namespace std::chrono; - -using LogName = string; +using LogName = std::string; // *********************************************************************************************** // - mem safe: yes // - MT safe : yes upon UniCoutLog, no upon UniSmartLog -#define BUF(content) __func__ << "():" << __LINE__ << ": " << content << endl // __FILE_NAME__ since GCC 12 +#define BUF(content) __func__ << "():" << __LINE__ << ": " << content << std::endl // __FILE_NAME__ since GCC 12 #define INF(content) { oneLog() << "INF] " << BUF(content); } #define WRN(content) { oneLog() << "WRN] " << BUF(content); } #define ERR(content) { oneLog() << "ERR] " << BUF(content); } @@ -49,11 +46,12 @@ inline const char* timestamp() { static thread_local char buf[] = "ddd/HH:MM:SS.123456"; // ddd is days/year; thread_local is MT safe - auto now_tp = system_clock::now(); - auto now_tt = system_clock::to_time_t(now_tp); + auto now_tp = std::chrono::system_clock::now(); + auto now_tt = std::chrono::system_clock::to_time_t(now_tp); strftime(buf, sizeof(buf), "%j/%T.", localtime(&now_tt)); snprintf(buf + sizeof(buf) - 7, 7, "%06u", // snprintf is safer than sprintf - unsigned(duration_cast(now_tp.time_since_epoch()).count() % 1'000'000)); // can milliseconds + unsigned(std::chrono::duration_cast(now_tp.time_since_epoch()).count() + % 1'000'000)); return buf; } diff --git a/src/log/UniCoutLog.cpp b/src/log/UniCoutLog.cpp index 4de3a30..5cf065d 100644 --- a/src/log/UniCoutLog.cpp +++ b/src/log/UniCoutLog.cpp @@ -6,6 +6,8 @@ // *********************************************************************************************** #include "UniCoutLog.hpp" +using namespace std; + namespace RLib { // *********************************************************************************************** diff --git a/src/log/UniCoutLog.hpp b/src/log/UniCoutLog.hpp index ece2dbb..93f4da2 100644 --- a/src/log/UniCoutLog.hpp +++ b/src/log/UniCoutLog.hpp @@ -24,8 +24,6 @@ #include "UniBaseLog.hpp" -using namespace std; - namespace RLib { // *********************************************************************************************** @@ -35,8 +33,8 @@ class UniCoutLog explicit UniCoutLog(const LogName&) {} // compatible UniSmartLog UniCoutLog() = default; - static ostream& oneLog(); - ostream& operator()() const { return oneLog(); } + static std::ostream& oneLog(); + std::ostream& operator()() const { return oneLog(); } static void needLog() {} static LogName uniLogName() { return ULN_DEFAULT; } @@ -59,7 +57,7 @@ class UniCoutLog // *********************************************************************************************** // static than inline, avoid ut conflict when coexist both UniLog -static ostream& oneLog() { return UniCoutLog::oneLog(); } +static std::ostream& oneLog() { return UniCoutLog::oneLog(); } using UniLog = UniCoutLog; diff --git a/src/log/UniSmartLog.cpp b/src/log/UniSmartLog.cpp index 9252a2b..cb41191 100644 --- a/src/log/UniSmartLog.cpp +++ b/src/log/UniSmartLog.cpp @@ -6,6 +6,8 @@ // *********************************************************************************************** #include "UniSmartLog.hpp" +using namespace std; + namespace RLib { // *********************************************************************************************** diff --git a/src/log/UniSmartLog.hpp b/src/log/UniSmartLog.hpp index 7e77e2d..9311889 100644 --- a/src/log/UniSmartLog.hpp +++ b/src/log/UniSmartLog.hpp @@ -27,13 +27,11 @@ #include "StrCoutFSL.hpp" #include "UniBaseLog.hpp" -using namespace std; - namespace RLib { // *********************************************************************************************** using SmartLog = StrCoutFSL; -using LogStore = unordered_map >; +using LogStore = std::unordered_map >; // *********************************************************************************************** class UniSmartLog @@ -51,8 +49,8 @@ class UniSmartLog private: // ------------------------------------------------------------------------------------------- - shared_ptr smartLog_; - const LogName uniLogName_; + std::shared_ptr smartLog_; + const LogName uniLogName_; static LogStore name_log_S_; public: diff --git a/src/msg_self/MsgSelf.hpp b/src/msg_self/MsgSelf.hpp index 5cfac94..b8e022a 100644 --- a/src/msg_self/MsgSelf.hpp +++ b/src/msg_self/MsgSelf.hpp @@ -45,8 +45,6 @@ #define MSG_SELF (ObjAnywhere::getObj()) -using namespace std; - namespace RLib { // *********************************************************************************************** @@ -64,9 +62,9 @@ enum EMsgPriority : unsigned char // !!! MsgCB shall NEVER throw exception!!! // - MsgCB can try-catch all exception // - exception is bug to be fixed than pretected -using MsgCB = function; -using WeakMsgCB = weak_ptr; -using SharedMsgCB = shared_ptr; +using MsgCB = std::function; +using WeakMsgCB = std::weak_ptr; +using SharedMsgCB = std::shared_ptr; // *********************************************************************************************** class MsgSelf : public UniLog @@ -86,7 +84,7 @@ class MsgSelf : public UniLog bool handleOneMsg_(); // ------------------------------------------------------------------------------------------- - deque msgQueues_[EMsgPri_MAX]; + std::deque msgQueues_[EMsgPri_MAX]; size_t nMsg_ = 0; }; } // namespace diff --git a/src/obj_anywhere/DataStore.hpp b/src/obj_anywhere/DataStore.hpp index 0eef902..569e48a 100644 --- a/src/obj_anywhere/DataStore.hpp +++ b/src/obj_anywhere/DataStore.hpp @@ -20,8 +20,6 @@ #include "SafePtr.hpp" // can't UniPtr.hpp since ut(=req) build-err #include "UniLog.hpp" // debug -using namespace std; - namespace RLib { // *********************************************************************************************** @@ -45,7 +43,7 @@ class DataStore private: // ------------------------------------------------------------------------------------------- - unordered_map> key_data_S_; + std::unordered_map> key_data_S_; }; // *********************************************************************************************** @@ -82,7 +80,7 @@ SafePtr DataStore::get(const aDataKey& aKey) const HID("(DataStore) can't find key=" << aKey); return nullptr; } - return dynamic_pointer_cast(key_data->second); + return std::dynamic_pointer_cast(key_data->second); } // *********************************************************************************************** diff --git a/src/obj_anywhere/ObjAnywhere.cpp b/src/obj_anywhere/ObjAnywhere.cpp index 6b66dfd..baeba33 100644 --- a/src/obj_anywhere/ObjAnywhere.cpp +++ b/src/obj_anywhere/ObjAnywhere.cpp @@ -5,6 +5,8 @@ */ #include "ObjAnywhere.hpp" +using namespace std; + namespace RLib { shared_ptr> ObjAnywhere::name_obj_S_; diff --git a/src/obj_anywhere/ObjAnywhere.hpp b/src/obj_anywhere/ObjAnywhere.hpp index fb29750..092748a 100644 --- a/src/obj_anywhere/ObjAnywhere.hpp +++ b/src/obj_anywhere/ObjAnywhere.hpp @@ -27,11 +27,9 @@ #include "DataStore.hpp" #include "UniLog.hpp" -using namespace std; - namespace RLib { -using ObjName = string; +using ObjName = std::string; // *********************************************************************************************** class ObjAnywhere @@ -57,7 +55,7 @@ class ObjAnywhere private: // ------------------------------------------------------------------------------------------- - static shared_ptr> name_obj_S_; // store aObj w/o include aObj.hpp; shared_ptr is safe here + static std::shared_ptr> name_obj_S_; // store aObj w/o include aObj.hpp; shared_ptr is safe here }; // *********************************************************************************************** diff --git a/src/safe_mem/SafePtr.hpp b/src/safe_mem/SafePtr.hpp index 66483b9..330d604 100644 --- a/src/safe_mem/SafePtr.hpp +++ b/src/safe_mem/SafePtr.hpp @@ -36,8 +36,6 @@ #include "UniLog.hpp" -using namespace std; - namespace RLib { // *********************************************************************************************** @@ -54,15 +52,15 @@ class SafePtr // safe-only cast (vs shared_ptr, eg static_pointer_cast is not safe) template SafePtr(const SafePtr&) noexcept; // cp ok or compile err template SafePtr(SafePtr&&) noexcept; // mv ok or compile err - template shared_ptr cast() const noexcept; // ret ok or null + template std::shared_ptr cast() const noexcept; // ret ok or null template - friend SafePtr dynamic_pointer_cast(const SafePtr&) noexcept; // ret ok or null + friend SafePtr std::dynamic_pointer_cast(const SafePtr&) noexcept; // ret ok or null // safe usage: convenient(compatible shared_ptr), equivalent & min // . ret shared_ptr is safer than T* (but not safest since to call T's func easily) // . no operator*() since T& is unsafe - shared_ptr get() const noexcept { return pT_; } - shared_ptr operator->() const noexcept { return pT_; } // convenient + std::shared_ptr get() const noexcept { return pT_; } + std::shared_ptr operator->() const noexcept { return pT_; } // convenient explicit operator bool() const noexcept { return pT_ != nullptr; } auto use_count() const noexcept { return pT_.use_count(); } @@ -74,9 +72,9 @@ class SafePtr template void init_(const SafePtr&) noexcept; // ------------------------------------------------------------------------------------------- - shared_ptr pT_; // core - type_index realType_ = typeid(T); // origin type - type_index lastType_ = typeid(T); // maybe last valid type than realType_ & void + std::shared_ptr pT_; // core + std::type_index realType_ = typeid(T); // origin type + std::type_index lastType_ = typeid(T); // maybe last valid type than realType_ & void }; // *********************************************************************************************** @@ -101,24 +99,24 @@ SafePtr::SafePtr(SafePtr&& aSafeFrom) noexcept // mv - MtQ need // *********************************************************************************************** template template -shared_ptr SafePtr::cast() const noexcept +std::shared_ptr SafePtr::cast() const noexcept { - if constexpr(is_base_of_v) // safer than is_convertible() + if constexpr(std::is_base_of_v) // safer than is_convertible() { //HID("(SafePtr) cast to base/self"); // ERR() not MT safe - return dynamic_pointer_cast(pT_); // private/protected inherit will compile err(rare & no easy fix) + return std::dynamic_pointer_cast(pT_); // private/protected inherit will compile err(rare & no easy fix) } - else if constexpr(is_base_of_v) // else if for constexpr + else if constexpr(std::is_base_of_v) // else if for constexpr { //HID("(SafePtr) cast to derived"); - return dynamic_pointer_cast(pT_); + return std::dynamic_pointer_cast(pT_); } - else if constexpr(is_void_v) + else if constexpr(std::is_void_v) { //HID("(SafePtr) cast to void (for container to store diff types)"); return pT_; } - else if constexpr(!is_void_v) + else if constexpr(!std::is_void_v) { HID("(SafePtr) invalid nonVoid-to-nonVoid, from=" << typeid(T).name() << " to=" << typeid(To).name()); return nullptr; // cast ok or null @@ -127,12 +125,12 @@ shared_ptr SafePtr::cast() const noexcept else if (realType_ == typeid(To)) { //HID("(SafePtr) cast void->origin"); - return static_pointer_cast(pT_); + return std::static_pointer_cast(pT_); } else if (lastType_ == typeid(To)) { //HID("(SafePtr) cast void to last-type-except-void"); - return static_pointer_cast(pT_); + return std::static_pointer_cast(pT_); } HID("(SafePtr) can't cast from=void/" << typeid(T).name() << " to=" << typeid(To).name()); return nullptr; // since dynamic_pointer_cast(pT_) may fail compile DataStore::get(); cast or or null @@ -152,7 +150,7 @@ void SafePtr::init_(const SafePtr& aSafeFrom) noexcept realType_ = aSafeFrom.realType(); // save last useful type - if (!is_same_v && realType_ != typeid(T)) + if (!std::is_same_v && realType_ != typeid(T)) lastType_ = typeid(T); else lastType_ = aSafeFrom.lastType(); @@ -164,16 +162,6 @@ void SafePtr::init_(const SafePtr& aSafeFrom) noexcept -// *********************************************************************************************** -template -SafePtr dynamic_pointer_cast(const SafePtr& aSafeFrom) noexcept -{ - SafePtr safeTo; - safeTo.pT_ = aSafeFrom.template cast(); - safeTo.init_(aSafeFrom); - return safeTo; -} - // *********************************************************************************************** template SafePtr make_safe(ConstructArgs&&... aArgs) @@ -202,15 +190,26 @@ bool operator<(SafePtr lhs, SafePtr rhs) { return lhs.get() < rhs.get(); } +} // namespace + +// *********************************************************************************************** +template +RLib::SafePtr std::dynamic_pointer_cast(const RLib::SafePtr& aSafeFrom) noexcept +{ + RLib::SafePtr safeTo; + safeTo.pT_ = aSafeFrom.template cast(); + safeTo.init_(aSafeFrom); + return safeTo; +} // *********************************************************************************************** template -SafePtr static_pointer_cast(const SafePtr& aSafeFrom) noexcept +RLib::SafePtr std::static_pointer_cast(const RLib::SafePtr& aSafeFrom) noexcept { - return dynamic_pointer_cast(aSafeFrom); + return std::dynamic_pointer_cast(aSafeFrom); } -} // namespace +// *********************************************************************************************** template struct std::hash> { diff --git a/src/safe_mem/UniPtr.hpp b/src/safe_mem/UniPtr.hpp index 4ed4cdf..80966db 100644 --- a/src/safe_mem/UniPtr.hpp +++ b/src/safe_mem/UniPtr.hpp @@ -15,8 +15,6 @@ #include // make_shared -using namespace std; - #if 0 namespace RLib { diff --git a/src/thread/AsyncBack.cpp b/src/thread/AsyncBack.cpp index f2d555d..f24d92b 100644 --- a/src/thread/AsyncBack.cpp +++ b/src/thread/AsyncBack.cpp @@ -5,6 +5,8 @@ */ #include "AsyncBack.hpp" +using namespace std; + namespace RLib { // *********************************************************************************************** diff --git a/src/thread/AsyncBack.hpp b/src/thread/AsyncBack.hpp index 3107190..fe1bac9 100644 --- a/src/thread/AsyncBack.hpp +++ b/src/thread/AsyncBack.hpp @@ -54,8 +54,6 @@ #include "ThreadBack.hpp" -using namespace std; - namespace RLib { // *********************************************************************************************** diff --git a/src/thread/MT_Semaphore.hpp b/src/thread/MT_Semaphore.hpp index b353254..a9dba42 100644 --- a/src/thread/MT_Semaphore.hpp +++ b/src/thread/MT_Semaphore.hpp @@ -23,8 +23,6 @@ #include #include -using namespace std; - namespace RLib { // *********************************************************************************************** @@ -43,7 +41,7 @@ class MT_Semaphore private: sem_t mt_sem_; - atomic_flag mt_notified_ = ATOMIC_FLAG_INIT; // = false + std::atomic_flag mt_notified_ = ATOMIC_FLAG_INIT; // = false // ------------------------------------------------------------------------------------------- #ifdef RLIB_UT diff --git a/src/thread/MtInQueue.cpp b/src/thread/MtInQueue.cpp index 2333a9b..0dd1ca8 100644 --- a/src/thread/MtInQueue.cpp +++ b/src/thread/MtInQueue.cpp @@ -9,6 +9,8 @@ #include "MT_PingMainTH.hpp" #include "MtInQueue.hpp" +using namespace std; + namespace RLib { // *********************************************************************************************** diff --git a/src/thread/MtInQueue.hpp b/src/thread/MtInQueue.hpp index 9934887..cc9624c 100644 --- a/src/thread/MtInQueue.hpp +++ b/src/thread/MtInQueue.hpp @@ -33,14 +33,12 @@ #include "UniLog.hpp" #include "UniPtr.hpp" -using namespace std; - namespace RLib { // - ele & its type_index(==/!= ok, but type_info* & hash_code nok) // - shared_ptr is safe to cast void since type_index (but not safe as SafePtr's create) -using ELE_TID = pair; -using EleHdlr = function; // NO exception allowed +using ELE_TID = std::pair; +using EleHdlr = std::function; // NO exception allowed // *********************************************************************************************** class MtInQueue @@ -66,20 +64,20 @@ class MtInQueue void clearHdlrPool() { tid_hdlr_S_.clear(); } private: - deque::iterator begin_(); + std::deque::iterator begin_(); size_t handleCacheEle_(); // ------------------------------------------------------------------------------------------- - deque queue_; // my limit ele# if need; most suitable container - deque cache_; // main-thread use ONLY (so no mutex protect) - mutex mutex_; + std::deque queue_; // my limit ele# if need; most suitable container + std::deque cache_; // main-thread use ONLY (so no mutex protect) + std::mutex mutex_; - unordered_map tid_hdlr_S_; + std::unordered_map tid_hdlr_S_; // ------------------------------------------------------------------------------------------- #ifdef RLIB_UT public: - mutex& backdoor() { return mutex_; } + std::mutex& backdoor() { return mutex_; } #endif }; @@ -102,8 +100,8 @@ void MtInQueue::mt_push(PTR&& aEle) // push { - lock_guard guard(mutex_); - queue_.push_back(ELE_TID(move(aEle), typeid(aEleType))); + std::lock_guard guard(mutex_); + queue_.push_back(ELE_TID(std::move(aEle), typeid(aEleType))); //HID("(MtQ) ptr=" << aEle.get() << ", nRef=" << aEle.use_count()); // HID supports MT } @@ -125,9 +123,9 @@ PTR MtInQueue::pop() return nullptr; // pop - auto ele = move(it->first); // must copy + auto ele = std::move(it->first); cache_.pop_front(); - return static_pointer_cast(ele); + return std::static_pointer_cast(ele); } // *********************************************************************************************** @@ -140,7 +138,7 @@ bool MtInQueue::setHdlrOK(const EleHdlr& aHdlr) return false; } - auto&& tid = type_index(typeid(aEleType)); + auto&& tid = std::type_index(typeid(aEleType)); if (tid_hdlr_S_.find(tid) != tid_hdlr_S_.end()) { ERR("(MtInQueue) failed!!! overwrite hdlr may unsafe existing data"); diff --git a/src/thread/ThPoolBack.cpp b/src/thread/ThPoolBack.cpp index 0e2c25d..d6de624 100644 --- a/src/thread/ThPoolBack.cpp +++ b/src/thread/ThPoolBack.cpp @@ -5,6 +5,8 @@ */ #include "ThPoolBack.hpp" +using namespace std; + namespace RLib { // *********************************************************************************************** diff --git a/src/thread/ThPoolBack.hpp b/src/thread/ThPoolBack.hpp index 247b25d..a4ae9b3 100644 --- a/src/thread/ThPoolBack.hpp +++ b/src/thread/ThPoolBack.hpp @@ -20,8 +20,6 @@ #include "ThreadBack.hpp" -using namespace std; - namespace RLib { // *********************************************************************************************** @@ -35,12 +33,12 @@ class ThPoolBack : public ThreadBack private: // ------------------------------------------------------------------------------------------- - vector thPool_; - deque> taskQ_; + std::vector thPool_; + std::deque> taskQ_; - mutex mutex_; - condition_variable cv_; - atomic stopAllTH_ = false; + std::mutex mutex_; + std::condition_variable cv_; + std::atomic stopAllTH_ = false; }; } // namespace diff --git a/src/thread/ThreadBack.cpp b/src/thread/ThreadBack.cpp index 9767430..bebfc6b 100644 --- a/src/thread/ThreadBack.cpp +++ b/src/thread/ThreadBack.cpp @@ -10,6 +10,8 @@ #include "ThreadBack.hpp" +using namespace std; + namespace RLib { // *********************************************************************************************** diff --git a/src/thread/ThreadBack.hpp b/src/thread/ThreadBack.hpp index adcec7f..3280dd0 100644 --- a/src/thread/ThreadBack.hpp +++ b/src/thread/ThreadBack.hpp @@ -19,14 +19,12 @@ #define THREAD_BACK (RLib::ObjAnywhere::getObj()) -using namespace std; - namespace RLib { // *********************************************************************************************** -using MT_TaskEntryFN = function; // succ ret true, otherwise false -using TaskBackFN = function; // entry ret as para -using StoreThreadBack = list, TaskBackFN> >; // deque rm middle is worse +using MT_TaskEntryFN = std::function; // succ ret true, otherwise false +using TaskBackFN = std::function; // entry ret as para +using StoreThreadBack = std::list, TaskBackFN> >; // deque rm middle is worse // *********************************************************************************************** class ThreadBack @@ -49,8 +47,8 @@ class ThreadBack static bool inMyMainTH() { - static const auto s_myMainTH = this_thread::get_id(); - return s_myMainTH == this_thread::get_id(); + static const auto s_myMainTH = std::this_thread::get_id(); + return s_myMainTH == std::this_thread::get_id(); } protected: diff --git a/src/thread/ThreadBackViaMsgSelf.hpp b/src/thread/ThreadBackViaMsgSelf.hpp index 178e615..a568ccf 100644 --- a/src/thread/ThreadBackViaMsgSelf.hpp +++ b/src/thread/ThreadBackViaMsgSelf.hpp @@ -20,7 +20,7 @@ namespace RLib // *********************************************************************************************** // wrap TaskBackFN to queue in MsgSelf inline -TaskBackFN viaMsgSelf(const TaskBackFN& aBackFN, shared_ptr aMsgSelf, EMsgPriority aPri = EMsgPri_NORM) +TaskBackFN viaMsgSelf(const TaskBackFN& aBackFN, std::shared_ptr aMsgSelf, EMsgPriority aPri = EMsgPri_NORM) { return ! aBackFN || aMsgSelf == nullptr ? TaskBackFN(nullptr) // empty fn diff --git a/ut/log/UniLogTest.hpp b/ut/log/UniLogTest.hpp index 0df740b..41ce640 100644 --- a/ut/log/UniLogTest.hpp +++ b/ut/log/UniLogTest.hpp @@ -6,6 +6,7 @@ // *********************************************************************************************** #include +using namespace std; using namespace testing; namespace RLib diff --git a/ut/msg_self/MsgSelfTest.cpp b/ut/msg_self/MsgSelfTest.cpp index a8e44dd..b098721 100644 --- a/ut/msg_self/MsgSelfTest.cpp +++ b/ut/msg_self/MsgSelfTest.cpp @@ -13,6 +13,7 @@ #include "MsgSelf.hpp" #include "MT_PingMainTH.hpp" +using namespace std; using namespace std::chrono; using namespace testing; @@ -38,7 +39,7 @@ struct MsgSelfTest : public Test, public UniLog }; MOCK_METHOD(void, d6MsgHdlr, ()); - queue hdlrIDs_; + std::queue hdlrIDs_; }; #define SEND_MSG diff --git a/ut/obj_anywhere/DataStoreTest.cpp b/ut/obj_anywhere/DataStoreTest.cpp index 2158590..00ab29c 100644 --- a/ut/obj_anywhere/DataStoreTest.cpp +++ b/ut/obj_anywhere/DataStoreTest.cpp @@ -11,6 +11,7 @@ #include "DataStore.hpp" #include "SafePtr.hpp" +using namespace std; using namespace testing; namespace RLib diff --git a/ut/thread/MtInQueueTest.cpp b/ut/thread/MtInQueueTest.cpp index b1e3fa4..87b0f24 100644 --- a/ut/thread/MtInQueueTest.cpp +++ b/ut/thread/MtInQueueTest.cpp @@ -18,6 +18,7 @@ #include "MtInQueue.hpp" #undef RLIB_UT +using namespace std; using namespace testing; namespace RLib diff --git a/ut/thread/ThreadBackTest.hpp b/ut/thread/ThreadBackTest.hpp index 8b5a606..48a7394 100644 --- a/ut/thread/ThreadBackTest.hpp +++ b/ut/thread/ThreadBackTest.hpp @@ -15,6 +15,8 @@ #include "ThreadBackViaMsgSelf.hpp" #include "UniLog.hpp" +using namespace std; +using namespace std::chrono; using namespace testing; namespace RLib @@ -36,7 +38,7 @@ struct THREAD_BACK_TEST : public Test, public UniLog // ------------------------------------------------------------------------------------------- THREAD_BACK_TYPE threadBack_; - shared_ptr msgSelf_ = make_shared(uniLogName()); + std::shared_ptr msgSelf_ = std::make_shared(uniLogName()); }; #define THREAD_AND_BACK