diff --git a/HISTORY b/HISTORY index b6e99132f2f85a7022a929135bc594f593a05d16..35111eb822d7d0a2e1651b051ea3a9806bb19d33 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 b48c19e8435a83e3823d086c1b24d122ecce4d35..8bfe98a412960ddf447d4abe0630a30a14ca7afd 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 993f1bfdafe54d1ad1a657021fd9254c160c228a..907e2dd57d8e46615c9f45c790ffd218b9a34b7f 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 913bd1f24a91e8bad656eabb115bffcc2d77474a..2434d20c6b23e2dc7240a3395735b71c12a8358c 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 074086467d2d229bdddf95d710a75bb1034cf059..525a6f6f1cf2cdb89b002015ede95dd7f1eda054 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 f80353d854af0b45e2beb75b0b3fcaac72155530..3bcaf36d59022cce3efe4db0303c7b3d22d11ce0 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" {