source: lib/data-struct/ring_buffer.h @ b73407f

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

Add an object cache with thread local caches
All packets used by a trace are put through this.
Adds bulk read/write operations to the ringbuffer (used by the object cache)
Replace semaphores with condition variables to support these bulk operations.
Internally use bulk read operations from a single threaded formats to reduce lock overhead.
Replaces the asserts around pthread_* functions with a version that will still run the command if NDEBUG

  • Property mode set to 100644
File size: 2.7 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        // We need to ensure that broadcasts dont get lost hence
23        // these locks below
24        // We avoid using semaphores since they don't allow
25        // multiple releases.
26        pthread_mutex_t empty_lock;
27        pthread_mutex_t full_lock;
28        pthread_cond_t empty_cond; // Signal when empties are ready
29        pthread_cond_t full_cond; // Signal when fulls are ready
30        // Aim to get this on a separate cache line to start - important if spinning
31        volatile size_t end;
32} libtrace_ringbuffer_t;
33
34DLLEXPORT void libtrace_ringbuffer_init(libtrace_ringbuffer_t * rb, size_t size, int mode);
35DLLEXPORT void libtrace_zero_ringbuffer(libtrace_ringbuffer_t * rb);
36DLLEXPORT void libtrace_ringbuffer_destroy(libtrace_ringbuffer_t * rb);
37DLLEXPORT int libtrace_ringbuffer_is_empty(const libtrace_ringbuffer_t * rb);
38DLLEXPORT int libtrace_ringbuffer_is_full(const libtrace_ringbuffer_t * rb);
39
40DLLEXPORT void libtrace_ringbuffer_write(libtrace_ringbuffer_t * rb, void* value);
41DLLEXPORT int libtrace_ringbuffer_try_write(libtrace_ringbuffer_t * rb, void* value);
42DLLEXPORT void libtrace_ringbuffer_swrite(libtrace_ringbuffer_t * rb, void* value);
43DLLEXPORT int libtrace_ringbuffer_try_swrite(libtrace_ringbuffer_t * rb, void* value);
44DLLEXPORT int libtrace_ringbuffer_try_swrite_bl(libtrace_ringbuffer_t * rb, void* value);
45
46DLLEXPORT void* libtrace_ringbuffer_read(libtrace_ringbuffer_t *rb) ;
47DLLEXPORT int libtrace_ringbuffer_try_read(libtrace_ringbuffer_t *rb, void ** value);
48DLLEXPORT void * libtrace_ringbuffer_sread(libtrace_ringbuffer_t *rb);
49DLLEXPORT int libtrace_ringbuffer_try_sread(libtrace_ringbuffer_t *rb, void ** value);
50DLLEXPORT int libtrace_ringbuffer_try_sread_bl(libtrace_ringbuffer_t *rb, void ** value);
51
52
53
54DLLEXPORT size_t libtrace_ringbuffer_write_bulk(libtrace_ringbuffer_t *rb, void *values[], size_t nb_buffers, size_t min_nb_buffers);
55DLLEXPORT size_t libtrace_ringbuffer_read_bulk(libtrace_ringbuffer_t *rb, void *values[], size_t nb_buffers, size_t min_nb_buffers);
56DLLEXPORT size_t libtrace_ringbuffer_sread_bulk(libtrace_ringbuffer_t *rb, void *values[], size_t nb_buffers, size_t min_nb_buffers);
57DLLEXPORT size_t libtrace_ringbuffer_swrite_bulk(libtrace_ringbuffer_t *rb, void *values[], size_t nb_buffers, size_t min_nb_buffers);
58
59#endif
Note: See TracBrowser for help on using the repository browser.