Beispiel #1
0
static void
test_pool_2_timeout(void * array, unsigned array_index, void * caller_info)
{
    SXEE82("test_pool_2_timeout(array=%p,array_index=%u)", array, array_index);
    SXE_UNUSED_PARAMETER(caller_info);
    test_pool_2_timeout_call_count ++;

    if (1 == test_pool_2_timeout_call_count) {
        sxe_pool_set_indexed_element_state(array, array_index, TEST_STATE_USED,   TEST_STATE_FREE);
    }

    if (2 == test_pool_2_timeout_call_count) {
        sxe_pool_set_indexed_element_state(array, array_index, TEST_STATE_ABUSED, TEST_STATE_USED);
    }

    if (3 == test_pool_2_timeout_call_count) {
        sxe_pool_set_indexed_element_state(array, array_index, TEST_STATE_USED,   TEST_STATE_FREE);
    }

    SXER80("return");
}
Beispiel #2
0
/**
 * Add an element to the hash
 *
 * @param array = Pointer to the hash array
 * @param id    = Index of the element to hash
 */
void
sxe_hash_add(void * array, unsigned id)
{
    SXE_HASH * hash = SXE_HASH_ARRAY_TO_IMPL(array);
    void     * key;
    unsigned   bucket;

    SXEE6("sxe_hash_add(hash=%s,id=%u)", sxe_pool_get_name(array), id);

    key = &((char *)array)[id * hash->size + hash->key_offset];
    bucket = hash->hash_key(key, hash->key_size) % hash->count + SXE_HASH_BUCKETS_RESERVED;
    SXEL6("Adding element %u to bucket %u", id, bucket);
    sxe_pool_set_indexed_element_state(array, id, SXE_HASH_NEW_BUCKET, bucket);
    SXER6("return");
}
Beispiel #3
0
int
main(int argc, char ** argv)
{
    int             fd;
    double          start_time;
    unsigned        count = 0;                   /* e.g. master=0, slaves=1, 2, 3, etc */
    char          * unique_memmap_path_and_file; /* e.g. /tmp/test-sxe-pool-mmap-pid-1234.bin */
    char            unique_memmap_path_and_file_master_buffer[PATH_MAX];
    unsigned        unique_memmap_path_and_file_master_buffer_used;
    unsigned        id;
    unsigned      * pool;
    unsigned      * shared;
    size_t          size;
    SXE_MMAP        memmap;
    int             child[TEST_CLIENT_INSTANCES];
    SXE_POOL_WALKER walker;

    putenv(SXE_CAST_NOCONST(char *, "SXE_LOG_LEVEL_LIBSXE_LIB_SXE_POOL=5"));    /* Set to 5 to suppress sxe-pool debug logging since this is kind of a stress test */
    putenv(SXE_CAST_NOCONST(char *, "SXE_LOG_LEVEL_LIBSXE_LIB_SXE_LIST=5"));    /* Set to 5 to suppress sxe-list debug logging since this is kind of a stress test */

    if (argc > 1) {
        count                       = atoi(argv[1]);
        unique_memmap_path_and_file =      argv[2] ;

        SXEL1("Instance %2u unique memmap path and file: %s", count, unique_memmap_path_and_file);
        sxe_mmap_open(&memmap, unique_memmap_path_and_file);
        shared  = SXE_CAST(unsigned *, SXE_MMAP_ADDR(&memmap));
        pool    = sxe_pool_from_base(shared);
        SXEL6("Instance %2u mapped to shared pool // base=%p, pool=%p", count, shared, pool);

        do {
            usleep(10000 * count);
            id = sxe_pool_set_oldest_element_state(pool, TEST_STATE_FREE, TEST_STATE_CLIENT_TAKE);
            SXEA1(id != SXE_POOL_LOCK_NOT_TAKEN, "Got SXE_POOL_LOCK_NOT_TAKEN");;
        } while (id == SXE_POOL_NO_INDEX);

        SXEL6("Instance %2u got pool element %u", count, id);
        pool[id] = count;
        sxe_pool_set_indexed_element_state(pool, id, TEST_STATE_CLIENT_TAKE, TEST_STATE_CLIENT_DONE);
        sxe_mmap_close(&memmap);
        SXEL6("Instance %2u exiting", count);
        return 0;
    }