source: lib/data-struct/ring_buffer.h @ 8af0d01

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

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.

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