diff --git a/src/UtilsCtrl/ThreadPool/Queue/ULockFreeRingBufferQueue.h b/src/UtilsCtrl/ThreadPool/Queue/ULockFreeRingBufferQueue.h index 50dfcc3b..0165a2d6 100644 --- a/src/UtilsCtrl/ThreadPool/Queue/ULockFreeRingBufferQueue.h +++ b/src/UtilsCtrl/ThreadPool/Queue/ULockFreeRingBufferQueue.h @@ -16,7 +16,7 @@ CGRAPH_NAMESPACE_BEGIN -template +template class ULockFreeRingBufferQueue : public UQueueObject { public: explicit ULockFreeRingBufferQueue() { diff --git a/src/UtilsCtrl/ThreadPool/UThreadPoolDefine.h b/src/UtilsCtrl/ThreadPool/UThreadPoolDefine.h index 3fd0767b..da1076ff 100644 --- a/src/UtilsCtrl/ThreadPool/UThreadPoolDefine.h +++ b/src/UtilsCtrl/ThreadPool/UThreadPoolDefine.h @@ -37,7 +37,7 @@ static const int CGRAPH_THREAD_SCHED_FIFO = 0; static const CInt CGRAPH_THREAD_MIN_PRIORITY = 0; // 线程最低优先级 static const CInt CGRAPH_THREAD_MAX_PRIORITY = 99; // 线程最高优先级 static const CMSec CGRAPH_MAX_BLOCK_TTL = 1999999999; // 最大阻塞时间,单位为ms -static const CUint CGRAPH_DEFAULT_RINGBUFFER_SIZE = 1024; // 默认环形队列的大小 +static const CUint CGRAPH_DEFAULT_RINGBUFFER_SIZE = 64; // 默认环形队列的大小 static const CIndex CGRAPH_SECONDARY_THREAD_COMMON_ID = -1; // 辅助线程统一id标识 static const CInt CGRAPH_DEFAULT_PRIORITY = 0; // 默认优先级 diff --git a/src/UtilsCtrl/UtilsDefine.h b/src/UtilsCtrl/UtilsDefine.h index 79be81fa..c375d28c 100644 --- a/src/UtilsCtrl/UtilsDefine.h +++ b/src/UtilsCtrl/UtilsDefine.h @@ -35,6 +35,12 @@ CGRAPH_NAMESPACE_BEGIN using CGRAPH_LOCK_GUARD = std::lock_guard; using CGRAPH_UNIQUE_LOCK = std::unique_lock; +/* 判断函数流程是否可以继续 */ +CGRAPH_INTERNAL_NAMESPACE_BEGIN + static std::mutex g_check_status_mtx; + static std::mutex g_echo_mtx; +CGRAPH_INTERNAL_NAMESPACE_END + #if __cplusplus >= 201703L using CGRAPH_READ_LOCK = std::shared_lock; using CGRAPH_WRITE_LOCK = std::unique_lock; @@ -89,18 +95,6 @@ CVoid __ASSERT_NOT_NULL_THROW_EXCEPTION(T t, Args... args) { #define CGRAPH_ASSERT_NOT_NULL_THROW_ERROR(ptr, ...) \ __ASSERT_NOT_NULL_THROW_EXCEPTION(ptr, ##__VA_ARGS__); \ - -/* 判断函数流程是否可以继续 */ -static std::mutex g_check_status_mtx; -#define CGRAPH_FUNCTION_CHECK_STATUS \ - if (unlikely(status.isErr())) { \ - if (status.isCrash()) { throw CException(status.getInfo()); } \ - CGRAPH_LOCK_GUARD lock{ g_check_status_mtx }; \ - CGRAPH_ECHO("%s, errorCode = [%d], errorInfo = [%s].", \ - status.getLocate().c_str(), status.getCode(), status.getInfo().c_str()); \ - return status; \ - } \ - /* 删除资源信息 */ #define CGRAPH_DELETE_PTR(ptr) \ if (unlikely((ptr) != nullptr)) { \ @@ -117,11 +111,9 @@ static std::mutex g_check_status_mtx; if (unlikely((isInit) != is_init_)) { \ CGRAPH_THROW_EXCEPTION("[CException] init status is not suitable") } \ -#define CGRAPH_ASSERT_MUTABLE_INIT_THROW_ERROR(isInit) \ - if (unlikely((isInit) != is_init_) && !isMutable()) { \ - CGRAPH_THROW_EXCEPTION("[CException] init status is not suitable") } \ - - +#define CGRAPH_ASSERT_MUTABLE_INIT_THROW_ERROR(isInit) \ + if (unlikely((isInit) != is_init_) && !isMutable()) { \ + CGRAPH_THROW_EXCEPTION("[CException] mutable init status is not suitable") } \ #define CGRAPH_SLEEP_SECOND(s) \ std::this_thread::sleep_for(std::chrono::seconds(s)); \ @@ -129,6 +121,40 @@ static std::mutex g_check_status_mtx; #define CGRAPH_SLEEP_MILLISECOND(ms) \ std::this_thread::sleep_for(std::chrono::milliseconds(ms)); \ +#define CGRAPH_FUNCTION_CHECK_STATUS \ + if (unlikely(status.isErr())) { \ + if (status.isCrash()) { throw CException(status.getInfo()); } \ + CGRAPH_LOCK_GUARD lock{ internal::g_check_status_mtx }; \ + CGRAPH_ECHO("%s, errorCode = [%d], errorInfo = [%s].", \ + status.getLocate().c_str(), status.getCode(), status.getInfo().c_str()); \ + return status; \ + } \ + +/** +* 定制化输出 +* @param cmd +* @param ... +* 注:内部包含全局锁,不建议正式上线的时候使用 +*/ +inline CVoid CGRAPH_ECHO(const char *cmd, ...) { +#ifdef _CGRAPH_SILENCE_ + return; +#endif + + std::lock_guard lock{ internal::g_echo_mtx }; + auto now = std::chrono::system_clock::now(); + auto time = std::chrono::system_clock::to_time_t(now); + auto ms = std::chrono::duration_cast(now.time_since_epoch()).count() % 1000; + std::cout << "[" << std::put_time(std::localtime(&time), "%Y-%m-%d %H:%M:%S.") \ + << std::setfill('0') << std::setw(3) << ms << "] "; + + va_list args; + va_start(args, cmd); + vprintf(cmd, args); + va_end(args); + std::cout << "\n"; +} + CGRAPH_NAMESPACE_END #endif //CGRAPH_UTILSDEFINE_H diff --git a/src/UtilsCtrl/UtilsFunction.h b/src/UtilsCtrl/UtilsFunction.h index 45a571c3..6b2f46f3 100644 --- a/src/UtilsCtrl/UtilsFunction.h +++ b/src/UtilsCtrl/UtilsFunction.h @@ -20,33 +20,6 @@ CGRAPH_NAMESPACE_BEGIN -/** - * 定制化输出 - * @param cmd - * @param ... - * 注:内部包含全局锁,不建议正式上线的时候使用 - */ -static std::mutex g_echo_mtx; -inline CVoid CGRAPH_ECHO(const char *cmd, ...) { -#ifdef _CGRAPH_SILENCE_ - return; -#endif - - std::lock_guard lock{ g_echo_mtx }; - auto now = std::chrono::system_clock::now(); - auto time = std::chrono::system_clock::to_time_t(now); - auto ms = std::chrono::duration_cast(now.time_since_epoch()).count() % 1000; - std::cout << "[" << std::put_time(std::localtime(&time), "%Y-%m-%d %H:%M:%S.") \ - << std::setfill('0') << std::setw(3) << ms << "] "; - - va_list args; - va_start(args, cmd); - vprintf(cmd, args); - va_end(args); - std::cout << "\n"; -} - - /** * 获取当前的ms信息 * @return