diff --git a/src/ckpool.c b/src/ckpool.c index 7d7d8515..21802096 100644 --- a/src/ckpool.c +++ b/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; diff --git a/src/ckpool.h b/src/ckpool.h index 16a2f998..e7715d47 100644 --- a/src/ckpool.h +++ b/src/ckpool.h @@ -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;