Ignore:
Timestamp:
07/30/14 18:44:16 (7 years ago)
Author:
Richard Sanger <rsangerarj@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
be3f75b
Parents:
41148f2
Message:

Add an object cache with thread local caches
All packets used by a trace are put through this.
Adds bulk read/write operations to the ringbuffer (used by the object cache)
Replace semaphores with condition variables to support these bulk operations.
Internally use bulk read operations from a single threaded formats to reduce lock overhead.
Replaces the asserts around pthread_* functions with a version that will still run the command if NDEBUG

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/test-datastruct-ringbuffer.c

    r19135af ra49a9eb  
    2626}
    2727
     28static void * producer_bulk(void * a) {
     29        libtrace_ringbuffer_t * rb = (libtrace_ringbuffer_t *) a;
     30        char * i;
     31        for (i = NULL; i < TEST_SIZE; i++) {
     32                assert(libtrace_ringbuffer_write_bulk(rb, (void **) &i, 1, 1) == 1);
     33        }
     34        return 0;
     35}
     36
     37static void * consumer_bulk(void * a) {
     38        libtrace_ringbuffer_t * rb = (libtrace_ringbuffer_t *) a;
     39        char *i;
     40        void *value;
     41        for (i = NULL; i < TEST_SIZE; i++) {
     42                assert (libtrace_ringbuffer_read_bulk(rb, &value, 1, 1) == 1);
     43                assert(value == i);
     44        }
     45        return 0;
     46}
     47
     48
    2849/**
    2950 * Tests the ringbuffer data structure, first this establishes that single
     
    3960
    4061        libtrace_ringbuffer_init(&rb_block, (size_t) RINGBUFFER_SIZE, LIBTRACE_RINGBUFFER_BLOCKING);
    41         libtrace_ringbuffer_init(&rb_polling, (size_t) RINGBUFFER_SIZE, LIBTRACE_RINGBUFFER_BLOCKING);
     62        libtrace_ringbuffer_init(&rb_polling, (size_t) RINGBUFFER_SIZE, LIBTRACE_RINGBUFFER_POLLING);
    4263        assert(libtrace_ringbuffer_is_empty(&rb_block));
    4364        assert(libtrace_ringbuffer_is_empty(&rb_polling));
     
    105126        assert(libtrace_ringbuffer_is_empty(&rb_polling));
    106127
     128        pthread_create(&t[0], NULL, &producer_bulk, (void *) &rb_block);
     129        pthread_create(&t[1], NULL, &consumer_bulk, (void *) &rb_block);
     130        pthread_join(t[0], NULL);
     131        pthread_join(t[1], NULL);
     132        assert(libtrace_ringbuffer_is_empty(&rb_block));
     133
     134        pthread_create(&t[0], NULL, &producer_bulk, (void *) &rb_polling);
     135        pthread_create(&t[1], NULL, &consumer_bulk, (void *) &rb_polling);
     136        pthread_join(t[0], NULL);
     137        pthread_join(t[1], NULL);
     138        assert(libtrace_ringbuffer_is_empty(&rb_polling));
     139
    107140        return 0;
    108141}
Note: See TracChangeset for help on using the changeset viewer.