source: lib/data-struct/ring_buffer.h @ 10553bf

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

Add pthread_spinlock so we can build on Apple's

  • Property mode set to 100644
File size: 2.7 KB
Line 
1#include <pthread.h>
2#include <semaphore.h>
3#include "../libtrace.h"
4#include "../pthread_spinlock.h"
5
6#ifndef LIBTRACE_RINGBUFFER_H
7#define LIBTRACE_RINGBUFFER_H
8
9#define LIBTRACE_RINGBUFFER_BLOCKING 0
10#define LIBTRACE_RINGBUFFER_POLLING 1
11
12// All of start, elements and end must be accessed in the listed order
13// if LIBTRACE_RINGBUFFER_POLLING is to work.
14typedef struct libtrace_ringbuffer {
15        volatile size_t start;
16        size_t size;
17        int mode;
18        void *volatile*elements;
19        pthread_mutex_t wlock;
20        pthread_mutex_t rlock;
21        pthread_spinlock_t swlock;
22        pthread_spinlock_t srlock;
23        // We need to ensure that broadcasts dont get lost hence
24        // these locks below
25        // We avoid using semaphores since they don't allow
26        // multiple releases.
27        pthread_mutex_t empty_lock;
28        pthread_mutex_t full_lock;
29        pthread_cond_t empty_cond; // Signal when empties are ready
30        pthread_cond_t full_cond; // Signal when fulls are ready
31        // Aim to get this on a separate cache line to start - important if spinning
32        volatile size_t end;
33} libtrace_ringbuffer_t;
34
35DLLEXPORT int libtrace_ringbuffer_init(libtrace_ringbuffer_t * rb, size_t size, int mode);
36DLLEXPORT void libtrace_zero_ringbuffer(libtrace_ringbuffer_t * rb);
37DLLEXPORT void libtrace_ringbuffer_destroy(libtrace_ringbuffer_t * rb);
38DLLEXPORT int libtrace_ringbuffer_is_empty(const libtrace_ringbuffer_t * rb);
39DLLEXPORT int libtrace_ringbuffer_is_full(const libtrace_ringbuffer_t * rb);
40
41DLLEXPORT void libtrace_ringbuffer_write(libtrace_ringbuffer_t * rb, void* value);
42DLLEXPORT int libtrace_ringbuffer_try_write(libtrace_ringbuffer_t * rb, void* value);
43DLLEXPORT void libtrace_ringbuffer_swrite(libtrace_ringbuffer_t * rb, void* value);
44DLLEXPORT int libtrace_ringbuffer_try_swrite(libtrace_ringbuffer_t * rb, void* value);
45DLLEXPORT int libtrace_ringbuffer_try_swrite_bl(libtrace_ringbuffer_t * rb, void* value);
46
47DLLEXPORT void* libtrace_ringbuffer_read(libtrace_ringbuffer_t *rb) ;
48DLLEXPORT int libtrace_ringbuffer_try_read(libtrace_ringbuffer_t *rb, void ** value);
49DLLEXPORT void * libtrace_ringbuffer_sread(libtrace_ringbuffer_t *rb);
50DLLEXPORT int libtrace_ringbuffer_try_sread(libtrace_ringbuffer_t *rb, void ** value);
51DLLEXPORT int libtrace_ringbuffer_try_sread_bl(libtrace_ringbuffer_t *rb, void ** value);
52
53
54
55DLLEXPORT size_t libtrace_ringbuffer_write_bulk(libtrace_ringbuffer_t *rb, void *values[], size_t nb_buffers, size_t min_nb_buffers);
56DLLEXPORT size_t libtrace_ringbuffer_read_bulk(libtrace_ringbuffer_t *rb, void *values[], size_t nb_buffers, size_t min_nb_buffers);
57DLLEXPORT size_t libtrace_ringbuffer_sread_bulk(libtrace_ringbuffer_t *rb, void *values[], size_t nb_buffers, size_t min_nb_buffers);
58DLLEXPORT size_t libtrace_ringbuffer_swrite_bulk(libtrace_ringbuffer_t *rb, void *values[], size_t nb_buffers, size_t min_nb_buffers);
59
60#endif
Note: See TracBrowser for help on using the repository browser.