Skip to content

Commit

Permalink
fix: release args
Browse files Browse the repository at this point in the history
  • Loading branch information
Zxilly committed Dec 18, 2024
1 parent d89b534 commit be8da9d
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,28 @@ typedef struct {
} thread_args;

_Noreturn static void* check_cache(void* arg) {
__auto_type args = (thread_args*)arg;
const __auto_type args = (thread_args *)arg;
const __auto_type lock = args->lock;
const __auto_type table = args->table;
const __auto_type check_interval = args->check_interval;
free(args);

while (true) {
pthread_rwlock_wrlock(args->lock);
pthread_rwlock_wrlock(lock);

const time_t now = time(NULL);
struct cache *cur, *tmp;

HASH_ITER(hh, not_http_dst_cache, cur, tmp) {
if (difftime(now, cur->last_time) > args->check_interval) {
HASH_ITER(hh, table, cur, tmp) {
if (difftime(now, cur->last_time) > check_interval) {
HASH_DEL(not_http_dst_cache, cur);
free(cur);
}
}

pthread_rwlock_unlock(args->lock);
pthread_rwlock_unlock(lock);

sleep(args->check_interval);
sleep(check_interval);
}
}

Expand Down

0 comments on commit be8da9d

Please sign in to comment.