diff options
| author | Burt P <pburt0@gmail.com> | 2019-08-03 13:15:12 -0500 | 
|---|---|---|
| committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2019-08-10 16:47:25 -0700 | 
| commit | a071cf575cafc3d8c15e4886fd65b8763086016f (patch) | |
| tree | e60047d213e2159cdd7980bc2ca3b004e5bbfd14 /deps/sysobj_early/src | |
| parent | 4ebe1d6b2bc615acbe28aa8defdeda2c71d1c57f (diff) | |
auto_free: update with auto_free_on_exit(), use to free arm_ids_file in arm_data.c
Signed-off-by: Burt P <pburt0@gmail.com>
Diffstat (limited to 'deps/sysobj_early/src')
| -rw-r--r-- | deps/sysobj_early/src/auto_free.c | 61 | 
1 files changed, 45 insertions, 16 deletions
| diff --git a/deps/sysobj_early/src/auto_free.c b/deps/sysobj_early/src/auto_free.c index 78f11690..3d75c169 100644 --- a/deps/sysobj_early/src/auto_free.c +++ b/deps/sysobj_early/src/auto_free.c @@ -19,15 +19,26 @@   */  #include "auto_free.h" +#if (AF_USE_SYSOBJ) +#include "sysobj.h" +#else  #include <stdio.h> -//#include "sysobj.h" +#define sysobj_elapsed() af_elapsed() +#define sysobj_stats af_stats +static struct { +    double auto_free_next; +    unsigned long long +        auto_freed, +        auto_free_len; +} af_stats; +#endif  static GMutex free_lock;  static GSList *free_list = NULL;  static gboolean free_final = FALSE;  static GTimer *auto_free_timer = NULL;  static guint free_event_source = 0; -#define _elapsed() (auto_free_timer ? g_timer_elapsed(auto_free_timer, NULL) : 0) +#define af_elapsed() (auto_free_timer ? g_timer_elapsed(auto_free_timer, NULL) : 0)  #define auto_free_msg(msg, ...)  fprintf (stderr, "[%s] " msg "\n", __FUNCTION__, ##__VA_ARGS__) /**/ @@ -49,7 +60,7 @@ gboolean free_auto_free_sf(gpointer trash) {          return G_SOURCE_REMOVE;      }      free_auto_free(); -    //sysobj_stats.auto_free_next = sysobj_elapsed() + AF_SECONDS; +    sysobj_stats.auto_free_next = sysobj_elapsed() + AF_SECONDS;      return G_SOURCE_CONTINUE;  } @@ -73,7 +84,7 @@ gpointer auto_free_ex_(gpointer p, GDestroyNotify f, const char *file, int line,           * will be called at sysobj_cleanup() and when exiting           * threads, as in sysobj_foreach(). */          free_event_source = g_timeout_add_seconds(AF_SECONDS, (GSourceFunc)free_auto_free_sf, NULL); -        //sysobj_stats.auto_free_next = sysobj_elapsed() + AF_SECONDS; +        sysobj_stats.auto_free_next = sysobj_elapsed() + AF_SECONDS;      }      auto_free_item *z = g_new0(auto_free_item, 1); @@ -83,22 +94,41 @@ gpointer auto_free_ex_(gpointer p, GDestroyNotify f, const char *file, int line,      z->file = file;      z->line = line;      z->func = func; -    z->stamp = _elapsed(); +    z->stamp = af_elapsed();      g_mutex_lock(&free_lock);      free_list = g_slist_prepend(free_list, z); -    //sysobj_stats.auto_free_len++; +    sysobj_stats.auto_free_len++;      g_mutex_unlock(&free_lock);      return p;  } -gpointer auto_free_(gpointer p, const char *file, int line, const char *func) { -    return auto_free_ex_(p, (GDestroyNotify)g_free, file, line, func); +gpointer auto_free_on_exit_ex_(gpointer p, GDestroyNotify f, const char *file, int line, const char *func) { +    if (!p) return p; + +    auto_free_item *z = g_new0(auto_free_item, 1); +    z->ptr = p; +    z->f_free = f; +    z->thread = g_thread_self(); +    z->file = file; +    z->line = line; +    z->func = func; +    z->stamp = -1.0; +    g_mutex_lock(&free_lock); +    free_list = g_slist_prepend(free_list, z); +    sysobj_stats.auto_free_len++; +    g_mutex_unlock(&free_lock); +    return p;  }  static struct { GDestroyNotify fptr; char *name; }      free_function_tab[] = {      { (GDestroyNotify) g_free,             "g_free" }, -    // ... +#if (AF_USE_SYSOBJ) +    { (GDestroyNotify) sysobj_free,        "sysobj_free" }, +    { (GDestroyNotify) class_free,         "class_free" }, +    { (GDestroyNotify) sysobj_filter_free, "sysobj_filter_free" }, +    { (GDestroyNotify) sysobj_virt_free,   "sysobj_virt_free" }, +#endif      { NULL, "(null)" },  }; @@ -106,18 +136,17 @@ static void free_auto_free_ex(gboolean thread_final) {      GThread *this_thread = g_thread_self();      GSList *l = NULL, *n = NULL;      long long unsigned fc = 0; -    double now = _elapsed(); +    double now = af_elapsed();      if (!free_list) return;      g_mutex_lock(&free_lock); -    if (DEBUG_AUTO_FREE) { -        unsigned long long ll = g_slist_length(free_list); -        auto_free_msg("%llu total items in queue, but will free from thread %p only... ", ll, this_thread); -    } +    if (DEBUG_AUTO_FREE) +        auto_free_msg("%llu total items in queue, but will free from thread %p only... ", sysobj_stats.auto_free_len, this_thread);      for(l = free_list; l; l = n) {          auto_free_item *z = (auto_free_item*)l->data;          n = l->next; +        if (!free_final && z->stamp < 0) continue;          double age = now - z->stamp;          if (free_final || (z->thread == this_thread && (thread_final || age > AF_DELAY_SECONDS) ) ) {              if (DEBUG_AUTO_FREE == 2) { @@ -143,8 +172,8 @@ static void free_auto_free_ex(gboolean thread_final) {      }      if (DEBUG_AUTO_FREE)          auto_free_msg("... freed %llu (from thread %p)", fc, this_thread); -    //sysobj_stats.auto_freed += fc; -    //sysobj_stats.auto_free_len -= fc; +    sysobj_stats.auto_freed += fc; +    sysobj_stats.auto_free_len -= fc;      g_mutex_unlock(&free_lock);  } | 
