Changeset 640

Show
Ignore:
Timestamp:
07/25/05 20:39:45 (3 years ago)
Author:
jajcus
Message:

- call the 'garbage collector' on each user_delete() (makes unregistration work) and every minute (will probably save some memory)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/users.c

    r630 r640  
    3434static char *spool_dir; 
    3535char *default_user_locale="C"; 
     36static guint users_tick_source; 
     37 
     38static int user_destroy(User *s); 
     39 
     40static gboolean users_gc_hash_func(gpointer key,gpointer value,gpointer udata){ 
     41User *u=(User *)value; 
     42 
     43        if (u->refcount==0) { 
     44                user_destroy(u); 
     45                g_free(key); 
     46        } 
     47        return TRUE; 
     48} 
     49 
     50int users_gc(){ 
     51        g_hash_table_foreach_remove(users_jid,users_gc_hash_func,NULL); 
     52        return 0; 
     53} 
     54 
     55gboolean users_tick(gpointer data){ 
     56 
     57        users_gc(); 
     58        return TRUE; 
     59} 
    3660 
    3761int users_init(){ 
     
    4973        users_jid=g_hash_table_new(g_str_hash,g_str_equal); 
    5074        if (!users_jid) return -1; 
     75         
     76        users_tick_source=g_timeout_add(60000,users_tick,NULL); 
     77         
    5178        return 0; 
    5279} 
    5380 
    54 static int user_destroy(User *s); 
    55  
    56 static gboolean users_gc_hash_func(gpointer key,gpointer value,gpointer udata){ 
    57 User *u=(User *)value; 
    58  
    59         if (u->refcount==0) { 
    60                 user_destroy(u); 
    61                 g_free(key); 
    62         } 
    63         return TRUE; 
    64 } 
    65  
    66 int users_gc(){ 
    67         g_hash_table_foreach_remove(users_jid,users_gc_hash_func,NULL); 
    68         return 0; 
    69 } 
    7081 
    7182 
     
    7384guint s; 
    7485         
     86        g_source_remove(users_tick_source); 
    7587        s=g_hash_table_size(users_jid); 
    7688        if (s) g_debug(L_("Before cleanup: %u users in hash table"),s); 
     
    648660        g_free(njid); 
    649661 
     662        users_gc(); 
     663 
    650664        return r; 
    651665}