aboutsummaryrefslogtreecommitdiff
path: root/deps/sysobj_early/include/auto_free.h
diff options
context:
space:
mode:
authorBurt P <pburt0@gmail.com>2019-07-25 20:43:25 -0500
committerLeandro A. F. Pereira <leandro@hardinfo.org>2019-07-29 19:44:59 -0700
commit6938cbfd0c8d64aa93633fc7423879de757fd45c (patch)
tree359dd94243c72f29da8d848dbe5f23dd84b35fbc /deps/sysobj_early/include/auto_free.h
parent9d043ceb42468af2f18b823e7dd5d026ef24b0b1 (diff)
replace idle_free() with auto_free() from sysobj
* auto_free() works in both report mode and gui mode. * auto_free() only creates one recuring event for the whole system rather than idle_free()'s one event per call. * auto_free_ex() allows specifying the free function to use. * auto_free() is thread-aware, free_auto_free_thread_final() can be used to clean up on thread exit. * auto_free() has some tweakability. Signed-off-by: Burt P <pburt0@gmail.com>
Diffstat (limited to 'deps/sysobj_early/include/auto_free.h')
-rw-r--r--deps/sysobj_early/include/auto_free.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/deps/sysobj_early/include/auto_free.h b/deps/sysobj_early/include/auto_free.h
new file mode 100644
index 00000000..e038783d
--- /dev/null
+++ b/deps/sysobj_early/include/auto_free.h
@@ -0,0 +1,58 @@
+/*
+ * sysobj - https://github.com/bp0/verbose-spork
+ * Copyright (C) 2018 Burt P. <pburt0@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef _AUTO_FREE_H_
+#define _AUTO_FREE_H_
+
+#include <glib.h>
+
+/* DEBUG_AUTO_FREE messages level:
+ * 0 - none
+ * 1 - some
+ * 2 - much
+ */
+#ifndef DEBUG_AUTO_FREE
+#define DEBUG_AUTO_FREE 0
+#endif
+/* the period between free_auto_free()s in the main loop */
+#define AF_SECONDS 11
+/* the minimum time between auto_free(p) and free(p) */
+#define AF_DELAY_SECONDS 10
+
+#if (DEBUG_AUTO_FREE > 0)
+#define auto_free(p) auto_free_(p, __FILE__, __LINE__, __FUNCTION__)
+#define auto_free_ex(p, f) auto_free_ex_(p, f, __FILE__, __LINE__, __FUNCTION__)
+#else
+#define auto_free(p) auto_free_(p, NULL, 0, NULL)
+#define auto_free_ex(p, f) auto_free_ex_(p, f, NULL, 0, NULL)
+#endif
+gpointer auto_free_(gpointer p, const char *file, int line, const char *func);
+gpointer auto_free_ex_(gpointer p, GDestroyNotify f, const char *file, int line, const char *func);
+
+/* free all the auto_free marked items in the current thread */
+void free_auto_free();
+
+/* call at thread termination */
+void free_auto_free_thread_final();
+
+/* call at program termination */
+void free_auto_free_final();
+
+#endif