Skip to content

Commit 536db18

Browse files
renaming
1 parent 85e51be commit 536db18

File tree

3 files changed

+63
-63
lines changed

3 files changed

+63
-63
lines changed

libudpard/udpard.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -124,24 +124,24 @@ udpard_udpip_ep_t udpard_make_subject_endpoint(const uint32_t subject_id)
124124
}
125125

126126
// NOLINTNEXTLINE(misc-no-recursion)
127-
void udpard_fragment_free_all(udpard_fragment_t* const frag, const udpard_mem_resource_t fragment_memory_resource)
127+
void udpard_fragment_free_all(udpard_fragment_t* const frag, const udpard_mem_resource_t fragment_mem_resource)
128128
{
129129
if (frag != NULL) {
130130
// Descend the tree
131131
for (uint_fast8_t i = 0; i < 2; i++) {
132132
if (frag->index_offset.lr[i] != NULL) {
133133
frag->index_offset.lr[i]->up = NULL; // Prevent backtrack ascension from this branch
134-
udpard_fragment_free_all((udpard_fragment_t*)frag->index_offset.lr[i], fragment_memory_resource);
134+
udpard_fragment_free_all((udpard_fragment_t*)frag->index_offset.lr[i], fragment_mem_resource);
135135
frag->index_offset.lr[i] = NULL; // Avoid dangly pointers even if we're headed for imminent destruction
136136
}
137137
}
138138
// Delete this fragment
139139
udpard_fragment_t* const parent = (udpard_fragment_t*)frag->index_offset.up;
140140
mem_free_payload(frag->payload_deleter, frag->origin);
141-
mem_free(fragment_memory_resource, sizeof(udpard_fragment_t), frag);
141+
mem_free(fragment_mem_resource, sizeof(udpard_fragment_t), frag);
142142
if (parent != NULL) {
143143
parent->index_offset.lr[parent->index_offset.lr[1] == (udpard_tree_t*)frag] = NULL;
144-
udpard_fragment_free_all(parent, fragment_memory_resource); // tail call hopefully
144+
udpard_fragment_free_all(parent, fragment_mem_resource); // tail call hopefully
145145
}
146146
}
147147
}
@@ -1559,21 +1559,21 @@ static void rx_session_update(rx_session_t* const self,
15591559

15601560
// --------------------------------------------- RX PUBLIC API ---------------------------------------------
15611561

1562-
static bool rx_validate_memory_resources(const udpard_rx_memory_resources_t memory)
1562+
static bool rx_validate_mem_resources(const udpard_rx_mem_resources_t memory)
15631563
{
15641564
return (memory.session.alloc != NULL) && (memory.session.free != NULL) && //
15651565
(memory.fragment.alloc != NULL) && (memory.fragment.free != NULL);
15661566
}
15671567

1568-
bool udpard_rx_new(udpard_rx_t* const self,
1569-
const uint64_t local_uid,
1570-
const udpard_rx_memory_resources_t p2p_port_memory,
1571-
const udpard_rx_on_message_t on_message,
1572-
const udpard_rx_on_collision_t on_collision,
1573-
const udpard_rx_on_ack_mandate_t on_ack_mandate)
1568+
bool udpard_rx_new(udpard_rx_t* const self,
1569+
const uint64_t local_uid,
1570+
const udpard_rx_mem_resources_t p2p_port_memory,
1571+
const udpard_rx_on_message_t on_message,
1572+
const udpard_rx_on_collision_t on_collision,
1573+
const udpard_rx_on_ack_mandate_t on_ack_mandate)
15741574
{
1575-
bool ok = (self != NULL) && (local_uid > 0) && rx_validate_memory_resources(p2p_port_memory) &&
1576-
(on_message != NULL) && (on_collision != NULL) && (on_ack_mandate != NULL);
1575+
bool ok = (self != NULL) && (local_uid > 0) && rx_validate_mem_resources(p2p_port_memory) && (on_message != NULL) &&
1576+
(on_collision != NULL) && (on_ack_mandate != NULL);
15771577
if (ok) {
15781578
mem_zero(sizeof(*self), self);
15791579
self->list_session_by_animation = (udpard_list_t){ NULL, NULL };
@@ -1585,8 +1585,8 @@ bool udpard_rx_new(udpard_rx_t* const self,
15851585
self->errors_frame_malformed = 0;
15861586
self->errors_transfer_malformed = 0;
15871587
self->user = NULL;
1588-
ok =
1589-
udpard_rx_port_new(&self->p2p_port, local_uid, SIZE_MAX, UDPARD_REORDERING_WINDOW_UNORDERED, p2p_port_memory);
1588+
ok = udpard_rx_port_new(
1589+
&self->p2p_port, local_uid, SIZE_MAX, UDPARD_RX_REORDERING_WINDOW_UNORDERED, p2p_port_memory);
15901590
}
15911591
return ok;
15921592
}
@@ -1626,16 +1626,16 @@ void udpard_rx_poll(udpard_rx_t* const self, const udpard_us_t now)
16261626
self->p2p_port.invoked = false;
16271627
}
16281628

1629-
bool udpard_rx_port_new(udpard_rx_port_t* const self,
1630-
const uint64_t topic_hash,
1631-
const size_t extent,
1632-
const udpard_us_t reordering_window,
1633-
const udpard_rx_memory_resources_t memory)
1629+
bool udpard_rx_port_new(udpard_rx_port_t* const self,
1630+
const uint64_t topic_hash,
1631+
const size_t extent,
1632+
const udpard_us_t reordering_window,
1633+
const udpard_rx_mem_resources_t memory)
16341634
{
16351635
const bool win_ok = (reordering_window >= 0) || //
1636-
(reordering_window == UDPARD_REORDERING_WINDOW_UNORDERED) ||
1637-
(reordering_window == UDPARD_REORDERING_WINDOW_STATELESS);
1638-
const bool ok = (self != NULL) && rx_validate_memory_resources(memory) && win_ok;
1636+
(reordering_window == UDPARD_RX_REORDERING_WINDOW_UNORDERED) ||
1637+
(reordering_window == UDPARD_RX_REORDERING_WINDOW_STATELESS);
1638+
const bool ok = (self != NULL) && rx_validate_mem_resources(memory) && win_ok;
16391639
if (ok) {
16401640
mem_zero(sizeof(*self), self);
16411641
self->topic_hash = topic_hash;
@@ -1755,7 +1755,7 @@ bool udpard_rx_port_push(udpard_rx_t* const rx,
17551755
// Process the frame.
17561756
if (frame_valid) {
17571757
if (frame.meta.topic_hash == port->topic_hash) {
1758-
const bool stateful = (port->reordering_window != UDPARD_REORDERING_WINDOW_STATELESS);
1758+
const bool stateful = (port->reordering_window != UDPARD_RX_REORDERING_WINDOW_STATELESS);
17591759
(stateful ? rx_port_accept_stateful : rx_port_accept_stateless)(
17601760
rx, port, timestamp, source_ep, frame, payload_deleter, redundant_iface_index);
17611761
} else { // Collisions are discovered early so that we don't attempt to allocate sessions for them.

libudpard/udpard.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ typedef struct udpard_fragment_t
275275
/// or if the memory resource implementation does not require deallocation size.
276276
///
277277
/// If any of the arguments are NULL, the function has no effect. The complexity is linear in the number of fragments.
278-
void udpard_fragment_free_all(udpard_fragment_t* const frag, const udpard_mem_resource_t fragment_memory_resource);
278+
void udpard_fragment_free_all(udpard_fragment_t* const frag, const udpard_mem_resource_t fragment_mem_resource);
279279

280280
/// Given any fragment in a transfer, returns the fragment that contains the given payload offset.
281281
/// Returns NULL if the offset points beyond the stored payload, or if any_frag is NULL.
@@ -506,7 +506,7 @@ void udpard_tx_free(const udpard_tx_mem_resources_t memory, udpard_tx_item_t* co
506506
/// These are used to serve the memory needs of the library to keep state while reassembling incoming transfers.
507507
/// Several memory resources are provided to enable fine control over the allocated memory if necessary; however,
508508
/// simple applications may choose to use the same memory resource implemented via malloc()/free() for all of them.
509-
typedef struct udpard_rx_memory_resources_t
509+
typedef struct udpard_rx_mem_resources_t
510510
{
511511
/// Provides memory for the session instances described below.
512512
/// Each instance is fixed-size, so a trivial zero-fragmentation block allocator is sufficient.
@@ -515,7 +515,7 @@ typedef struct udpard_rx_memory_resources_t
515515
/// The fragment handles are allocated per payload fragment; each handle contains a pointer to its fragment.
516516
/// Each instance is of a very small fixed size, so a trivial zero-fragmentation block allocator is sufficient.
517517
udpard_mem_resource_t fragment;
518-
} udpard_rx_memory_resources_t;
518+
} udpard_rx_mem_resources_t;
519519

520520
/// The transfer reassembly state machine can operate in several modes described below. First, a brief summary:
521521
///
@@ -568,8 +568,8 @@ typedef struct udpard_rx_memory_resources_t
568568
/// publishers where unordered and duplicated messages are acceptable, such as the heartbeat topic.
569569
///
570570
/// The UNORDERED mode is used if the reordering window duration is set to UDPARD_REORDERING_WINDOW_STATELESS.
571-
#define UDPARD_REORDERING_WINDOW_UNORDERED ((udpard_us_t)(-1))
572-
#define UDPARD_REORDERING_WINDOW_STATELESS ((udpard_us_t)(-2))
571+
#define UDPARD_RX_REORDERING_WINDOW_UNORDERED ((udpard_us_t)(-1))
572+
#define UDPARD_RX_REORDERING_WINDOW_STATELESS ((udpard_us_t)(-2))
573573

574574
/// This type represents an open input port, such as a subscription to a topic.
575575
typedef struct udpard_rx_port_t
@@ -581,11 +581,11 @@ typedef struct udpard_rx_port_t
581581
/// The total size of the received payload may still exceed this extent setting by some small margin.
582582
size_t extent;
583583

584-
/// See UDPARD_REORDERING_WINDOW_... above.
584+
/// See UDPARD_RX_REORDERING_WINDOW_... above.
585585
/// Behavior undefined if the reassembly mode is switched on a live port with ongoing transfers.
586586
udpard_us_t reordering_window;
587587

588-
udpard_rx_memory_resources_t memory;
588+
udpard_rx_mem_resources_t memory;
589589

590590
/// Libudpard creates a new session instance per remote UID that emits transfers matching this port.
591591
/// For example, if the local node is subscribed to a certain subject and there are X nodes publishing
@@ -719,12 +719,12 @@ typedef struct udpard_rx_t
719719
/// The application does not need to initialize the P2P port itself; it is initialized automatically.
720720
/// The application must push the datagrams arriving to its P2P sockets into this port using udpard_rx_port_push().
721721
/// True on success, false if any of the arguments are invalid.
722-
bool udpard_rx_new(udpard_rx_t* const self,
723-
const uint64_t local_uid,
724-
const udpard_rx_memory_resources_t p2p_port_memory,
725-
const udpard_rx_on_message_t on_message,
726-
const udpard_rx_on_collision_t on_collision,
727-
const udpard_rx_on_ack_mandate_t on_ack_mandate);
722+
bool udpard_rx_new(udpard_rx_t* const self,
723+
const uint64_t local_uid,
724+
const udpard_rx_mem_resources_t p2p_port_memory,
725+
const udpard_rx_on_message_t on_message,
726+
const udpard_rx_on_collision_t on_collision,
727+
const udpard_rx_on_ack_mandate_t on_ack_mandate);
728728

729729
/// Returns all memory allocated for the entire RX stack, including all ports, sessions, slots, fragments, etc.
730730
/// It is safe to invoke this at any time, but the instance and its ports shall not be used again unless
@@ -760,11 +760,11 @@ void udpard_rx_poll(udpard_rx_t* const self, const udpard_us_t now);
760760
///
761761
/// The return value is true on success, false if any of the arguments are invalid.
762762
/// The time complexity is constant. This function does not invoke the dynamic memory manager.
763-
bool udpard_rx_port_new(udpard_rx_port_t* const self,
764-
const uint64_t topic_hash,
765-
const size_t extent,
766-
const udpard_us_t reordering_window,
767-
const udpard_rx_memory_resources_t memory);
763+
bool udpard_rx_port_new(udpard_rx_port_t* const self,
764+
const uint64_t topic_hash,
765+
const size_t extent,
766+
const udpard_us_t reordering_window,
767+
const udpard_rx_mem_resources_t memory);
768768

769769
/// Returns all memory allocated for the sessions, slots, fragments, etc of the given port.
770770
/// Does not free the port itself and does not alter the RX instance aside from unlinking the port from it.
@@ -777,7 +777,7 @@ void udpard_rx_port_free(udpard_rx_t* const rx, udpard_rx_port_t* const port);
777777
///
778778
/// The function takes ownership of the passed datagram payload buffer. The library will either store it as a
779779
/// fragment of the reassembled transfer payload or free it using the corresponding memory resource
780-
/// (see udpard_rx_memory_resources_t) if the datagram is not needed for reassembly. Because of the ownership transfer,
780+
/// (see udpard_rx_mem_resources_t) if the datagram is not needed for reassembly. Because of the ownership transfer,
781781
/// the datagram payload buffer has to be mutable (non-const). The ownership transfer does not take place if
782782
/// any of the arguments are invalid; the function returns false in that case and the caller must clean up.
783783
///

tests/src/test_intrusive_rx.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,7 +2058,7 @@ static void test_rx_session_ordered(void)
20582058
const udpard_mem_resource_t mem_payload = instrumented_allocator_make_resource(&alloc_payload);
20592059
const udpard_mem_deleter_t del_payload = instrumented_allocator_make_deleter(&alloc_payload);
20602060

2061-
const udpard_rx_memory_resources_t rx_mem = { .fragment = mem_frag, .session = mem_session };
2061+
const udpard_rx_mem_resources_t rx_mem = { .fragment = mem_frag, .session = mem_session };
20622062

20632063
// Initialize the shared RX instance.
20642064
const uint64_t local_uid = 0xC3C8E4974254E1F5ULL;
@@ -2677,7 +2677,7 @@ static void test_rx_session_unordered(void)
26772677
const udpard_mem_resource_t mem_payload = instrumented_allocator_make_resource(&alloc_payload);
26782678
const udpard_mem_deleter_t del_payload = instrumented_allocator_make_deleter(&alloc_payload);
26792679

2680-
const udpard_rx_memory_resources_t rx_mem = { .fragment = mem_frag, .session = mem_session };
2680+
const udpard_rx_mem_resources_t rx_mem = { .fragment = mem_frag, .session = mem_session };
26812681

26822682
// Initialize the shared RX instance.
26832683
const uint64_t local_uid = 0xC3C8E4974254E1F5ULL;
@@ -2686,7 +2686,7 @@ static void test_rx_session_unordered(void)
26862686
callback_result_t cb_result = { 0 };
26872687
rx.user = &cb_result;
26882688
TEST_ASSERT_EQUAL(local_uid, rx.p2p_port.topic_hash);
2689-
TEST_ASSERT_EQUAL(UDPARD_REORDERING_WINDOW_UNORDERED, rx.p2p_port.reordering_window);
2689+
TEST_ASSERT_EQUAL(UDPARD_RX_REORDERING_WINDOW_UNORDERED, rx.p2p_port.reordering_window);
26902690

26912691
// Construct the session instance using the p2p port.
26922692
udpard_us_t now = 0;
@@ -2929,7 +2929,7 @@ static void test_rx_port(void)
29292929
const udpard_mem_resource_t mem_payload = instrumented_allocator_make_resource(&alloc_payload);
29302930
const udpard_mem_deleter_t del_payload = instrumented_allocator_make_deleter(&alloc_payload);
29312931

2932-
const udpard_rx_memory_resources_t rx_mem = { .fragment = mem_frag, .session = mem_session };
2932+
const udpard_rx_mem_resources_t rx_mem = { .fragment = mem_frag, .session = mem_session };
29332933

29342934
// Initialize the shared RX instance.
29352935
const uint64_t local_uid = 0x6EC164169C3088B4ULL;
@@ -2938,7 +2938,7 @@ static void test_rx_port(void)
29382938
callback_result_t cb_result = { 0 };
29392939
rx.user = &cb_result;
29402940
TEST_ASSERT_EQUAL(local_uid, rx.p2p_port.topic_hash);
2941-
TEST_ASSERT_EQUAL(UDPARD_REORDERING_WINDOW_UNORDERED, rx.p2p_port.reordering_window);
2941+
TEST_ASSERT_EQUAL(UDPARD_RX_REORDERING_WINDOW_UNORDERED, rx.p2p_port.reordering_window);
29422942

29432943
// Initialize two ports: one ORDERED, one STATELESS.
29442944
udpard_rx_port_t port_ordered;
@@ -2948,7 +2948,7 @@ static void test_rx_port(void)
29482948
udpard_rx_port_t port_stateless;
29492949
const uint64_t topic_hash_stateless = 0xFEDCBA0987654321ULL;
29502950
TEST_ASSERT(
2951-
udpard_rx_port_new(&port_stateless, topic_hash_stateless, 500, UDPARD_REORDERING_WINDOW_STATELESS, rx_mem));
2951+
udpard_rx_port_new(&port_stateless, topic_hash_stateless, 500, UDPARD_RX_REORDERING_WINDOW_STATELESS, rx_mem));
29522952

29532953
udpard_us_t now = 0;
29542954

@@ -3301,9 +3301,9 @@ static void test_rx_port_timeouts(void)
33013301

33023302
instrumented_allocator_t alloc_payload = { 0 };
33033303
instrumented_allocator_new(&alloc_payload);
3304-
const udpard_mem_resource_t mem_payload = instrumented_allocator_make_resource(&alloc_payload);
3305-
const udpard_mem_deleter_t del_payload = instrumented_allocator_make_deleter(&alloc_payload);
3306-
const udpard_rx_memory_resources_t rx_mem = { .fragment = mem_frag, .session = mem_session };
3304+
const udpard_mem_resource_t mem_payload = instrumented_allocator_make_resource(&alloc_payload);
3305+
const udpard_mem_deleter_t del_payload = instrumented_allocator_make_deleter(&alloc_payload);
3306+
const udpard_rx_mem_resources_t rx_mem = { .fragment = mem_frag, .session = mem_session };
33073307

33083308
udpard_rx_t rx;
33093309
callback_result_t cb_result = { 0 };
@@ -3461,21 +3461,21 @@ static void test_rx_port_oom(void)
34613461
instrumented_allocator_new(&alloc_session);
34623462
instrumented_allocator_t alloc_payload = { 0 };
34633463
instrumented_allocator_new(&alloc_payload);
3464-
alloc_session.limit_fragments = 0;
3465-
alloc_frag.limit_fragments = 0;
3466-
const udpard_mem_resource_t mem_frag = instrumented_allocator_make_resource(&alloc_frag);
3467-
const udpard_mem_resource_t mem_session = instrumented_allocator_make_resource(&alloc_session);
3468-
const udpard_mem_resource_t mem_payload = instrumented_allocator_make_resource(&alloc_payload);
3469-
const udpard_mem_deleter_t del_payload = instrumented_allocator_make_deleter(&alloc_payload);
3470-
const udpard_rx_memory_resources_t rx_mem = { .fragment = mem_frag, .session = mem_session };
3471-
udpard_rx_t rx;
3472-
callback_result_t cb_result = { 0 };
3464+
alloc_session.limit_fragments = 0;
3465+
alloc_frag.limit_fragments = 0;
3466+
const udpard_mem_resource_t mem_frag = instrumented_allocator_make_resource(&alloc_frag);
3467+
const udpard_mem_resource_t mem_session = instrumented_allocator_make_resource(&alloc_session);
3468+
const udpard_mem_resource_t mem_payload = instrumented_allocator_make_resource(&alloc_payload);
3469+
const udpard_mem_deleter_t del_payload = instrumented_allocator_make_deleter(&alloc_payload);
3470+
const udpard_rx_mem_resources_t rx_mem = { .fragment = mem_frag, .session = mem_session };
3471+
udpard_rx_t rx;
3472+
callback_result_t cb_result = { 0 };
34733473
TEST_ASSERT(udpard_rx_new(&rx, 0x5555ULL, rx_mem, &on_message, &on_collision, &on_ack_mandate));
34743474
rx.user = &cb_result;
34753475
udpard_rx_port_t port_ordered;
34763476
udpard_rx_port_t port_stateless;
34773477
TEST_ASSERT(udpard_rx_port_new(&port_ordered, 0xAAAALL, 100, 20000, rx_mem));
3478-
TEST_ASSERT(udpard_rx_port_new(&port_stateless, 0xBBBBLL, 100, UDPARD_REORDERING_WINDOW_STATELESS, rx_mem));
3478+
TEST_ASSERT(udpard_rx_port_new(&port_stateless, 0xBBBBLL, 100, UDPARD_RX_REORDERING_WINDOW_STATELESS, rx_mem));
34793479
udpard_us_t now = 0;
34803480
const byte_t payload_state[] = { 's', 't', 'a', 't', 'e', 'f', 'u', 'l' };
34813481
const size_t payload_len = sizeof(payload_state);
@@ -3556,7 +3556,7 @@ static void test_rx_free_loop(void)
35563556
const udpard_mem_resource_t mem_payload = instrumented_allocator_make_resource(&alloc_payload);
35573557
const udpard_mem_deleter_t del_payload = instrumented_allocator_make_deleter(&alloc_payload);
35583558

3559-
const udpard_rx_memory_resources_t rx_mem = { .fragment = mem_frag, .session = mem_session };
3559+
const udpard_rx_mem_resources_t rx_mem = { .fragment = mem_frag, .session = mem_session };
35603560

35613561
udpard_rx_t rx;
35623562
callback_result_t cb_result = { 0 };

0 commit comments

Comments
 (0)