| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #include "rrdhost-slots.h" |
| 4 | #include "rrdset.h" |
| 5 | |
| 6 | void rrdhost_pluginsd_send_chart_slots_free(RRDHOST *host) { |
| 7 | rrd_slot_memory_removed(host->stream.snd.pluginsd_chart_slots.available.size * sizeof(uint32_t)); |
| 8 | |
| 9 | spinlock_lock(&host->stream.snd.pluginsd_chart_slots.available.spinlock); |
| 10 | host->stream.snd.pluginsd_chart_slots.available.ignore = true; |
| 11 | freez(host->stream.snd.pluginsd_chart_slots.available.array); |
| 12 | host->stream.snd.pluginsd_chart_slots.available.array = NULL; |
| 13 | host->stream.snd.pluginsd_chart_slots.available.used = 0; |
| 14 | host->stream.snd.pluginsd_chart_slots.available.size = 0; |
| 15 | spinlock_unlock(&host->stream.snd.pluginsd_chart_slots.available.spinlock); |
| 16 | |
| 17 | // zero all the slots on all charts, so that they will not attempt to access the array |
| 18 | RRDSET *st; |
| 19 | rrdset_foreach_read(st, host) { |
| 20 | st->stream.snd.chart_slot = 0; |
| 21 | } |
| 22 | rrdset_foreach_done(st); |
| 23 | } |
| 24 | |
| 25 | void rrdhost_pluginsd_receive_chart_slots_free(RRDHOST *host) { |
| 26 | rrd_slot_memory_removed(host->stream.rcv.pluginsd_chart_slots.size * sizeof(RRDSET *)); |
| 27 | |
| 28 | spinlock_lock(&host->stream.rcv.pluginsd_chart_slots.spinlock); |
| 29 | |
| 30 | if(host->stream.rcv.pluginsd_chart_slots.array) { |
| 31 | for (size_t s = 0; s < host->stream.rcv.pluginsd_chart_slots.size; s++) { |
| 32 | RRDSET *st = host->stream.rcv.pluginsd_chart_slots.array[s]; |
| 33 | if(st) { |
| 34 | // Clear collector_tid - the collector is already stopped |
| 35 | // (stream_receiver_signal_to_stop_and_wait was called before this) |
| 36 | // so it's safe to cleanup regardless of the previous collector_tid value |
| 37 | __atomic_store_n(&st->pluginsd.collector_tid, 0, __ATOMIC_RELEASE); |
| 38 | |
| 39 | // Pre-clear last_slot so that rrdset_pluginsd_receive_unslot_and_cleanup |
| 40 | // won't try to re-acquire the host spinlock we already hold. |
| 41 | // This prevents recursive locking on pluginsd_chart_slots.spinlock. |
| 42 | // We're freeing the entire host slots array below, so clearing individual |
| 43 | // slot entries is unnecessary. |
| 44 | st->pluginsd.last_slot = -1; |
| 45 | |
| 46 | rrdset_pluginsd_receive_unslot_and_cleanup(st); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | freez(host->stream.rcv.pluginsd_chart_slots.array); |
| 51 | host->stream.rcv.pluginsd_chart_slots.array = NULL; |
| 52 | host->stream.rcv.pluginsd_chart_slots.size = 0; |
| 53 | } |
| 54 | |
| 55 | spinlock_unlock(&host->stream.rcv.pluginsd_chart_slots.spinlock); |
| 56 | } |