| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #ifndef NETDATA_STREAM_SENDER_COMMIT_H |
| 4 | #define NETDATA_STREAM_SENDER_COMMIT_H |
| 5 | |
| 6 | #include "libnetdata/libnetdata.h" |
| 7 | #include "stream-traffic-types.h" |
| 8 | |
| 9 | struct rrdhost; |
| 10 | struct sender_state; |
| 11 | struct receiver_state; |
| 12 | |
| 13 | struct sender_buffer { |
| 14 | const char *last_function; |
| 15 | BUFFER *wb; |
| 16 | pid_t receiver_tid; |
| 17 | bool used; |
| 18 | uint16_t reused; |
| 19 | uint32_t our_recreates; |
| 20 | uint32_t sender_recreates; |
| 21 | }; |
| 22 | void sender_buffer_destroy(struct sender_buffer *commit); |
| 23 | |
| 24 | // thread buffer for sending data upstream (to a parent) |
| 25 | |
| 26 | void sender_thread_buffer_free(void); |
| 27 | void sender_host_buffer_free(struct rrdhost *host); |
| 28 | |
| 29 | // get the thread buffer |
| 30 | // this is the preferred buffer for dedicated workers sending a lot of messages (like replication) |
| 31 | // these threads need to maintain enough allocation for repeated use of the buffer |
| 32 | BUFFER *sender_thread_buffer_with_trace(struct sender_state *s, size_t default_size, const char *func); |
| 33 | #define sender_thread_buffer(s, default_size) sender_thread_buffer_with_trace(s, default_size, __FUNCTION__) |
| 34 | |
| 35 | // get the global host buffer |
| 36 | // this is the preferred buffer for stream threads (unified receiver / sender threads) |
| 37 | // these threads require a buffer that can remain intact while switching hosts |
| 38 | BUFFER *sender_host_buffer_with_trace(struct rrdhost *host, const char *func); |
| 39 | #define sender_host_buffer(host) sender_host_buffer_with_trace(host, __FUNCTION__) |
| 40 | |
| 41 | // commit a buffer acquired with sender_thread_buffer() or sender_host_buffer() |
| 42 | void sender_thread_commit_with_trace(struct sender_state *s, BUFFER *wb, STREAM_TRAFFIC_TYPE type, const char *func); |
| 43 | #define sender_commit(s, wb, type) sender_thread_commit_with_trace(s, wb, type, __FUNCTION__) |
| 44 | |
| 45 | // commit any buffer |
| 46 | // this is the preferred buffer for occasional senders, as it avoids a permanently allocated buffer |
| 47 | void sender_buffer_commit(struct sender_state *s, BUFFER *wb, struct sender_buffer *commit, STREAM_TRAFFIC_TYPE type); |
| 48 | #define sender_commit_clean_buffer(s, wb, type) sender_buffer_commit(s, wb, NULL, type) |
| 49 | |
| 50 | #endif //NETDATA_STREAM_SENDER_COMMIT_H |