Skip to content

Commit

Permalink
improved locks
Browse files Browse the repository at this point in the history
  • Loading branch information
fangfufu committed Dec 6, 2024
1 parent eca4375 commit 36b5b44
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,18 +554,24 @@ static void Cache_free(Cache *cf)
{
int err_code = 0;

PTHREAD_MUTEX_LOCK(&cf->seek_lock);
PTHREAD_MUTEX_UNLOCK(&cf->seek_lock);
err_code = pthread_mutex_destroy(&cf->seek_lock);
if (err_code) {
lprintf(fatal, "could not destroy seek_lock: %d, %s!\n", err_code,
strerror(err_code));
}

PTHREAD_MUTEX_LOCK(&cf->w_lock);
PTHREAD_MUTEX_UNLOCK(&cf->w_lock);
err_code = pthread_mutex_destroy(&cf->w_lock);
if (err_code) {
lprintf(fatal, "could not destroy w_lock: %d, %s!\n", err_code,
strerror(err_code));
}

PTHREAD_MUTEX_LOCK(&cf->bgt_lock);
PTHREAD_MUTEX_UNLOCK(&cf->bgt_lock);
err_code = pthread_mutex_destroy(&cf->bgt_lock);
if (err_code) {
lprintf(fatal, "could not destroy bgt_lock: %d, %s!\n", err_code,
Expand Down Expand Up @@ -977,8 +983,8 @@ void Cache_close(Cache *cf)
lprintf(cache_lock_debug,
"thread %x: unlocking cf_lock, cache closed: %s\n", pthread_self(),
cf->path);
PTHREAD_MUTEX_UNLOCK(&cf_lock);
Cache_free(cf);
PTHREAD_MUTEX_UNLOCK(&cf_lock);
}

/**
Expand Down

0 comments on commit 36b5b44

Please sign in to comment.