Changeset 04bf7c5 for lib/data-struct


Ignore:
Timestamp:
01/20/15 09: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:
75e088f, fed9152
Parents:
b73407f
Message:

Remove unused sliding window code.
Refactored pstart and added some proper error handling.

Location:
lib/data-struct
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • lib/data-struct/object_cache.c

    r6e41e73 r04bf7c5  
    175175  *             reads will block (free never should).Otherwise packets can be freely
    176176  *     allocated upon requested and are free'd if there is not enough space for them.
    177   * @return Returns The number of packets outstanding, or extra object recevied
    178   *             Ideally this should be zero (0) otherwise some form of memory leak
    179   *             is likely present.
     177  * @return If successful returns 0 otherwise -1.
    180178  */
    181 DLLEXPORT void libtrace_ocache_init(libtrace_ocache_t *oc, void *(*alloc)(void), void (*free)(void *),
    182                                                                           size_t thread_cache_size, size_t buffer_size, bool limit_size) {
     179DLLEXPORT int libtrace_ocache_init(libtrace_ocache_t *oc, void *(*alloc)(void),
     180                                    void (*free)(void *),
     181                                    size_t thread_cache_size,
     182                                    size_t buffer_size, bool limit_size) {
    183183
    184184        assert(buffer_size);
    185185        assert(alloc);
    186186        assert(free);
    187         libtrace_ringbuffer_init(&oc->rb, buffer_size, LIBTRACE_RINGBUFFER_BLOCKING);
     187        if (libtrace_ringbuffer_init(&oc->rb, buffer_size, LIBTRACE_RINGBUFFER_BLOCKING) != 0) {
     188                return -1;
     189        }
    188190        oc->alloc = alloc;
    189191        oc->free = free;
     
    193195        oc->max_nb_thread_list = 0x10;
    194196        oc->thread_list = calloc(0x10, sizeof(void*));
     197        if (oc->thread_list == NULL) {
     198                libtrace_ringbuffer_destroy(&oc->rb);
     199                return -1;
     200        }
    195201        pthread_spin_init(&oc->spin, 0);
    196202        if (limit_size)
     
    198204        else
    199205                oc->max_allocations = 0;
     206        return 0;
    200207}
    201208
  • lib/data-struct/object_cache.h

    r6e41e73 r04bf7c5  
    2020} libtrace_ocache_t;
    2121
    22 DLLEXPORT void libtrace_ocache_init(libtrace_ocache_t *oc, void *(*alloc)(void), void (*free)(void*),
     22DLLEXPORT int libtrace_ocache_init(libtrace_ocache_t *oc, void *(*alloc)(void), void (*free)(void*),
    2323                                    size_t thread_cache_size, size_t buffer_size, bool limit_size);
    2424DLLEXPORT int libtrace_ocache_destroy(libtrace_ocache_t *oc);
  • lib/data-struct/ring_buffer.c

    ra49a9eb r04bf7c5  
    4747 *                              becomes available. LIBTRACE_RINGBUFFER_BLOCKING or LIBTRACE_RINGBUFFER_POLLING.
    4848 *                              NOTE: this mainly applies to the blocking functions
    49  */
    50 DLLEXPORT void libtrace_ringbuffer_init(libtrace_ringbuffer_t * rb, size_t size, int mode) {
     49 * @return If successful returns 0 otherwise -1 upon failure.
     50 */
     51DLLEXPORT int libtrace_ringbuffer_init(libtrace_ringbuffer_t * rb, size_t size, int mode) {
    5152        size = size + 1;
    52         assert (size > 1);
    53         rb->size = size; // Only this -1 actually usable :)
     53        if (!(size > 1))
     54                return -1;
     55        rb->size = size;
    5456        rb->start = 0;
    5557        rb->end = 0;
    5658        rb->elements = calloc(rb->size, sizeof(void*));
    57         assert(rb->elements);
     59        if (!rb->elements)
     60                return -1;
    5861        rb->mode = mode;
    5962        if (mode == LIBTRACE_RINGBUFFER_BLOCKING) {
    60                 /* The signaling part - i.e. release when data's ready to read */
     63                /* The signaling part - i.e. release when data is ready to read */
    6164                pthread_cond_init(&rb->full_cond, NULL);
    6265                pthread_cond_init(&rb->empty_cond, NULL);
     
    7578        ASSERT_RET(pthread_mutex_init(&rb->rlock, NULL), == 0);
    7679#endif
     80        return 0;
    7781}
    7882
  • lib/data-struct/ring_buffer.h

    ra49a9eb r04bf7c5  
    3232} libtrace_ringbuffer_t;
    3333
    34 DLLEXPORT void libtrace_ringbuffer_init(libtrace_ringbuffer_t * rb, size_t size, int mode);
     34DLLEXPORT int libtrace_ringbuffer_init(libtrace_ringbuffer_t * rb, size_t size, int mode);
    3535DLLEXPORT void libtrace_zero_ringbuffer(libtrace_ringbuffer_t * rb);
    3636DLLEXPORT void libtrace_ringbuffer_destroy(libtrace_ringbuffer_t * rb);
Note: See TracChangeset for help on using the changeset viewer.