use crate::REGISTRY;
pub fn cleanup_tempfiles_signal_safe() {
let current_pid = std::process::id();
#[cfg(feature = "hp-hashmap")]
{
use crate::NEXT_MAP_INDEX;
use std::sync::atomic::Ordering;
let one_past_last_index = NEXT_MAP_INDEX.load(Ordering::SeqCst);
for idx in 0..one_past_last_index {
if let Some(entry) = REGISTRY.try_entry(idx) {
entry.and_modify(|tempfile| {
if tempfile
.as_ref()
.map_or(false, |tf| tf.owning_process_id == current_pid)
{
if let Some(tempfile) = tempfile.take() {
tempfile.drop_without_deallocation();
}
}
});
}
}
}
#[cfg(not(feature = "hp-hashmap"))]
{
REGISTRY.for_each(|tf| {
if tf.as_ref().map_or(false, |tf| tf.owning_process_id == current_pid) {
if let Some(tf) = tf.take() {
tf.drop_without_deallocation();
}
}
});
}
}
pub fn cleanup_tempfiles() {
let current_pid = std::process::id();
#[cfg(feature = "hp-hashmap")]
REGISTRY.iter_mut().for_each(|mut tf| {
if tf.as_ref().map_or(false, |tf| tf.owning_process_id == current_pid) {
tf.take();
}
});
#[cfg(not(feature = "hp-hashmap"))]
REGISTRY.for_each(|tf| {
if tf.as_ref().map_or(false, |tf| tf.owning_process_id == current_pid) {
tf.take();
}
});
}