add function common_blocked_queue_push_ex
parent
d3b0c5dfb0
commit
2df796589c
|
|
@ -50,11 +50,11 @@ void common_blocked_queue_destroy(struct common_blocked_queue *queue)
|
|||
pthread_mutex_destroy(&(queue->lock));
|
||||
}
|
||||
|
||||
int common_blocked_queue_push(struct common_blocked_queue *queue, void *data)
|
||||
int common_blocked_queue_push_ex(struct common_blocked_queue *queue,
|
||||
void *data, bool *notify)
|
||||
{
|
||||
int result;
|
||||
struct common_blocked_node *node;
|
||||
bool notify;
|
||||
|
||||
if ((result=pthread_mutex_lock(&(queue->lock))) != 0)
|
||||
{
|
||||
|
|
@ -75,16 +75,15 @@ int common_blocked_queue_push(struct common_blocked_queue *queue, void *data)
|
|||
|
||||
node->data = data;
|
||||
node->next = NULL;
|
||||
|
||||
if (queue->tail == NULL)
|
||||
{
|
||||
queue->head = node;
|
||||
notify = true;
|
||||
*notify = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
queue->tail->next = node;
|
||||
notify = false;
|
||||
*notify = false;
|
||||
}
|
||||
queue->tail = node;
|
||||
|
||||
|
|
@ -96,11 +95,6 @@ int common_blocked_queue_push(struct common_blocked_queue *queue, void *data)
|
|||
__LINE__, result, STRERROR(result));
|
||||
}
|
||||
|
||||
if (notify)
|
||||
{
|
||||
pthread_cond_signal(&(queue->cond));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -61,7 +61,27 @@ static inline void common_blocked_queue_terminate_all(
|
|||
}
|
||||
}
|
||||
|
||||
int common_blocked_queue_push(struct common_blocked_queue *queue, void *data);
|
||||
//notify by the caller
|
||||
int common_blocked_queue_push_ex(struct common_blocked_queue *queue,
|
||||
void *data, bool *notify);
|
||||
|
||||
static inline int common_blocked_queue_push(struct common_blocked_queue
|
||||
*queue, void *data)
|
||||
{
|
||||
bool notify;
|
||||
int result;
|
||||
|
||||
if ((result=common_blocked_queue_push_ex(queue, data, ¬ify)) == 0)
|
||||
{
|
||||
if (notify)
|
||||
{
|
||||
pthread_cond_signal(&(queue->cond));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void common_blocked_queue_return_nodes(struct common_blocked_queue *queue,
|
||||
struct common_blocked_node *node);
|
||||
|
|
|
|||
Loading…
Reference in New Issue