Esempio n. 1
0
static void test_unsigned(void) {
        unsigned buffer[SET_SIZE], i;
        Prioq *q;

        srand(0);

        q = prioq_new(trivial_compare_func);
        assert_se(q);

        for (i = 0; i < ELEMENTSOF(buffer); i++) {
                unsigned u;

                u = (unsigned) rand();
                buffer[i] = u;
                assert_se(prioq_put(q, UINT_TO_PTR(u), NULL) >= 0);
        }

        qsort(buffer, ELEMENTSOF(buffer), sizeof(buffer[0]), unsigned_compare);

        for (i = 0; i < ELEMENTSOF(buffer); i++) {
                unsigned u;

                assert_se(prioq_size(q) == ELEMENTSOF(buffer) - i);

                u = PTR_TO_UINT(prioq_pop(q));
                assert_se(buffer[i] == u);
        }

        assert_se(prioq_isempty(q));
        prioq_free(q);
}
Esempio n. 2
0
_public_ sd_lldp* sd_lldp_unref(sd_lldp *lldp) {

        if (!lldp)
                return NULL;

        lldp_flush_neighbors(lldp);

        hashmap_free(lldp->neighbor_by_id);
        prioq_free(lldp->neighbor_by_expiry);

        sd_event_source_unref(lldp->io_event_source);
        sd_event_source_unref(lldp->timer_event_source);
        sd_event_unref(lldp->event);
        safe_close(lldp->fd);

        free(lldp);

        return NULL;
}
Esempio n. 3
0
_public_ sd_lldp* sd_lldp_unref(sd_lldp *lldp) {

        if (!lldp)
                return NULL;

        assert(lldp->n_ref > 0);
        lldp->n_ref --;

        if (lldp->n_ref > 0)
                return NULL;

        lldp_reset(lldp);
        sd_lldp_detach_event(lldp);
        lldp_flush_neighbors(lldp);

        hashmap_free(lldp->neighbor_by_id);
        prioq_free(lldp->neighbor_by_expiry);
        return mfree(lldp);
}
Esempio n. 4
0
static void test_struct(void) {
        Prioq *q;
        Set *s;
        unsigned previous = 0, i;
        int r;

        srand(0);

        q = prioq_new(test_compare);
        assert_se(q);

        s = set_new(test_hash, test_compare);
        assert_se(s);

        for (i = 0; i < SET_SIZE; i++) {
                struct test *t;

                t = new0(struct test, 1);
                assert_se(t);
                t->value = (unsigned) rand();

                r = prioq_put(q, t, &t->idx);
                assert_se(r >= 0);

                if (i % 4 == 0) {
                        r = set_consume(s, t);
                        assert_se(r >= 0);
                }
        }

        for (;;) {
                struct test *t;

                t = set_steal_first(s);
                if (!t)
                        break;

                r = prioq_remove(q, t, &t->idx);
                assert_se(r > 0);

                free(t);
        }

        for (i = 0; i < SET_SIZE * 3 / 4; i++) {
                struct test *t;

                assert_se(prioq_size(q) == (SET_SIZE * 3 / 4) - i);

                t = prioq_pop(q);
                assert_se(t);

                assert_se(previous <= t->value);
                previous = t->value;
                free(t);
        }

        assert_se(prioq_isempty(q));
        prioq_free(q);

        assert_se(set_isempty(s));
        set_free(s);
}