Skip to content

Commit

Permalink
[feat] shade some param with ::internal
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunelFeng committed Nov 19, 2023
1 parent 806e02e commit 0ce3e01
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/UtilsCtrl/ThreadPool/Queue/ULockFreeRingBufferQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

CGRAPH_NAMESPACE_BEGIN

template<typename T, CInt CAPACITY = 32>
template<typename T, CInt CAPACITY = CGRAPH_DEFAULT_RINGBUFFER_SIZE>
class ULockFreeRingBufferQueue : public UQueueObject {
public:
explicit ULockFreeRingBufferQueue() {
Expand Down
2 changes: 1 addition & 1 deletion src/UtilsCtrl/ThreadPool/UThreadPoolDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; // 默认优先级

Expand Down
60 changes: 43 additions & 17 deletions src/UtilsCtrl/UtilsDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ CGRAPH_NAMESPACE_BEGIN
using CGRAPH_LOCK_GUARD = std::lock_guard<std::mutex>;
using CGRAPH_UNIQUE_LOCK = std::unique_lock<std::mutex>;

/* 判断函数流程是否可以继续 */
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<std::shared_mutex>;
using CGRAPH_WRITE_LOCK = std::unique_lock<std::shared_mutex>;
Expand Down Expand Up @@ -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)) { \
Expand All @@ -117,18 +111,50 @@ 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)); \

#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<std::mutex> 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<std::chrono::milliseconds>(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
27 changes: 0 additions & 27 deletions src/UtilsCtrl/UtilsFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex> 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<std::chrono::milliseconds>(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
Expand Down

0 comments on commit 0ce3e01

Please sign in to comment.