add function fc_queue_timedpeek

pull/37/merge
YuQing 2021-08-11 11:32:23 +08:00
parent 44dcf4f821
commit 2fafa215fd
3 changed files with 40 additions and 13 deletions

View File

@ -1,7 +1,8 @@
Version 1.54 2021-08-08 Version 1.54 2021-08-11
* fast_allocator.[hc]: correct reclaim_interval logic * fast_allocator.[hc]: correct reclaim_interval logic
* shared_func.[hc]: add functions getFileContentEx1 and getFileContent1 * shared_func.[hc]: add functions getFileContentEx1 and getFileContent1
* fc_queue.[hc]: add function fc_queue_timedpeek
Version 1.53 2021-06-30 Version 1.53 2021-06-30
* process_action support action status * process_action support action status

View File

@ -181,21 +181,35 @@ void *fc_queue_timedpop(struct fc_queue *queue,
void *data; void *data;
PTHREAD_MUTEX_LOCK(&queue->lc_pair.lock); PTHREAD_MUTEX_LOCK(&queue->lc_pair.lock);
do { data = queue->head;
if (data == NULL) {
fc_cond_timedwait(&queue->lc_pair, timeout, time_unit);
data = queue->head; data = queue->head;
if (data == NULL) { }
fc_cond_timedwait(&queue->lc_pair, timeout, time_unit);
data = queue->head;
}
if (data != NULL) { if (data != NULL) {
queue->head = FC_QUEUE_NEXT_PTR(queue, data); queue->head = FC_QUEUE_NEXT_PTR(queue, data);
if (queue->head == NULL) { if (queue->head == NULL) {
queue->tail = NULL; queue->tail = NULL;
}
} }
} while (0); }
PTHREAD_MUTEX_UNLOCK(&queue->lc_pair.lock); PTHREAD_MUTEX_UNLOCK(&queue->lc_pair.lock);
return data; return data;
} }
void *fc_queue_timedpeek(struct fc_queue *queue,
const int timeout, const int time_unit)
{
void *data;
PTHREAD_MUTEX_LOCK(&queue->lc_pair.lock);
data = queue->head;
if (data == NULL) {
fc_cond_timedwait(&queue->lc_pair, timeout, time_unit);
data = queue->head;
}
PTHREAD_MUTEX_UNLOCK(&queue->lc_pair.lock);
return data;
}

View File

@ -160,6 +160,18 @@ void *fc_queue_timedpop(struct fc_queue *queue,
#define fc_queue_timedpop_us(queue, timeout_us) \ #define fc_queue_timedpop_us(queue, timeout_us) \
fc_queue_timedpop(queue, timeout_us, FC_TIME_UNIT_USECOND) fc_queue_timedpop(queue, timeout_us, FC_TIME_UNIT_USECOND)
void *fc_queue_timedpeek(struct fc_queue *queue,
const int timeout, const int time_unit);
#define fc_queue_timedpeek_sec(queue, timeout) \
fc_queue_timedpeek(queue, timeout, FC_TIME_UNIT_SECOND)
#define fc_queue_timedpeek_ms(queue, timeout_ms) \
fc_queue_timedpeek(queue, timeout_ms, FC_TIME_UNIT_MSECOND)
#define fc_queue_timedpeek_us(queue, timeout_us) \
fc_queue_timedpeek(queue, timeout_us, FC_TIME_UNIT_USECOND)
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif