Changeset b5cd711 for lib/fifo.c


Ignore:
Timestamp:
08/26/05 11:22:23 (16 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, 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:
53f8305
Parents:
1974620
Message:

Changed all references to "fifo" to "tracefifo" with regards to function names and structures.
Fixes namespace conflicts with libfifo.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/fifo.c

    r23c13e8 rb5cd711  
    5757enum which_t { IN, OUT, ACK };
    5858
    59 struct fifo_t {
     59struct tracefifo_t {
    6060        size_t length;
    6161        size_t datamap[3];
     
    6666
    6767
    68 static char *fifo_stat_buffer = 0;
    69 
    70 static void increment_pointer(struct fifo_t *fifo, enum which_t which, int amount);
    71 static void set_pointer(struct fifo_t *fifo, enum which_t which, int location);
    72 static size_t fifo_compare(struct fifo_t *fifo, enum which_t first, enum which_t second);
    73 static int fifo_read_generic(struct fifo_t *fifo, void *buffer, size_t len, enum which_t which, char update);
    74 
    75 struct fifo_t *create_fifo(size_t size)
     68static char *tracefifo_stat_buffer = 0;
     69
     70static void increment_pointer(struct tracefifo_t *fifo, enum which_t which, int amount);
     71static void set_pointer(struct tracefifo_t *fifo, enum which_t which, int location);
     72static size_t tracefifo_compare(struct tracefifo_t *fifo, enum which_t first, enum which_t second);
     73static int tracefifo_read_generic(struct tracefifo_t *fifo, void *buffer, size_t len, enum which_t which, char update);
     74
     75struct tracefifo_t *create_tracefifo(size_t size)
    7676{
    7777        /* Set up our fifo
    7878        */
    79         struct fifo_t *fifo = malloc(sizeof(struct fifo_t));
     79        struct tracefifo_t *fifo = malloc(sizeof(struct tracefifo_t));
    8080        assert(size > 0);
    8181
    82         if (fifo_stat_buffer == 0)
    83                 fifo_stat_buffer = (char *)malloc(513);
     82        if (tracefifo_stat_buffer == 0)
     83                tracefifo_stat_buffer = (char *)malloc(513);
    8484        fifo->length = size;
    8585
     
    9595}
    9696
    97 void destroy_fifo(struct fifo_t *fifo)
    98 {
    99         assert(fifo);
    100         //free(fifo_stat_buffer);
     97void destroy_tracefifo(struct tracefifo_t *fifo)
     98{
     99        assert(fifo);
     100        //free(tracefifo_stat_buffer);
    101101        free(fifo->base);
    102102        free(fifo);
    103103}
    104104
    105 static void increment_pointer(struct fifo_t *fifo, enum which_t which, int amount) {
     105static void increment_pointer(struct tracefifo_t *fifo, enum which_t which, int amount) {
    106106        assert(fifo);
    107107        assert(which == IN || which == OUT || which == ACK);
     
    115115}
    116116
    117 void fifo_flush(struct fifo_t *fifo) {
     117void tracefifo_flush(struct tracefifo_t *fifo) {
    118118        // do nothing
    119119        return;
    120120}
    121121
    122 static void set_pointer(struct fifo_t *fifo, enum which_t which, int location) {
     122static void set_pointer(struct tracefifo_t *fifo, enum which_t which, int location) {
    123123        assert(fifo);
    124124        assert(which == IN || which == OUT || which == ACK);
     
    130130}
    131131
    132 static size_t fifo_compare(struct fifo_t *fifo, enum which_t first, enum which_t second) {
     132static size_t tracefifo_compare(struct tracefifo_t *fifo, enum which_t first, enum which_t second) {
    133133        assert(fifo);
    134134        assert(first == IN || first == OUT || first == ACK);
     
    145145}
    146146
    147 size_t fifo_free(struct fifo_t *fifo) {
    148         assert(fifo);
    149         return (fifo->length - fifo_compare(fifo,IN,ACK));
     147size_t tracefifo_free(struct tracefifo_t *fifo) {
     148        assert(fifo);
     149        return (fifo->length - tracefifo_compare(fifo,IN,ACK));
    150150}
    151151
    152 size_t fifo_length(struct fifo_t *fifo) {
     152size_t tracefifo_length(struct tracefifo_t *fifo) {
    153153        assert(fifo);
    154154        return fifo->length;
    155155}
    156156
    157 size_t fifo_out_available(struct fifo_t *fifo) {
    158         assert(fifo);
    159         return fifo_compare(fifo,IN,OUT);
    160 }
    161 
    162 size_t fifo_ack_available(struct fifo_t *fifo) {
    163         assert(fifo);
    164         return fifo_compare(fifo,OUT,ACK);
    165 }
    166 
    167 void fifo_stat_int(struct fifo_t *fifo, fifo_state_t *state)
     157size_t tracefifo_out_available(struct tracefifo_t *fifo) {
     158        assert(fifo);
     159        return tracefifo_compare(fifo,IN,OUT);
     160}
     161
     162size_t tracefifo_ack_available(struct tracefifo_t *fifo) {
     163        assert(fifo);
     164        return tracefifo_compare(fifo,OUT,ACK);
     165}
     166
     167void tracefifo_stat_int(struct tracefifo_t *fifo, tracefifo_state_t *state)
    168168{
    169169        assert(fifo);
     
    174174        state->ack = fifo->datamap[ACK];
    175175        state->length = fifo->length;
    176         state->used = fifo_compare(fifo,IN,ACK);
    177 
    178 }
    179 char *fifo_stat_str(struct fifo_t *fifo, char *desc, int delta)
     176        state->used = tracefifo_compare(fifo,IN,ACK);
     177
     178}
     179char *tracefifo_stat_str(struct tracefifo_t *fifo, char *desc, int delta)
    180180{
    181181        char *scan = 0;
    182182        assert(fifo);
    183183
    184         bzero(fifo_stat_buffer,513);
    185         scan = fifo_stat_buffer;
     184        bzero(tracefifo_stat_buffer,513);
     185        scan = tracefifo_stat_buffer;
    186186        if (desc)
    187187                scan += sprintf(scan,"%s\t",desc);
     
    191191        if (delta > 0)
    192192                scan += sprintf(scan,"delta: %d\t", delta);
    193         scan += sprintf(scan,"Size: %d", fifo_compare(fifo,IN,ACK));
     193        scan += sprintf(scan,"Size: %d", tracefifo_compare(fifo,IN,ACK));
    194194        scan += sprintf(scan,"\n");
    195         return fifo_stat_buffer;
    196 }
    197 void fifo_stat(struct fifo_t *fifo, char *desc, int delta)
    198 {
    199         assert(fifo);
    200 
    201         printf("%s",fifo_stat_str(fifo,desc,delta));
     195        return tracefifo_stat_buffer;
     196}
     197void tracefifo_stat(struct tracefifo_t *fifo, char *desc, int delta)
     198{
     199        assert(fifo);
     200
     201        printf("%s",tracefifo_stat_str(fifo,desc,delta));
    202202}
    203203
     
    206206 * starting at the pointer corresponding to which - if thats bogus data then its not
    207207 * the fault of this function */
    208 static int fifo_read_generic(struct fifo_t *fifo, void *buffer, size_t len, enum which_t which, char update) {
     208static int tracefifo_read_generic(struct tracefifo_t *fifo, void *buffer, size_t len, enum which_t which, char update) {
    209209        size_t oldptr;
    210210        int lenleft;
     
    232232}
    233233
    234 int fifo_write(struct fifo_t *fifo, void *buffer, size_t len) {
     234int tracefifo_write(struct tracefifo_t *fifo, void *buffer, size_t len) {
    235235        int lenleft;
    236236        int size;
     
    239239        assert(len >= 0);
    240240
    241         if (fifo_free(fifo) < len) {
     241        if (tracefifo_free(fifo) < len) {
    242242                return 0;
    243243        }
     
    257257
    258258
    259 int fifo_out_read(struct fifo_t *fifo, void *buffer, size_t len) {
     259int tracefifo_out_read(struct tracefifo_t *fifo, void *buffer, size_t len) {
    260260        assert(fifo);
    261261        assert(buffer);
    262262        assert(len >= 0);
    263         if (fifo_compare(fifo,IN,OUT) < len) {
    264                 return 0;
    265         }
    266         return fifo_read_generic(fifo,buffer,len,OUT,0);
    267 }
    268 
    269 int fifo_ack_read(struct fifo_t *fifo, void *buffer, size_t len) {
     263        if (tracefifo_compare(fifo,IN,OUT) < len) {
     264                return 0;
     265        }
     266        return tracefifo_read_generic(fifo,buffer,len,OUT,0);
     267}
     268
     269int tracefifo_ack_read(struct tracefifo_t *fifo, void *buffer, size_t len) {
    270270        assert(fifo);
    271271        assert(buffer);
    272272        assert(len >= 0);
    273         if (fifo_compare(fifo,OUT,ACK) < len) {
    274                 return 0;
    275         }
    276         return fifo_read_generic(fifo,buffer,len,ACK,0);
    277 }
    278 
    279 int fifo_out_update(struct fifo_t *fifo, size_t len){
    280         assert(fifo);
    281         assert(len >= 0);
    282         if (fifo_compare(fifo,IN,OUT) < len) {
     273        if (tracefifo_compare(fifo,OUT,ACK) < len) {
     274                return 0;
     275        }
     276        return tracefifo_read_generic(fifo,buffer,len,ACK,0);
     277}
     278
     279int tracefifo_out_update(struct tracefifo_t *fifo, size_t len){
     280        assert(fifo);
     281        assert(len >= 0);
     282        if (tracefifo_compare(fifo,IN,OUT) < len) {
    283283                return 0;
    284284        }
     
    287287}
    288288
    289 int fifo_ack_update(struct fifo_t *fifo, size_t len){
    290         assert(fifo);
    291         assert(len >= 0);
    292         if (fifo_compare(fifo,OUT,ACK) < len) {
     289int tracefifo_ack_update(struct tracefifo_t *fifo, size_t len){
     290        assert(fifo);
     291        assert(len >= 0);
     292        if (tracefifo_compare(fifo,OUT,ACK) < len) {
    293293                return 0;
    294294        }
     
    297297}
    298298
    299 void fifo_out_reset(struct fifo_t *fifo) {
     299void tracefifo_out_reset(struct tracefifo_t *fifo) {
    300300        /*
    301301         * This will reset the sent pointer back to the ack pointer. This
Note: See TracChangeset for help on using the changeset viewer.