Browse Source

Add a helper function to detect when a ckmsgq is empty

master
Con Kolivas 10 years ago
parent
commit
90f5936956
  1. 16
      src/ckpool.c
  2. 1
      src/ckpool.h

16
src/ckpool.c

@ -148,8 +148,8 @@ ckmsgq_t *create_ckmsgq(ckpool_t *ckp, const char *name, const void *func)
return ckmsgq; return ckmsgq;
} }
/* Generic function for adding messages to a ckmsgq linked list and signal the ckmsgq /* Generic function for adding messages to a ckmsgq linked list and signal the
* parsing thread to wake up and process it. */ * ckmsgq parsing thread to wake up and process it. */
void ckmsgq_add(ckmsgq_t *ckmsgq, void *data) void ckmsgq_add(ckmsgq_t *ckmsgq, void *data)
{ {
ckmsg_t *msg = ckalloc(sizeof(ckmsg_t)); ckmsg_t *msg = ckalloc(sizeof(ckmsg_t));
@ -162,6 +162,18 @@ void ckmsgq_add(ckmsgq_t *ckmsgq, void *data)
mutex_unlock(&ckmsgq->lock); 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) static void broadcast_proc(ckpool_t *ckp, const char *buf)
{ {
int i; int i;

1
src/ckpool.h

@ -173,6 +173,7 @@ struct ckpool_instance {
ckmsgq_t *create_ckmsgq(ckpool_t *ckp, const char *name, const void *func); ckmsgq_t *create_ckmsgq(ckpool_t *ckp, const char *name, const void *func);
void ckmsgq_add(ckmsgq_t *ckmsgq, void *data); void ckmsgq_add(ckmsgq_t *ckmsgq, void *data);
bool ckmsgq_empty(ckmsgq_t *ckmsgq);
ckpool_t *global_ckp; ckpool_t *global_ckp;

Loading…
Cancel
Save