示例#1
0
static void
ngx_http_js_cleanup_mem_cache_pool(void *data)
{
    nxt_mem_cache_pool_t *mcp = data;

    nxt_mem_cache_pool_destroy(mcp);
}
示例#2
0
static nxt_int_t
lvlhsh_unit_test(nxt_uint_t n)
{
    uintptr_t            key;
    nxt_uint_t            i;
    nxt_lvlhsh_t          lh;
    nxt_lvlhsh_each_t     lhe;
    nxt_mem_cache_pool_t  *pool;

    const size_t         min_chunk_size = 32;
    const size_t         page_size = 1024;
    const size_t         page_alignment = 128;
    const size_t         cluster_size = 4096;

    pool = nxt_mem_cache_pool_create(&mem_cache_pool_proto, NULL, NULL,
                                    cluster_size, page_alignment,
                                    page_size, min_chunk_size);
    if (pool == NULL) {
        return NXT_ERROR;
    }

    printf("lvlhsh unit test started: %ld items\n", (long) n);

    memset(&lh, 0, sizeof(nxt_lvlhsh_t));

    key = 0;
    for (i = 0; i < n; i++) {
        key = nxt_murmur_hash2(&key, sizeof(uint32_t));

        if (lvlhsh_unit_test_add(&lh, &lvlhsh_proto, pool, key) != NXT_OK) {
            printf("lvlhsh add unit test failed at %ld\n", (long) i);
            return NXT_ERROR;
        }
    }

    key = 0;
    for (i = 0; i < n; i++) {
        key = nxt_murmur_hash2(&key, sizeof(uint32_t));

        if (lvlhsh_unit_test_get(&lh, &lvlhsh_proto, key) != NXT_OK) {
            return NXT_ERROR;
        }
    }

    memset(&lhe, 0, sizeof(nxt_lvlhsh_each_t));
    lhe.proto = &lvlhsh_proto;

    for (i = 0; i < n + 1; i++) {
        if (nxt_lvlhsh_each(&lh, &lhe) == NULL) {
            break;
        }
    }

    if (i != n) {
        printf("lvlhsh each unit test failed at %ld of %ld\n",
                (long) i, (long) n);
        return NXT_ERROR;
    }

    key = 0;
    for (i = 0; i < n; i++) {
        key = nxt_murmur_hash2(&key, sizeof(uint32_t));

        if (lvlhsh_unit_test_delete(&lh, &lvlhsh_proto, pool, key) != NXT_OK) {
            return NXT_ERROR;
        }
    }

    if (!nxt_mem_cache_pool_is_empty(pool)) {
        printf("mem cache pool is not empty\n");
        return NXT_ERROR;
    }

    nxt_mem_cache_pool_destroy(pool);

    printf("lvlhsh unit test passed\n");

    return NXT_OK;
}