Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
DVR: fix locking in dvr_get_disk_space_tcb
  • Loading branch information
perexg committed Dec 3, 2015
1 parent 4d0738e commit bd86875
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/dvr/dvr_vfsmgr.c
Expand Up @@ -168,6 +168,8 @@ dvr_disk_space_check()
int64_t requiredBytes, availBytes;
int idx = 0, cleanupDone = 0;

pthread_mutex_lock(&global_lock);

dvr_disk_space_config_idx++;
if (dvr_disk_space_config_idx > dvr_disk_space_config_size)
dvr_disk_space_config_idx = 1;
Expand Down Expand Up @@ -213,6 +215,8 @@ dvr_disk_space_check()
dvr_disk_space_config_idx = 0;

dvr_disk_space_config_size = idx;

pthread_mutex_unlock(&global_lock);
}

/**
Expand All @@ -226,8 +230,10 @@ dvr_get_disk_space_update(const char *path)
if(statvfs(path, &diskdata) == -1)
return;

pthread_mutex_lock(&dvr_disk_space_mutex);
dvr_bfree = diskdata.f_bsize * (int64_t)diskdata.f_bavail;
dvr_btotal = diskdata.f_bsize * (int64_t)diskdata.f_blocks;
pthread_mutex_unlock(&dvr_disk_space_mutex);
}

/**
Expand All @@ -238,16 +244,16 @@ dvr_get_disk_space_tcb(void *opaque, int dearmed)
{
if (!dearmed) {
htsmsg_t *m = htsmsg_create_map();
pthread_mutex_lock(&dvr_disk_space_mutex);

/* update disk space from default dvr config */
dvr_get_disk_space_update((char *)opaque);
htsmsg_add_s64(m, "freediskspace", dvr_bfree);
htsmsg_add_s64(m, "totaldiskspace", dvr_btotal);

/* check free disk space for each dvr config and start cleanup if needed */
pthread_mutex_unlock(&tasklet_lock);
dvr_disk_space_check();
pthread_mutex_unlock(&dvr_disk_space_mutex);
pthread_mutex_lock(&tasklet_lock);

notify_by_msg("diskspaceUpdate", m, 0);
}
Expand Down
1 change: 1 addition & 0 deletions src/tvheadend.h
Expand Up @@ -89,6 +89,7 @@ typedef struct str_list
extern int tvheadend_running;

extern pthread_mutex_t global_lock;
extern pthread_mutex_t tasklet_lock;
extern pthread_mutex_t fork_lock;

extern int tvheadend_webui_port;
Expand Down

0 comments on commit bd86875

Please sign in to comment.