Ignore:
Timestamp:
04/10/14 01:24:05 (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:
df668eb
Parents:
fb1fd42
Message:

Use size_t rather than int for the data structures. Export vector, deque and ring_buffer for testing and use in programs.
Remove some inlines for now since these result in lots of compile warnings when also exported, the compiler is probably smart enough anyway.

File:
1 edited

Legend:

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

    rd6a56b6 read9478  
    55#include <assert.h>
    66
    7 DLLEXPORT inline void libtrace_vector_init(libtrace_vector_t *v, int element_size) {
     7DLLEXPORT void libtrace_vector_init(libtrace_vector_t *v, size_t element_size) {
    88        v->element_size = element_size;
    99        v->size = 0; // Starts empty
     
    1313}
    1414
    15 DLLEXPORT inline void libtrace_vector_destroy(libtrace_vector_t *v) {
     15DLLEXPORT void libtrace_vector_destroy(libtrace_vector_t *v) {
    1616        assert(pthread_mutex_destroy(&v->lock) == 0);
    1717        free(v->elements);
     
    2323}
    2424
    25 DLLEXPORT inline void libtrace_vector_push_back(libtrace_vector_t *v, void *d) {
     25DLLEXPORT void libtrace_vector_push_back(libtrace_vector_t *v, void *d) {
    2626        assert(pthread_mutex_lock(&v->lock) == 0);
    2727        if (v->size >= v->max_size) {
     
    3636}
    3737
    38 DLLEXPORT inline int libtrace_vector_get_size(libtrace_vector_t *v) {
     38DLLEXPORT size_t libtrace_vector_get_size(libtrace_vector_t *v) {
    3939        return v->size;
    4040}
    4141
    42 DLLEXPORT inline int libtrace_vector_get(libtrace_vector_t *v, int location, void *d) {
     42DLLEXPORT int libtrace_vector_get(libtrace_vector_t *v, size_t location, void *d) {
    4343        assert(pthread_mutex_lock(&v->lock) == 0);
    4444        if (location >= v->size) {
     
    5151}
    5252
    53 DLLEXPORT inline int libtrace_vector_remove_front(libtrace_vector_t *v) {
    54         int i;
     53DLLEXPORT int libtrace_vector_remove_front(libtrace_vector_t *v) {
     54        size_t i;
    5555        assert(pthread_mutex_lock(&v->lock) == 0);
    5656        if (!v->size) {
     
    6666}
    6767
    68 static inline void memswap(void *a, void *b, int size) {
     68static inline void memswap(void *a, void *b, size_t size) {
    6969        char c;
    70         int i;
     70        size_t i;
    7171        for (i=0; i<size; i++) {
    7272                c = ((char *)a)[i];
     
    7676}
    7777// Note elements must be the same size
    78 DLLEXPORT inline void libtrace_vector_append(libtrace_vector_t *dest, libtrace_vector_t *src)
     78// This also empties the second source array
     79DLLEXPORT void libtrace_vector_append(libtrace_vector_t *dest, libtrace_vector_t *src)
    7980{
    8081        assert(dest->element_size == src->element_size);
     
    9192                memswap(&dest->elements, &src->elements, sizeof(src->elements));
    9293        } else {
    93                 int oldmax = dest->max_size;
     94                size_t oldmax = dest->max_size;
    9495                while (dest->max_size - dest->size < src->size) dest->max_size *= 2;
    9596                if (oldmax != dest->max_size)
     
    107108}
    108109
    109 DLLEXPORT inline void libtrace_zero_vector(libtrace_vector_t *v)
     110DLLEXPORT void libtrace_zero_vector(libtrace_vector_t *v)
    110111{
    111112        v->max_size = 0;
     
    115116}
    116117
    117 DLLEXPORT inline void libtrace_vector_empty(libtrace_vector_t *v) {
     118DLLEXPORT void libtrace_vector_empty(libtrace_vector_t *v) {
    118119        assert(pthread_mutex_lock(&v->lock) == 0);
    119120        v->size = 0;
Note: See TracChangeset for help on using the changeset viewer.