Add a helper function to detect when a ckmsgq is empty
This commit is contained in:
parent
ff2ee66e77
commit
90f5936956
16
src/ckpool.c
16
src/ckpool.c
@ -148,8 +148,8 @@ ckmsgq_t *create_ckmsgq(ckpool_t *ckp, const char *name, const void *func)
|
||||
return ckmsgq;
|
||||
}
|
||||
|
||||
/* Generic function for adding messages to a ckmsgq linked list and signal the ckmsgq
|
||||
* parsing thread to wake up and process it. */
|
||||
/* Generic function for adding messages to a ckmsgq linked list and signal the
|
||||
* ckmsgq parsing thread to wake up and process it. */
|
||||
void ckmsgq_add(ckmsgq_t *ckmsgq, void *data)
|
||||
{
|
||||
ckmsg_t *msg = ckalloc(sizeof(ckmsg_t));
|
||||
@ -162,6 +162,18 @@ void ckmsgq_add(ckmsgq_t *ckmsgq, void *data)
|
||||
mutex_unlock(&ckmsgq->lock);
|
||||
}
|
||||
|
||||
/* Return whether there are any messages queued in the ckmsgq linked list. */
|
||||
bool ckmsgq_empty(ckmsgq_t *ckmsgq)
|
||||
{
|
||||
bool ret;
|
||||
|
||||
mutex_lock(&ckmsgq->lock);
|
||||
ret = (ckmsgq->msgs->next == ckmsgq->msgs->prev);
|
||||
mutex_unlock(&ckmsgq->lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void broadcast_proc(ckpool_t *ckp, const char *buf)
|
||||
{
|
||||
int i;
|
||||
|
||||
@ -173,6 +173,7 @@ struct ckpool_instance {
|
||||
|
||||
ckmsgq_t *create_ckmsgq(ckpool_t *ckp, const char *name, const void *func);
|
||||
void ckmsgq_add(ckmsgq_t *ckmsgq, void *data);
|
||||
bool ckmsgq_empty(ckmsgq_t *ckmsgq);
|
||||
|
||||
ckpool_t *global_ckp;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user