From: Jaroslav Kysela Date: Thu, 3 Dec 2015 08:08:19 +0000 (+0100) Subject: DVR: fix locking in dvr_get_disk_space_tcb X-Git-Tag: v4.2.1~1396 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bd868755812f2c1bd6245bc3eaec00957e8d8186;p=thirdparty%2Ftvheadend.git DVR: fix locking in dvr_get_disk_space_tcb --- diff --git a/src/dvr/dvr_vfsmgr.c b/src/dvr/dvr_vfsmgr.c index 7d5a1c464..86ae48f13 100644 --- a/src/dvr/dvr_vfsmgr.c +++ b/src/dvr/dvr_vfsmgr.c @@ -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; @@ -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); } /** @@ -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); } /** @@ -238,7 +244,6 @@ 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); @@ -246,8 +251,9 @@ dvr_get_disk_space_tcb(void *opaque, int dearmed) 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); } diff --git a/src/tvheadend.h b/src/tvheadend.h index a652069f2..80b7ca3e8 100644 --- a/src/tvheadend.h +++ b/src/tvheadend.h @@ -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;