From 58e1aea32b2071ca78a42ea586c0d3033c871875 Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Tue, 3 Nov 2020 22:09:42 +0800 Subject: [PATCH] add function: fc_queue_empty --- HISTORY | 2 +- src/fast_mblock.c | 4 +++- src/fast_mblock.h | 5 +++-- src/fc_queue.h | 17 ++++++++++++++++- src/pthread_func.h | 1 + src/sched_thread.h | 27 +++++++++++++++++++-------- 6 files changed, 43 insertions(+), 13 deletions(-) diff --git a/HISTORY b/HISTORY index b6e9913..35111eb 100644 --- a/HISTORY +++ b/HISTORY @@ -1,5 +1,5 @@ -Version 1.44 2020-10-31 +Version 1.44 2020-11-03 * add test file src/tests/test_pthread_lock.c * add uniq_skiplist.[hc] * add function split_string_ex diff --git a/src/fast_mblock.c b/src/fast_mblock.c index b48c19e..8bfe98a 100644 --- a/src/fast_mblock.c +++ b/src/fast_mblock.c @@ -425,6 +425,7 @@ int fast_mblock_init_ex2(struct fast_mblock_man *mblock, const char *name, mblock->info.trunk_size = fast_mblock_get_trunk_size(mblock, block_size, mblock->alloc_elements.once); mblock->need_lock = need_lock; + mblock->exceed_log_level = LOG_ERR; mblock->malloc_trunk_callback.check_func = malloc_trunk_check; mblock->malloc_trunk_callback.notify_func = malloc_trunk_notify; mblock->malloc_trunk_callback.args = malloc_trunk_args; @@ -463,7 +464,8 @@ static int fast_mblock_prealloc(struct fast_mblock_man *mblock) mblock->info.element_total_count; if (avail_count <= 0) { - logError("file: "__FILE__", line: %d, " + log_it_ex(&g_log_context, mblock->exceed_log_level, + "file: "__FILE__", line: %d, " "allocated elements exceed limit: %"PRId64, __LINE__, mblock->alloc_elements.limit); return EOVERFLOW; diff --git a/src/fast_mblock.h b/src/fast_mblock.h index 993f1bf..907e2dd 100644 --- a/src/fast_mblock.h +++ b/src/fast_mblock.h @@ -102,8 +102,9 @@ struct fast_mblock_man fast_mblock_alloc_init_func alloc_init_func; struct fast_mblock_malloc_trunk_callback malloc_trunk_callback; - bool need_lock; //if need mutex lock - pthread_mutex_t lock; //the lock for read / write free node chain + bool need_lock; //if need mutex lock + int exceed_log_level; //log level for exceed limit + pthread_mutex_t lock; //the lock for read / write free node chain struct fast_mblock_man *prev; //for stat manager struct fast_mblock_man *next; //for stat manager void *init_args; //args for alloc_init_func diff --git a/src/fc_queue.h b/src/fc_queue.h index 913bd1f..2434d20 100644 --- a/src/fc_queue.h +++ b/src/fc_queue.h @@ -23,7 +23,6 @@ #include #include #include "common_define.h" -#include "fast_mblock.h" struct fc_queue_info { @@ -74,6 +73,12 @@ static inline void fc_queue_push(struct fc_queue *queue, void *data) } } +static inline void fc_queue_push_silence(struct fc_queue *queue, void *data) +{ + bool notify; + fc_queue_push_ex(queue, data, ¬ify); +} + void fc_queue_push_queue_to_head_ex(struct fc_queue *queue, struct fc_queue_info *qinfo, bool *notify); @@ -99,6 +104,16 @@ void *fc_queue_pop_all_ex(struct fc_queue *queue, const bool blocked); void fc_queue_pop_to_queue(struct fc_queue *queue, struct fc_queue_info *qinfo); +static inline bool fc_queue_empty(struct fc_queue *queue) +{ + bool empty; + + pthread_mutex_lock(&queue->lc_pair.lock); + empty = (queue->head == NULL); + pthread_mutex_unlock(&queue->lc_pair.lock); + return empty; +} + #ifdef __cplusplus } #endif diff --git a/src/pthread_func.h b/src/pthread_func.h index 0740864..525a6f6 100644 --- a/src/pthread_func.h +++ b/src/pthread_func.h @@ -23,6 +23,7 @@ #include #include #include "common_define.h" +#include "logger.h" #include "sched_thread.h" #ifdef __cplusplus diff --git a/src/sched_thread.h b/src/sched_thread.h index f80353d..3bcaf36 100644 --- a/src/sched_thread.h +++ b/src/sched_thread.h @@ -81,25 +81,36 @@ typedef struct bool *pcontinue_flag; } ScheduleContext; -#define INIT_SCHEDULE_ENTRY(schedule_entry, _id, _hour, _minute, _second, \ - _interval, _task_func, _func_args) \ +#define INIT_SCHEDULE_ENTRY1(schedule_entry, _id, _hour, _minute, _second, \ + _interval, _task_func, _func_args, _new_thread) \ (schedule_entry).id = _id; \ (schedule_entry).time_base.hour = _hour; \ (schedule_entry).time_base.minute = _minute; \ (schedule_entry).time_base.second = _second; \ (schedule_entry).interval = _interval; \ (schedule_entry).task_func = _task_func; \ - (schedule_entry).new_thread = false; \ - (schedule_entry).func_args = _func_args + (schedule_entry).func_args = _func_args; \ + (schedule_entry).new_thread = _new_thread -#define INIT_SCHEDULE_ENTRY_EX(schedule_entry, _id, _time_base, \ - _interval, _task_func, _func_args) \ +#define INIT_SCHEDULE_ENTRY_EX1(schedule_entry, _id, _time_base, \ + _interval, _task_func, _func_args, _new_thread) \ (schedule_entry).id = _id; \ (schedule_entry).time_base = _time_base; \ (schedule_entry).interval = _interval; \ (schedule_entry).task_func = _task_func; \ - (schedule_entry).new_thread = false; \ - (schedule_entry).func_args = _func_args + (schedule_entry).func_args = _func_args; \ + (schedule_entry).new_thread = _new_thread + +#define INIT_SCHEDULE_ENTRY(schedule_entry, _id, _hour, _minute, _second, \ + _interval, _task_func, _func_args) \ + INIT_SCHEDULE_ENTRY1(schedule_entry, _id, _hour, _minute, _second, \ + _interval, _task_func, _func_args, false) + +#define INIT_SCHEDULE_ENTRY_EX(schedule_entry, _id, _time_base, \ + _interval, _task_func, _func_args) \ + INIT_SCHEDULE_ENTRY_EX1(schedule_entry, _id, _time_base, \ + _interval, _task_func, _func_args, false) + #ifdef __cplusplus extern "C" { -- GitLab