Changeset 1482 in svn for trunk/mod_cacher/xc_cacher.c


Ignore:
Timestamp:
2014-03-30T09:06:19Z (17 months ago)
Author:
Xuefer
Message:

fixed random 24H counters clear. it's a race cached condition. thanks to the report from Per Hansson

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/mod_cacher/xc_cacher.c

    r1478 r1482  
    448448}
    449449/* }}} */
    450 static inline void xc_counters_inc(time_t *curtime, zend_uint *curslot, time_t interval, zend_ulong *counters, zend_uint count TSRMLS_DC) /* {{{ */
     450static inline void xc_counters_inc(time_t *curtime, zend_uint *curslot, time_t interval, zend_ulong *counters, zend_uint ncounters TSRMLS_DC) /* {{{ */
    451451{
    452452    time_t n = XG(request_time) / interval;
    453     if (*curtime != n) {
    454         zend_uint target_slot = ((zend_uint) n) % count;
     453    if (*curtime < n) {
     454        zend_uint target_slot = ((zend_uint) n) % ncounters;
    455455        zend_uint slot;
    456         for (slot = advance_wrapped(*curslot, count);
     456        for (slot = advance_wrapped(*curslot, ncounters);
    457457                slot != target_slot;
    458                 slot = advance_wrapped(slot, count)) {
     458                slot = advance_wrapped(slot, ncounters)) {
    459459            counters[slot] = 0;
    460460        }
     
    466466}
    467467/* }}} */
     468#define xc_countof(array) (sizeof(array) / sizeof(array[0]))
    468469static inline void xc_cached_hit_unlocked(xc_cached_t *cached TSRMLS_DC) /* {{{ */
    469470{
     
    473474            , &cached->hits_by_hour_cur_slot, 60 * 60
    474475            , cached->hits_by_hour
    475             , sizeof(cached->hits_by_hour) / sizeof(cached->hits_by_hour[0])
     476            , xc_countof(cached->hits_by_hour)
    476477            TSRMLS_CC);
    477478
     
    479480            , &cached->hits_by_second_cur_slot, 1
    480481            , cached->hits_by_second
    481             , sizeof(cached->hits_by_second) / sizeof(cached->hits_by_second[0])
     482            , xc_countof(cached->hits_by_second)
    482483            TSRMLS_CC);
    483484}
     
    666667    MAKE_STD_ZVAL(hits);
    667668    array_init(hits);
    668     for (i = 0; i < sizeof(cached->hits_by_hour) / sizeof(cached->hits_by_hour[0]); i ++) {
     669    for (i = 0; i < xc_countof(cached->hits_by_hour); i ++) {
    669670        add_next_index_long(hits, (long) cached->hits_by_hour[i]);
    670671    }
     
    673674    MAKE_STD_ZVAL(hits);
    674675    array_init(hits);
    675     for (i = 0; i < sizeof(cached->hits_by_second) / sizeof(cached->hits_by_second[0]); i ++) {
     676    for (i = 0; i < xc_countof(cached->hits_by_second); i ++) {
    676677        add_next_index_long(hits, (long) cached->hits_by_second[i]);
    677678    }
Note: See TracChangeset for help on using the changeset viewer.