#include #include #include #include #include "lf_ring_buffer.h" #define BUFFER_LEN 5000000 //static rb_data_t data[BUFFER_LEN][RB_DATA_LEN]; static int64_t time_diff(struct timespec *t0, struct timespec *t1) { return ((t1->tv_sec * 1000000000) + t1->tv_nsec) - ((t0->tv_sec * 1000000000) + t0->tv_nsec); } /* static void print_now(char* s) { fprintf(stdout,s); fflush(stdout); } */ static void report( char* op, int n, uint64_t dt, int redo ) { fprintf(stdout,"\t%9d %s operations in %4d [ms] => %7d [us] => %10d [ns]\t >>> %6d [ns/op]\t%4d redone operations\n", n, op, (int)(dt/1000000), (int)(dt/1000), (int)dt, (int)(dt/n), redo ); } struct thread_params { lf_ring_buffer_t *ring; int n; int flags; }; /* static void feed_data( int n){ int i; for(i=0; in, sequential_writes( params->ring, params->n, params->flags ) ); sequential_writes( params->ring, params->n, params->flags ); return NULL; } static void parallel_writes( int nt, lf_ring_buffer_t *ring, int n, int flags ) { int i; pthread_t *threads = malloc( sizeof(pthread_t)*nt); struct thread_params *params = malloc( sizeof(struct thread_params)*nt); for(i=0; i= (int) ARRAY_SIZE * (int) sizeof (int)) { if (jack_ringbuffer_read (rb, (char *) b, ARRAY_SIZE * sizeof (int))) { if (!cmp_array (a, b, ARRAY_SIZE)) { nfailures++; // //printf("failure in chunk %lu - probability: %lu/%lu = %.3f per million\n", // j, nfailures, j, (float) nfailures / (j + 1) * 1000000); //i = (b[0] + ARRAY_SIZE) % MAX_VALUE; // printf("FAILURE in chunk %lu\n", j); fflush(stdout); exit(1); } i = fill_int_array (a, i, ARRAY_SIZE); j++; } } } return NULL; } static void * writer_start (void * arg) { int i = 0, a[ARRAY_SIZE]; printf("[writer started] "); fflush(stdout); i = fill_int_array (a, i, ARRAY_SIZE); while (1) { if (jack_ringbuffer_write_space (rb) >= (int) ARRAY_SIZE * (int) sizeof (int)) { if (jack_ringbuffer_write (rb, (char *) a, ARRAY_SIZE * sizeof (int))) { i = fill_int_array (a, i, ARRAY_SIZE); } } } return NULL; } int main(int argc, char *argv[]) { int size; sscanf(argv[1], "%d", &size); printf("starting (120s max) - array/buffer size: %d/%d\n", (int) sizeof(int) * ARRAY_SIZE, size); fflush(stdout); rb = jack_ringbuffer_create(size); pthread_t reader_thread, writer_thread; if (pthread_create (&reader_thread, NULL, reader_start, NULL)) { printf("Failed to create reader thread\n"); exit(1); } if (pthread_create (&writer_thread, NULL, writer_start, NULL)) { printf("Failed to create writer thread\n"); exit(1); } sleep(120); if (flowing) printf("SUCCESS\n"); else printf("FAILURE: data did not flow\n"); fflush(stdout); return 0; } */