add function: fc_queue_empty
parent
5f9bfd8bae
commit
58e1aea32b
2
HISTORY
2
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 test file src/tests/test_pthread_lock.c
|
||||||
* add uniq_skiplist.[hc]
|
* add uniq_skiplist.[hc]
|
||||||
* add function split_string_ex
|
* add function split_string_ex
|
||||||
|
|
|
||||||
|
|
@ -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,
|
mblock->info.trunk_size = fast_mblock_get_trunk_size(mblock,
|
||||||
block_size, mblock->alloc_elements.once);
|
block_size, mblock->alloc_elements.once);
|
||||||
mblock->need_lock = need_lock;
|
mblock->need_lock = need_lock;
|
||||||
|
mblock->exceed_log_level = LOG_ERR;
|
||||||
mblock->malloc_trunk_callback.check_func = malloc_trunk_check;
|
mblock->malloc_trunk_callback.check_func = malloc_trunk_check;
|
||||||
mblock->malloc_trunk_callback.notify_func = malloc_trunk_notify;
|
mblock->malloc_trunk_callback.notify_func = malloc_trunk_notify;
|
||||||
mblock->malloc_trunk_callback.args = malloc_trunk_args;
|
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;
|
mblock->info.element_total_count;
|
||||||
if (avail_count <= 0)
|
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,
|
"allocated elements exceed limit: %"PRId64,
|
||||||
__LINE__, mblock->alloc_elements.limit);
|
__LINE__, mblock->alloc_elements.limit);
|
||||||
return EOVERFLOW;
|
return EOVERFLOW;
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,7 @@ struct fast_mblock_man
|
||||||
struct fast_mblock_malloc_trunk_callback malloc_trunk_callback;
|
struct fast_mblock_malloc_trunk_callback malloc_trunk_callback;
|
||||||
|
|
||||||
bool need_lock; //if need mutex lock
|
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
|
pthread_mutex_t lock; //the lock for read / write free node chain
|
||||||
struct fast_mblock_man *prev; //for stat manager
|
struct fast_mblock_man *prev; //for stat manager
|
||||||
struct fast_mblock_man *next; //for stat manager
|
struct fast_mblock_man *next; //for stat manager
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include "common_define.h"
|
#include "common_define.h"
|
||||||
#include "fast_mblock.h"
|
|
||||||
|
|
||||||
struct fc_queue_info
|
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,
|
void fc_queue_push_queue_to_head_ex(struct fc_queue *queue,
|
||||||
struct fc_queue_info *qinfo, bool *notify);
|
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,
|
void fc_queue_pop_to_queue(struct fc_queue *queue,
|
||||||
struct fc_queue_info *qinfo);
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include "common_define.h"
|
#include "common_define.h"
|
||||||
|
#include "logger.h"
|
||||||
#include "sched_thread.h"
|
#include "sched_thread.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
||||||
|
|
@ -81,25 +81,36 @@ typedef struct
|
||||||
bool *pcontinue_flag;
|
bool *pcontinue_flag;
|
||||||
} ScheduleContext;
|
} ScheduleContext;
|
||||||
|
|
||||||
#define INIT_SCHEDULE_ENTRY(schedule_entry, _id, _hour, _minute, _second, \
|
#define INIT_SCHEDULE_ENTRY1(schedule_entry, _id, _hour, _minute, _second, \
|
||||||
_interval, _task_func, _func_args) \
|
_interval, _task_func, _func_args, _new_thread) \
|
||||||
(schedule_entry).id = _id; \
|
(schedule_entry).id = _id; \
|
||||||
(schedule_entry).time_base.hour = _hour; \
|
(schedule_entry).time_base.hour = _hour; \
|
||||||
(schedule_entry).time_base.minute = _minute; \
|
(schedule_entry).time_base.minute = _minute; \
|
||||||
(schedule_entry).time_base.second = _second; \
|
(schedule_entry).time_base.second = _second; \
|
||||||
(schedule_entry).interval = _interval; \
|
(schedule_entry).interval = _interval; \
|
||||||
(schedule_entry).task_func = _task_func; \
|
(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, \
|
#define INIT_SCHEDULE_ENTRY_EX1(schedule_entry, _id, _time_base, \
|
||||||
_interval, _task_func, _func_args) \
|
_interval, _task_func, _func_args, _new_thread) \
|
||||||
(schedule_entry).id = _id; \
|
(schedule_entry).id = _id; \
|
||||||
(schedule_entry).time_base = _time_base; \
|
(schedule_entry).time_base = _time_base; \
|
||||||
(schedule_entry).interval = _interval; \
|
(schedule_entry).interval = _interval; \
|
||||||
(schedule_entry).task_func = _task_func; \
|
(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
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue