common_blocked_queue.h: add function common_blocked_queue_try_pop
parent
2c83c992ce
commit
d0729c2540
3
HISTORY
3
HISTORY
|
|
@ -1,8 +1,9 @@
|
||||||
|
|
||||||
Version 1.39 2018-07-10
|
Version 1.39 2018-07-16
|
||||||
* add #@function REPLACE_VARS
|
* add #@function REPLACE_VARS
|
||||||
* #@set value can embed %{VARIABLE}
|
* #@set value can embed %{VARIABLE}
|
||||||
* shared_func.h: add function starts_with and ends_with
|
* shared_func.h: add function starts_with and ends_with
|
||||||
|
* common_blocked_queue.h: add function common_blocked_queue_try_pop
|
||||||
|
|
||||||
Version 1.38 2018-06-26
|
Version 1.38 2018-06-26
|
||||||
* connection_pool.c: set err_no to 0 when success
|
* connection_pool.c: set err_no to 0 when success
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,8 @@ int common_blocked_queue_push(struct common_blocked_queue *queue, void *data)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *common_blocked_queue_pop(struct common_blocked_queue *queue)
|
void *common_blocked_queue_pop_ex(struct common_blocked_queue *queue,
|
||||||
|
const bool blocked)
|
||||||
{
|
{
|
||||||
struct common_blocked_node *node;
|
struct common_blocked_node *node;
|
||||||
void *data;
|
void *data;
|
||||||
|
|
@ -118,28 +119,36 @@ void *common_blocked_queue_pop(struct common_blocked_queue *queue)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
node = queue->head;
|
do {
|
||||||
if (node == NULL)
|
|
||||||
{
|
|
||||||
pthread_cond_wait(&(queue->cond), &(queue->lock));
|
|
||||||
node = queue->head;
|
node = queue->head;
|
||||||
}
|
if (node == NULL)
|
||||||
|
{
|
||||||
|
if (!blocked)
|
||||||
|
{
|
||||||
|
data = NULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (node != NULL)
|
pthread_cond_wait(&(queue->cond), &(queue->lock));
|
||||||
{
|
node = queue->head;
|
||||||
queue->head = node->next;
|
}
|
||||||
if (queue->head == NULL)
|
|
||||||
{
|
|
||||||
queue->tail = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
data = node->data;
|
if (node != NULL)
|
||||||
fast_mblock_free_object(&queue->mblock, node);
|
{
|
||||||
}
|
queue->head = node->next;
|
||||||
else
|
if (queue->head == NULL)
|
||||||
{
|
{
|
||||||
data = NULL;
|
queue->tail = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data = node->data;
|
||||||
|
fast_mblock_free_object(&queue->mblock, node);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
data = NULL;
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
|
||||||
if ((result=pthread_mutex_unlock(&(queue->lock))) != 0)
|
if ((result=pthread_mutex_unlock(&(queue->lock))) != 0)
|
||||||
{
|
{
|
||||||
|
|
@ -151,3 +160,4 @@ void *common_blocked_queue_pop(struct common_blocked_queue *queue)
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,18 @@ static inline void common_blocked_queue_terminate_all(
|
||||||
|
|
||||||
int common_blocked_queue_push(struct common_blocked_queue *queue, void *data);
|
int common_blocked_queue_push(struct common_blocked_queue *queue, void *data);
|
||||||
|
|
||||||
void *common_blocked_queue_pop(struct common_blocked_queue *queue);
|
void *common_blocked_queue_pop_ex(struct common_blocked_queue *queue,
|
||||||
|
const bool blocked);
|
||||||
|
|
||||||
|
static inline void *common_blocked_queue_pop(struct common_blocked_queue *queue)
|
||||||
|
{
|
||||||
|
return common_blocked_queue_pop_ex(queue, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void *common_blocked_queue_try_pop(struct common_blocked_queue *queue)
|
||||||
|
{
|
||||||
|
return common_blocked_queue_pop_ex(queue, false);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue