task_t *task_ref(task_id tid) { task_t f = { tid }; lc_spin_lock(lock); task_t *t = map_find(tasks, &f); if (t) { atomic_int_inc(&t->ref_count); } lc_spin_unlock(lock); return t; }
/** * Cleanup the TTH cache by removing needless entries. */ void tth_cache_cleanup(void) { if (0 == atomic_int_inc(&tth_cache_cleanups)) { int id = thread_create(tth_cache_cleanup_thread, NULL, THREAD_F_DETACH | THREAD_F_WARN, THREAD_STACK_MIN); if (-1 == id) atomic_int_dec(&tth_cache_cleanups); } else if (debugging(0)) { g_warning("%s(): concurrent cleanup in progress", G_STRFUNC); atomic_int_dec(&tth_cache_cleanups); } }