unsigned long global_getrate_avg (struct rate_calc *rate) { unsigned long v; thread_spin_lock (&global.spinlock); v = rate_avg (rate); thread_spin_unlock (&global.spinlock); return v; }
unsigned long global_getrate_avg (struct rate_calc *rate) { unsigned long avg = rate_avg (rate); if (global.max_rate) { float ratio = avg / global.max_rate; if (ratio > 0.99) throttle_sends = 3; else if (ratio > 0.9) throttle_sends = 2; else if (ratio > 0.8) throttle_sends = 1; else if (throttle_sends > 0) throttle_sends--; } return avg; }
void global_add_bitrates (struct rate_calc *rate, unsigned long value, uint64_t milli) { float avg; thread_spin_lock (&global.spinlock); rate_add (rate, value, milli); avg = rate_avg (rate); if (global.max_rate) { float ratio = avg / global.max_rate; if (ratio > 0.99) throttle_sends = 3; else if (ratio > 0.9) throttle_sends = 2; else if (ratio > 0.8) throttle_sends = 1; else if (throttle_sends > 0) throttle_sends--; } thread_spin_unlock (&global.spinlock); }
void fserve_scan (time_t now) { avl_node *node; avl_tree_wlock (fh_cache); node = avl_get_first (fh_cache); while (node) { fh_node *fh = node->key; node = avl_get_next (node); thread_mutex_lock (&fh->lock); if (global.running != ICE_RUNNING) fh->expire = 0; if (now == (time_t)0) { fh->expire = 0; thread_mutex_unlock (&fh->lock); continue; } if (fh->finfo.limit) { fbinfo *finfo = &fh->finfo; if (fh->stats == 0) { int len = strlen (finfo->mount) + 10; char *str = alloca (len); char buf[20]; snprintf (str, len, "%s-%s", (finfo->flags & FS_FALLBACK) ? "fallback" : "file", finfo->mount); fh->stats = stats_handle (str); stats_set_flags (fh->stats, "fallback", "file", STATS_COUNTERS|STATS_HIDDEN); stats_set_flags (fh->stats, "outgoing_kbitrate", "0", STATS_COUNTERS|STATS_HIDDEN); snprintf (buf, sizeof (buf), "%d", fh->refcount); stats_set_flags (fh->stats, "listeners", buf, STATS_GENERAL|STATS_HIDDEN); snprintf (buf, sizeof (buf), "%d", fh->peak); stats_set_flags (fh->stats, "listener_peak", buf, STATS_GENERAL|STATS_HIDDEN); fh->prev_count = fh->refcount; } else { stats_lock (fh->stats, NULL); if (fh->prev_count != fh->refcount) { fh->prev_count = fh->refcount; stats_set_args (fh->stats, "listeners", "%ld", fh->refcount); stats_set_args (fh->stats, "listener_peak", "%ld", fh->peak); } } if (fh->stats_update <= now) { fh->stats_update = now + 5; stats_set_args (fh->stats, "outgoing_kbitrate", "%ld", (long)((8 * rate_avg (fh->out_bitrate))/1024)); } stats_release (fh->stats); } if (fh->refcount == 0 && fh->expire >= 0 && now >= fh->expire) { DEBUG1 ("timeout of %s", fh->finfo.mount); if (fh->stats) { stats_lock (fh->stats, NULL); stats_set (fh->stats, NULL, NULL); } remove_fh_from_cache (fh); thread_mutex_unlock (&fh->lock); _delete_fh (fh); continue; } thread_mutex_unlock (&fh->lock); } avl_tree_unlock (fh_cache); }