static void mailbox_destroy(struct mailbox *mbox) { struct message *msg; while ((msg = VSTAILQ_FIRST(&mbox->messages))) { VSTAILQ_REMOVE_HEAD(&mbox->messages, list); free(msg); } pthread_cond_destroy(&mbox->has_mail); pthread_mutex_destroy(&mbox->lock); }
static struct message * mailbox_get(struct mailbox *mbox) { struct message *msg; pthread_mutex_lock(&mbox->lock); while ((msg = VSTAILQ_FIRST(&mbox->messages)) == NULL && mbox->open) pthread_cond_wait(&mbox->has_mail, &mbox->lock); if (msg != NULL) VSTAILQ_REMOVE_HEAD(&mbox->messages, list); pthread_mutex_unlock(&mbox->lock); return (msg); }
exp_thread(struct worker *wrk, void *priv) { struct objcore *oc; double t = 0, tnext = 0; struct exp_priv *ep; unsigned flags = 0; CAST_OBJ_NOTNULL(ep, priv, EXP_PRIV_MAGIC); ep->wrk = wrk; VSL_Setup(&ep->vsl, NULL, 0); ep->heap = binheap_new(NULL, object_cmp, object_update); AN(ep->heap); while (1) { Lck_Lock(&ep->mtx); oc = VSTAILQ_FIRST(&ep->inbox); CHECK_OBJ_ORNULL(oc, OBJCORE_MAGIC); if (oc != NULL) { assert(oc->refcnt >= 1); VSTAILQ_REMOVE(&ep->inbox, oc, objcore, exp_list); VSC_C_main->exp_received++; tnext = 0; flags = oc->exp_flags; if (flags & OC_EF_REMOVE) oc->exp_flags = 0; else oc->exp_flags &= OC_EF_REFD; } else if (tnext > t) { VSL_Flush(&ep->vsl, 0); Pool_Sumstat(wrk); (void)Lck_CondWait(&ep->condvar, &ep->mtx, tnext); } Lck_Unlock(&ep->mtx); t = VTIM_real(); if (oc != NULL) exp_inbox(ep, oc, flags); else tnext = exp_expire(ep, t); } NEEDLESS(return NULL); }