예제 #1
0
int wait_destroy_match (waitqueue_t *q, wait_compare_f cb, void *arg)
{
    zlist_t *tmp = NULL;
    wait_t *w;
    int rc = -1;
    int count = 0;

    assert (q->magic == WAITQUEUE_MAGIC);

    w = zlist_first (q->q);
    while (w) {
        if (w->hand.msg && cb != NULL && cb (w->hand.msg, arg)) {
            if (!tmp && !(tmp = zlist_new ()))
                oom ();
            if (zlist_append (tmp, w) < 0)
                oom ();
            w->hand.cb = NULL; // prevent wait_runone from restarting handler
            count++;
        }
        w = zlist_next (q->q);
    }
    if (tmp) {
        while ((w = zlist_pop (tmp))) {
            zlist_remove (q->q, w);
            if (--w->usecount == 0)
                wait_destroy (w, NULL);
        }
    }
    rc = count;
    zlist_destroy (&tmp);
    return rc;
}
예제 #2
0
void wait_runone (wait_t *w)
{
    assert (w->magic == WAIT_MAGIC);

    if (--w->usecount == 0) {
        if (w->hand.cb)
            w->hand.cb (w->hand.h, w->hand.w, w->hand.msg, w->hand.arg);
        wait_destroy (w, NULL);
    }
}
예제 #3
0
static void wait_runone (wait_t *w)
{
    if (--w->usecount == 0) {
        if (w->cb)
            w->cb (w->cb_arg);
        else if (w->hand.cb)
            w->hand.cb (w->hand.h, w->hand.w, w->hand.msg, w->hand.arg);
        wait_destroy (w);
    }
}
예제 #4
0
void wait_queue_destroy (waitqueue_t *q)
{
    wait_t *w;

    assert (q->magic == WAITQUEUE_MAGIC);
    while ((w = zlist_pop (q->q))) {
        if (--w->usecount == 0)
            wait_destroy (w, NULL);
    }
    zlist_destroy (&q->q);
    q->magic = ~WAITQUEUE_MAGIC;
    free (q);
}
예제 #5
0
wait_t *wait_create (flux_t h, flux_msg_handler_t *wh, const flux_msg_t *msg,
                     flux_msg_handler_f cb, void *arg)
{
    wait_t *w = xzmalloc (sizeof (*w));
    w->magic = WAIT_MAGIC;
    w->hand.cb = cb;
    w->hand.arg = arg;
    w->hand.h = h;
    w->hand.w = wh;
    if (!(w->hand.msg = flux_msg_copy (msg, true))) {
        wait_destroy (w, NULL);
        errno = ENOMEM;
        return NULL;
    }
    monotime (&w->t0);
    return w;
}
예제 #6
0
wait_t *wait_create_msg_handler (flux_t *h, flux_msg_handler_t *wh,
                                 const flux_msg_t *msg,
                                 flux_msg_handler_f cb, void *arg)
{
    wait_t *w = wait_create (NULL, NULL);
    if (w) {
        w->hand.cb = cb;
        w->hand.arg = arg;
        w->hand.h = h;
        w->hand.w = wh;
        if (msg && !(w->hand.msg = flux_msg_copy (msg, true))) {
            wait_destroy (w);
            errno = ENOMEM;
            return NULL;
        }
    }
    return w;
}