Ignore:
Timestamp:
Jan 18, 2019, 8:17:57 PM (10 months ago)
Author:
Gorgone Impertinence
Message:

big cleanup pack 3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/oscam-garbage.c

    r11246 r11473  
    4545
    4646    SAFE_MUTEX_LOCK(&add_lock);
    47    
     47
    4848    int32_t bucket = counter++;
    49    
     49
    5050    if(counter >= HASH_BUCKETS)
    5151    {
    5252        counter = 0;
    5353    }
    54    
     54
    5555    SAFE_MUTEX_UNLOCK(&add_lock);
    56    
     56
    5757    struct cs_garbage *garbage = (struct cs_garbage*)malloc(sizeof(struct cs_garbage));
    5858    if(garbage == NULL)
    5959    {
    60         cs_log("*** MEMORY FULL -> FREEING DIRECT MAY LEAD TO INSTABILITY!!!! ***");
     60        cs_log("*** MEMORY FULL -> FREEING DIRECT MAY LEAD TO INSTABILITY!!! ***");
    6161        NULLFREE(data);
    6262        return;
     
    9292#endif
    9393
    94     garbage->next = garbage_first[bucket]; 
     94    garbage->next = garbage_first[bucket];
    9595    garbage_first[bucket] = garbage;
    96    
     96
    9797    cs_writeunlock(__func__, &garbage_lock[bucket]);
    9898}
     
    106106    struct cs_garbage *garbage, *next, *prev, *first;
    107107    set_thread_name(__func__);
    108     int32_t timeout_time = 2*cfg.ctimeout/1000+6;
    109        
     108    int32_t timeout_time = 2 * cfg.ctimeout / 1000 + 6;
     109
    110110    while(garbage_collector_active)
    111111    {
    112112        time_t deltime = time(NULL) - timeout_time;
    113        
     113
    114114        for(i = 0; i < HASH_BUCKETS; ++i)
    115115        {
     
    117117            cs_writelock(__func__, &garbage_lock[i]);
    118118            first = garbage_first[i];
    119            
    120             for(garbage = first, prev = NULL; garbage; prev = garbage, garbage = garbage->next,j++)
    121             {
    122                 if(j==2)
     119
     120            for(garbage = first, prev = NULL; garbage; prev = garbage, garbage = garbage->next, j++)
     121            {
     122                if(j == 2)
    123123                {
    124124                    j++;
     
    126126                }
    127127
    128                 if(garbage->time < deltime)     // all following elements are too new
     128                if(garbage->time < deltime) // all following elements are too new
    129129                {
    130130                    if(prev)
     
    140140            }
    141141
    142             if(j<3)
     142            if(j < 3)
    143143            {
    144144                cs_writeunlock(__func__, &garbage_lock[i]);
     
    163163    garbage_debug = debug;
    164164    int32_t i;
    165    
     165
    166166    SAFE_MUTEX_INIT(&add_lock, NULL);
    167    
     167
    168168    for(i = 0; i < HASH_BUCKETS; ++i)
    169169    {
     
    194194        SAFE_COND_SIGNAL(&sleep_cond);
    195195        SAFE_THREAD_JOIN(garbage_thread, NULL);
     196
    196197        for(i = 0; i < HASH_BUCKETS; ++i)
    197198            { cs_writelock(__func__, &garbage_lock[i]); }
     
    207208            }
    208209        }
    209        
    210         for(i = 0; i < HASH_BUCKETS; ++i)
    211         { 
     210
     211        for(i = 0; i < HASH_BUCKETS; ++i)
     212        {
    212213            cs_writeunlock(__func__, &garbage_lock[i]);
    213214            cs_lock_destroy(__func__, &garbage_lock[i]);
    214215        }
    215216
    216         pthread_mutex_destroy(&add_lock);
    217         pthread_cond_destroy(&sleep_cond);
     217        pthread_mutex_destroy(&add_lock);
     218        pthread_cond_destroy(&sleep_cond);
    218219        pthread_mutex_destroy(&sleep_cond_mutex);
    219220    }
Note: See TracChangeset for help on using the changeset viewer.