source: lib/trace_ringbuffer.h @ 29ba7c2

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivelibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 29ba7c2 was 29bbef0, checked in by Richard Sanger <rsangerarj@…>, 7 years ago

My work from over summer, with a few things tidied up and updated to include recent commits/patches to bring this up to date. Still very much work in progress.

  • Property mode set to 100644
File size: 1.7 KB
Line 
1#include <pthread.h>
2#include <semaphore.h>
3
4#ifndef TRACE_RINGBUFFER_H
5#define TRACE_RINGBUFFER_H
6
7#define LIBTRACE_RINGBUFFER_BLOCKING 0
8#define LIBTRACE_RINGBUFFER_POLLING 1
9
10// All of start, elements and end must be accessed in the listed order
11// if LIBTRACE_RINGBUFFER_POLLING is to work.
12typedef struct libtrace_ringbuffer {
13        volatile int start;
14        int size;
15        int mode;
16        void *volatile*elements;
17        pthread_mutex_t wlock;
18        pthread_mutex_t rlock;
19        pthread_spinlock_t swlock;
20        pthread_spinlock_t srlock;
21        sem_t semrlock;
22        sem_t semwlock;
23        sem_t emptys;
24        sem_t fulls;
25        // Aim to get this on a separate cache line to start - important if spinning
26        volatile int end;
27       
28} libtrace_ringbuffer_t;
29
30void libtrace_ringbuffer_init(libtrace_ringbuffer_t * rb, int size, int mode);
31inline void libtrace_zero_ringbuffer(libtrace_ringbuffer_t * rb);
32void libtrace_ringbuffer_destroy(libtrace_ringbuffer_t * rb);
33int libtrace_ringbuffer_is_empty(const libtrace_ringbuffer_t * rb);
34int libtrace_ringbuffer_is_full(const libtrace_ringbuffer_t * rb);
35
36void libtrace_ringbuffer_write(libtrace_ringbuffer_t * rb, void* value);
37int libtrace_ringbuffer_try_write(libtrace_ringbuffer_t * rb, void* value);
38void libtrace_ringbuffer_swrite(libtrace_ringbuffer_t * rb, void* value);
39int libtrace_ringbuffer_try_swrite(libtrace_ringbuffer_t * rb, void* value);
40int libtrace_ringbuffer_try_swrite_bl(libtrace_ringbuffer_t * rb, void* value);
41
42void* libtrace_ringbuffer_read(libtrace_ringbuffer_t *rb) ;
43int libtrace_ringbuffer_try_read(libtrace_ringbuffer_t *rb, void ** value);
44void * libtrace_ringbuffer_sread(libtrace_ringbuffer_t *rb);
45int libtrace_ringbuffer_try_sread(libtrace_ringbuffer_t *rb, void ** value);
46int libtrace_ringbuffer_try_sread_bl(libtrace_ringbuffer_t *rb, void ** value);
47
48#endif
Note: See TracBrowser for help on using the repository browser.