SPSC
A shared memory single-producer single-consumer (SPSC) queue
spsc.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stdint.h>
4 #include <stdio.h>
5 
6 #define MSG_SIZE_T uint32_t
7 
8 #define READ_MODE 1
9 #define WRITE_MODE 2
10 
14 typedef struct spsc_ring_data
15 {
16  char _header[2];
17  int _version;
18  size_t _size;
19  char __pad0[64];
20 
21  size_t _rpos;
22  char __pad1[64];
23 
24  size_t _wpos;
25  char __pad2[64];
26 
27  char _buf[];
29 
33 typedef struct spsc_ring
34 {
42  int mode;
46  int flock_fd;
47 } spsc_ring;
48 
56 int spsc_create_sub(spsc_ring* ring, const char* pathname, const size_t size);
57 
65 int spsc_create_pub(spsc_ring* ring, const char* pathname, const size_t size);
66 
74 size_t spsc_read(spsc_ring* ring, void* dest, const size_t n);
75 
83 MSG_SIZE_T spsc_write(spsc_ring* ring, const void* src, const MSG_SIZE_T n);
84 
90 size_t spsc_size(const spsc_ring* ring);
91 
96 size_t spsc_capacity(const spsc_ring* ring);
97 
#define MSG_SIZE_T
Definition: spsc.h:6
size_t spsc_size(const spsc_ring *ring)
void spsc_destroy(spsc_ring *ring)
int spsc_create_sub(spsc_ring *ring, const char *pathname, const size_t size)
MSG_SIZE_T spsc_write(spsc_ring *ring, const void *src, const MSG_SIZE_T n)
int spsc_create_pub(spsc_ring *ring, const char *pathname, const size_t size)
size_t spsc_capacity(const spsc_ring *ring)
size_t spsc_read(spsc_ring *ring, void *dest, const size_t n)
Definition: spsc.h:15
size_t _rpos
Definition: spsc.h:21
size_t _size
Definition: spsc.h:18
char __pad2[64]
Definition: spsc.h:25
size_t _wpos
Definition: spsc.h:24
char __pad0[64]
Definition: spsc.h:19
int _version
Definition: spsc.h:17
char _buf[]
Definition: spsc.h:27
char __pad1[64]
Definition: spsc.h:22
char _header[2]
Definition: spsc.h:16
Definition: spsc.h:34
int mode
Definition: spsc.h:42
int flock_fd
Definition: spsc.h:46
spsc_ring_data * _data
Definition: spsc.h:38