Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge dev branch into main #1

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
fc8f6ce
Rename {shm/shamon} -> vms
mchalupa Apr 19, 2023
f1ac1b4
Format the previous patch
mchalupa Apr 19, 2023
6a2d754
Reformat the project
mchalupa Apr 19, 2023
ff18c6b
update .git-blame-ignore-revs
mchalupa Apr 19, 2023
ccc659c
cpp: add C++ bindings to vms_event
mchalupa Apr 19, 2023
a51875a
cpp: rewrite ringbuffer to C++
mchalupa Apr 19, 2023
e9da89c
cpp/ring_buff: fix the implementation
mchalupa Apr 21, 2023
a5e6864
Fix format the new commits
mchalupa Apr 21, 2023
2ca58d6
cpp/ring_buffer: add Reader::available() method
mchalupa May 2, 2023
33903b3
event: add a new special kind and move special kids ids
mchalupa May 31, 2023
32c26ec
event: fix naming of some functions
mchalupa May 31, 2023
c3b5d6e
cpp: add a draft of our vector
mchalupa Jun 1, 2023
9fc5694
core/event: add a method to set ID of events
mchalupa Jun 21, 2023
6df0ae2
event: allow initialize partially
mchalupa Jul 4, 2023
538d7bc
cpp/event: do not shadow the names of attributes with methods
mchalupa Jul 27, 2023
32ad604
Fix GCC build
mchalupa Aug 8, 2023
30ff4f2
Fix vms_open -> vms_shm_open
mchalupa Oct 12, 2023
4c5901f
Change SHAMON -> VAMOS
mchalupa Oct 17, 2023
55181d4
rename source_control -> vms_source_control
mchalupa Oct 17, 2023
52986ea
Rename event_record -> vms_event_record
mchalupa Oct 17, 2023
3a78b7d
Rename buffer structures to use vms_
mchalupa Oct 17, 2023
7c271d2
Rename buffer-related functions
mchalupa Oct 19, 2023
19b1317
Rename stream_fetch -> vms_stream_fetch
mchalupa Oct 19, 2023
1bebd2b
Fix some names missed in previous refactoring commits
mchalupa Oct 20, 2023
b08afa9
Fix bugs introduced during refactoring
mchalupa Oct 20, 2023
e82694f
source_control: add a fence on getting events from shared memory
mchalupa Oct 26, 2023
ea83343
Check that events were registered before reader is ready
mchalupa Oct 26, 2023
7bbdb53
shmbuf: use API instead of a hard-coded setting.
mchalupa Oct 26, 2023
c67fce2
Reformat the code with clang-format
mchalupa Oct 26, 2023
77fd61a
stream-generic: add a `const` qualifier
mchalupa Oct 31, 2023
c30af97
Rename vms_stream_fetch
mchalupa Nov 3, 2023
7049abb
signatures: fix a comment
mchalupa Apr 24, 2024
b8d53d0
stream: fix compilation
mchalupa Apr 24, 2024
d952908
A tiny reformating of streams
mchalupa Apr 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ ef787ba565f7c4e6bb1ba5f9259300254e95e266
141621deb9177fb2fcd74d7e14965da0e267beab
67843e4a329e0b49308ee13eedbad0683bdf7221
2f5e5f2fdc872e39a157bb7086c3bdde28fce239
6a2d754739d1ed1a806ba2528bd2c37c198000a3
78 changes: 40 additions & 38 deletions include/vamos-buffers/core/arbiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,73 +8,75 @@
* at the same time is not thread-safe.
************************************************/

#ifndef SHAMON_ARBITER_H_
#define SHAMON_ARBITER_H_
#ifndef VAMOS_ARBITER_H_
#define VAMOS_ARBITER_H_

#include <stdbool.h>
#include <unistd.h>

#include "stream.h"

typedef struct _shm_arbiter_buffer shm_arbiter_buffer;
typedef struct _shm_event shm_event;
typedef struct _vms_arbiter_buffer vms_arbiter_buffer;
typedef struct _vms_event vms_event;

void shm_arbiter_buffer_init(shm_arbiter_buffer *buffer, shm_stream *stream,
void vms_arbiter_buffer_init(vms_arbiter_buffer *buffer, vms_stream *stream,
size_t out_event_size, size_t capacity);
shm_arbiter_buffer *shm_arbiter_buffer_create(shm_stream *stream,
vms_arbiter_buffer *vms_arbiter_buffer_create(vms_stream *stream,
size_t out_event_size,
size_t capacity);
size_t shm_arbiter_buffer_set_drop_space_threshold(shm_arbiter_buffer *buffer,
size_t vms_arbiter_buffer_set_drop_space_threshold(vms_arbiter_buffer *buffer,
size_t thr);

void shm_arbiter_buffer_free(shm_arbiter_buffer *buffer);
void shm_arbiter_buffer_destroy(shm_arbiter_buffer *buffer);
void shm_arbiter_buffer_set_active(shm_arbiter_buffer *buffer, bool val);
size_t shm_arbiter_buffer_elem_size(shm_arbiter_buffer *q);
shm_stream *shm_arbiter_buffer_stream(shm_arbiter_buffer *buffer);
bool shm_arbiter_buffer_active(shm_arbiter_buffer *buffer);
size_t shm_arbiter_buffer_size(shm_arbiter_buffer *buffer);
size_t shm_arbiter_buffer_capacity(shm_arbiter_buffer *buffer);
size_t shm_arbiter_buffer_free_space(shm_arbiter_buffer *buffer);
size_t shm_arbiter_buffer_sizeof(void);
void vms_arbiter_buffer_free(vms_arbiter_buffer *buffer);
void vms_arbiter_buffer_destroy(vms_arbiter_buffer *buffer);
void vms_arbiter_buffer_set_active(vms_arbiter_buffer *buffer, bool val);
size_t vms_arbiter_buffer_elem_size(vms_arbiter_buffer *q);
vms_stream *vms_arbiter_buffer_stream(vms_arbiter_buffer *buffer);
bool vms_arbiter_buffer_active(vms_arbiter_buffer *buffer);
size_t vms_arbiter_buffer_size(vms_arbiter_buffer *buffer);
size_t vms_arbiter_buffer_capacity(vms_arbiter_buffer *buffer);
size_t vms_arbiter_buffer_free_space(vms_arbiter_buffer *buffer);
size_t vms_arbiter_buffer_sizeof(void);

/* writer's API */
void shm_arbiter_buffer_push(shm_arbiter_buffer *q, const void *elem,
void vms_arbiter_buffer_push(vms_arbiter_buffer *q, const void *elem,
size_t size);

/* cannot be mixed with push */

void *shm_arbiter_buffer_write_ptr(shm_arbiter_buffer *q);
void shm_arbiter_buffer_write_finish(shm_arbiter_buffer *q);
void shm_arbiter_buffer_get_str(shm_arbiter_buffer *q, size_t elem);
void *vms_arbiter_buffer_write_ptr(vms_arbiter_buffer *q);
void vms_arbiter_buffer_write_finish(vms_arbiter_buffer *q);
void vms_arbiter_buffer_get_str(vms_arbiter_buffer *q, size_t elem);

/* reader's API */
/* multiple threads can use top and peek if none of them uses drop/pop
* at the time */
shm_event *shm_arbiter_buffer_top(shm_arbiter_buffer *buffer);
size_t shm_arbiter_buffer_peek(shm_arbiter_buffer *buffer, size_t n,
vms_event *vms_arbiter_buffer_top(vms_arbiter_buffer *buffer);
size_t vms_arbiter_buffer_peek(vms_arbiter_buffer *buffer, size_t n,
void **data1, size_t *size1, void **data2,
size_t *size2);
/* peek 1 event */
size_t shm_arbiter_buffer_peek1(shm_arbiter_buffer *buffer, void **data);
size_t shm_arbiter_buffer_drop(shm_arbiter_buffer *buffer, size_t n);
size_t shm_arbiter_buffer_drop_older_than(shm_arbiter_buffer *buffer,
shm_eventid id);
bool shm_arbiter_buffer_pop(shm_arbiter_buffer *q, void *buff);
size_t vms_arbiter_buffer_peek1(vms_arbiter_buffer *buffer, void **data);
size_t vms_arbiter_buffer_drop(vms_arbiter_buffer *buffer, size_t n);
size_t vms_arbiter_buffer_drop_older_than(vms_arbiter_buffer *buffer,
vms_eventid id);
bool vms_arbiter_buffer_pop(vms_arbiter_buffer *q, void *buff);

void *stream_fetch(shm_stream *stream, shm_arbiter_buffer *buffer);
void *vms_stream_fetch(vms_stream *stream);
void *vms_stream_fetch_dropping(vms_stream *stream, vms_arbiter_buffer *buffer);

void *stream_filter_fetch(shm_stream *stream, shm_arbiter_buffer *buffer,
shm_stream_filter_fn filter);
void *vms_stream_fetch_dropping_filter(vms_stream *stream,
vms_arbiter_buffer *buffer,
vms_stream_filter_fn filter);

bool shm_arbiter_buffer_is_done(shm_arbiter_buffer *buffer);
bool vms_arbiter_buffer_is_done(vms_arbiter_buffer *buffer);

size_t shm_arbiter_buffer_dropped_num(shm_arbiter_buffer *buffer);
size_t shm_arbiter_buffer_dropped_times(shm_arbiter_buffer *buffer);
size_t shm_arbiter_buffer_written_num(shm_arbiter_buffer *buffer);
size_t vms_arbiter_buffer_dropped_num(vms_arbiter_buffer *buffer);
size_t vms_arbiter_buffer_dropped_times(vms_arbiter_buffer *buffer);
size_t vms_arbiter_buffer_written_num(vms_arbiter_buffer *buffer);

void shm_arbiter_buffer_notify_dropped(shm_arbiter_buffer *buffer,
void vms_arbiter_buffer_notify_dropped(vms_arbiter_buffer *buffer,
uint64_t begin_id, uint64_t end_id);

void shm_arbiter_buffer_dump_stats(shm_arbiter_buffer *buffer);
#endif /* SHAMON_ARBITER_H_ */
void vms_arbiter_buffer_dump_stats(vms_arbiter_buffer *buffer);
#endif /* VAMOS_ARBITER_H_ */
63 changes: 45 additions & 18 deletions include/vamos-buffers/core/event.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
#ifndef SHAMON_EVENT_H_
#define SHAMON_EVENT_H_
#ifndef VMS_EVENT_H_
#define VMS_EVENT_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>

typedef uint64_t shm_kind;
typedef uint64_t shm_eventid;
typedef struct _shm_stream shm_stream;
typedef uint64_t vms_kind;
typedef uint64_t vms_eventid;
typedef struct _vms_stream vms_stream;

// TODO: make this opaque? but how to do the inheritance, then? Via
// pointers to an interface?
typedef struct _shm_event {
shm_kind kind;
shm_eventid id;
} shm_event;
typedef struct _vms_event {
vms_kind kind;
vms_eventid id;

#ifdef __cplusplus
_vms_event() {}
_vms_event(vms_kind kind) : kind(kind) {}
_vms_event(vms_kind kind, vms_eventid id) : kind(kind), id(id) {}

vms_kind get_kind() const { return kind; }
vms_eventid get_id() const { return id; }
#endif
} vms_event;

typedef struct _shm_event_default_hole {
shm_event base;
typedef struct _vms_event_default_hole {
vms_event base;
size_t n; /* number of dropped events */
} shm_event_default_hole;
} vms_event_default_hole;

/* Must be called before using event API.
* It is called from shamon_create */
Expand All @@ -28,12 +41,26 @@ void initialize_events(void) __attribute__((deprecated));
void deinitialize_events(void) __attribute__((deprecated));

// EVENTS
shm_eventid shm_event_id(shm_event *event);
shm_kind shm_event_kind(shm_event *event);
#define VMS_EVENT_HOLE_KIND 1
#define VMS_EVENT_DONE_KIND 2
#define VMS_EVENT_LAST_SPECIAL_KIND 9

vms_eventid vms_event_id(const vms_event *event);
vms_kind vms_event_kind(const vms_event *event);

// Sometimes we want to generate the event step-by-step
// and then we may need this fun.
void vms_event_set_id(vms_event *event, vms_eventid id);

// DROP EVENT
bool shm_event_is_hole(shm_event *);
shm_kind shm_get_hole_kind(void);
shm_kind shm_get_last_special_kind(void);
bool vms_event_is_hole(const vms_event *);
bool vms_event_is_done(const vms_event *);
vms_kind vms_event_get_hole_kind(void);
vms_kind vms_event_get_done_kind(void);
vms_kind vms_event_get_last_special_kind(void);

#ifdef __cplusplus
}
#endif

#endif // SHAMON_EVENT_H_
#endif // VMS_EVENT_H
64 changes: 32 additions & 32 deletions include/vamos-buffers/core/list-embedded.h
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
#ifndef SHAMON_LIST_EMBEDDED_H_
#define SHAMON_LIST_EMBEDDED_H_
#ifndef VAMOS_LIST_EMBEDDED_H_
#define VAMOS_LIST_EMBEDDED_H_

#include <unistd.h>

/* circular embedded doubly-linked list */
typedef struct _shm_list_embedded {
struct _shm_list_embedded *next;
struct _shm_list_embedded *prev;
} shm_list_embedded;

void shm_list_embedded_init(shm_list_embedded *list);
void shm_list_embedded_insert_after(shm_list_embedded *list,
shm_list_embedded *elm);
void shm_list_embedded_insert_list(shm_list_embedded *list,
shm_list_embedded *other);
void shm_list_embedded_remove(shm_list_embedded *elm);
size_t shm_list_embedded_size(const shm_list_embedded *list);
_Bool shm_list_embedded_empty(const shm_list_embedded *list);

#define shm_list_embedded_object_of(ptr, tyobj, member) \
typedef struct _vms_list_embedded {
struct _vms_list_embedded *next;
struct _vms_list_embedded *prev;
} vms_list_embedded;

void vms_list_embedded_init(vms_list_embedded *list);
void vms_list_embedded_insert_after(vms_list_embedded *list,
vms_list_embedded *elm);
void vms_list_embedded_insert_list(vms_list_embedded *list,
vms_list_embedded *other);
void vms_list_embedded_remove(vms_list_embedded *elm);
size_t vms_list_embedded_size(const vms_list_embedded *list);
_Bool vms_list_embedded_empty(const vms_list_embedded *list);

#define vms_list_embedded_object_of(ptr, tyobj, member) \
(__typeof__(tyobj))((char *)(ptr)-offsetof(__typeof__(*tyobj), member))

#define shm_list_embedded_foreach(pos, head, member) \
for (pos = shm_list_embedded_object_of((head)->next, pos, member); \
#define vms_list_embedded_foreach(pos, head, member) \
for (pos = vms_list_embedded_object_of((head)->next, pos, member); \
&pos->member != (head); \
pos = shm_list_embedded_object_of(pos->member.next, pos, member))
pos = vms_list_embedded_object_of(pos->member.next, pos, member))

#define shm_list_embedded_foreach_safe(pos, tmp, head, member) \
for (pos = shm_list_embedded_object_of((head)->next, pos, member), \
tmp = shm_list_embedded_object_of((pos)->member.next, tmp, member); \
#define vms_list_embedded_foreach_safe(pos, tmp, head, member) \
for (pos = vms_list_embedded_object_of((head)->next, pos, member), \
tmp = vms_list_embedded_object_of((pos)->member.next, tmp, member); \
&pos->member != (head); pos = tmp, \
tmp = shm_list_embedded_object_of(pos->member.next, tmp, member))
tmp = vms_list_embedded_object_of(pos->member.next, tmp, member))

#define shm_list_embedded_foreach_reverse(pos, head, member) \
for (pos = shm_list_embedded_object_of((head)->prev, pos, member); \
#define vms_list_embedded_foreach_reverse(pos, head, member) \
for (pos = vms_list_embedded_object_of((head)->prev, pos, member); \
&pos->member != (head); \
pos = shm_list_embedded_object_of(pos->member.prev, pos, member))
pos = vms_list_embedded_object_of(pos->member.prev, pos, member))

#define shm_list_embedded_foreach_reverse_safe(pos, tmp, head, member) \
for (pos = shm_list_embedded_object_of((head)->prev, pos, member), \
tmp = shm_list_embedded_object_of((pos)->member.prev, tmp, member); \
#define vms_list_embedded_foreach_reverse_safe(pos, tmp, head, member) \
for (pos = vms_list_embedded_object_of((head)->prev, pos, member), \
tmp = vms_list_embedded_object_of((pos)->member.prev, tmp, member); \
&pos->member != (head); pos = tmp, \
tmp = shm_list_embedded_object_of(pos->member.prev, tmp, member))
tmp = vms_list_embedded_object_of(pos->member.prev, tmp, member))

#endif /* SHAMON_LIST_EMBEDDED_H_ */
#endif /* VAMOS_LIST_EMBEDDED_H_ */
48 changes: 24 additions & 24 deletions include/vamos-buffers/core/list.h
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
#ifndef SHAMON_LIST_H_
#define SHAMON_LIST_H_
#ifndef VAMOS_LIST_H_
#define VAMOS_LIST_H_

#include <unistd.h>

/* non-circular doubly-linked-list */
typedef struct _shm_list_elem {
struct _shm_list_elem *next, *prev;
typedef struct _vms_list_elem {
struct _vms_list_elem *next, *prev;
void *data;
} shm_list_elem;
} vms_list_elem;

typedef struct _shm_list {
shm_list_elem *first;
shm_list_elem *last;
typedef struct _vms_list {
vms_list_elem *first;
vms_list_elem *last;
size_t size;
} shm_list;
} vms_list;

typedef void(shm_list_elem_destroy_fn)(void *);
typedef void(vms_list_elem_destroy_fn)(void *);

void shm_list_init(shm_list *list);
void shm_list_destroy(shm_list *list, shm_list_elem_destroy_fn destroy);
void vms_list_init(vms_list *list);
void vms_list_destroy(vms_list *list, vms_list_elem_destroy_fn destroy);

size_t shm_list_prepend(shm_list *list, void *elem);
size_t shm_list_append(shm_list *list, void *elem);
size_t shm_list_append_elem(shm_list *list, shm_list_elem *elem);
size_t shm_list_insert_after(shm_list *list, shm_list_elem *elem, void *data);
size_t shm_list_insert_before(shm_list *list, shm_list_elem *elem, void *data);
size_t shm_list_insert_elem_after(shm_list *list, shm_list_elem *elem,
shm_list_elem *new);
size_t shm_list_remove(shm_list *list, shm_list_elem *elem);
size_t shm_list_size(shm_list *list);
size_t vms_list_prepend(vms_list *list, void *elem);
size_t vms_list_append(vms_list *list, void *elem);
size_t vms_list_append_elem(vms_list *list, vms_list_elem *elem);
size_t vms_list_insert_after(vms_list *list, vms_list_elem *elem, void *data);
size_t vms_list_insert_before(vms_list *list, vms_list_elem *elem, void *data);
size_t vms_list_insert_elem_after(vms_list *list, vms_list_elem *elem,
vms_list_elem *new);
size_t vms_list_remove(vms_list *list, vms_list_elem *elem);
size_t vms_list_size(vms_list *list);

shm_list_elem *shm_list_first(shm_list *list);
shm_list_elem *shm_list_last(shm_list *list);
vms_list_elem *vms_list_first(vms_list *list);
vms_list_elem *vms_list_last(vms_list *list);

#endif /* SHAMON_LIST_H_ */
#endif /* VAMOS_LIST_H_ */
Loading