Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
DVR: use atomic ops instead dvr_thread_mutex
  • Loading branch information
perexg committed Oct 31, 2015
1 parent 4400bb2 commit 2f7fd44
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/dvr/dvr.h
Expand Up @@ -228,7 +228,7 @@ typedef struct dvr_entry {
* Fields for recording
*/
pthread_t de_thread;
uint8_t de_thread_shutdown;
int de_thread_shutdown;

th_subscription_t *de_s;

Expand Down
24 changes: 9 additions & 15 deletions src/dvr/dvr_rec.c
Expand Up @@ -49,8 +49,6 @@
#include <sys/statvfs.h>
#endif

static pthread_mutex_t dvr_thread_mutex;

/**
*
*/
Expand Down Expand Up @@ -151,7 +149,7 @@ dvr_rec_subscribe(dvr_entry_t *de)

de->de_chain = prch;

de->de_thread_shutdown = 0;
atomic_exchange(&de->de_thread_shutdown, 0);
tvhthread_create(&de->de_thread, NULL, dvr_thread, de, "dvr");
return 0;
}
Expand All @@ -169,11 +167,7 @@ dvr_rec_unsubscribe(dvr_entry_t *de)

streaming_target_deliver(prch->prch_st, streaming_msg_create(SMT_EXIT));

pthread_mutex_unlock(&global_lock);
pthread_mutex_lock(&dvr_thread_mutex);
de->de_thread_shutdown = 1;
pthread_mutex_unlock(&dvr_thread_mutex);
pthread_mutex_lock(&global_lock);
atomic_add(&de->de_thread_shutdown, 1);

pthread_join(de->de_thread, NULL);

Expand Down Expand Up @@ -1040,12 +1034,10 @@ dvr_rec_start(dvr_entry_t *de, const streaming_start_t *ss)
/**
*
*/
static int
static inline int
dvr_thread_global_lock(dvr_entry_t *de, int *run)
{
pthread_mutex_lock(&dvr_thread_mutex);
if (de->de_thread_shutdown) {
pthread_mutex_unlock(&dvr_thread_mutex);
if (atomic_add(&de->de_thread_shutdown, 1) > 0) {
*run = 0;
return 0;
}
Expand All @@ -1056,11 +1048,11 @@ dvr_thread_global_lock(dvr_entry_t *de, int *run)
/**
*
*/
static void
static inline void
dvr_thread_global_unlock(dvr_entry_t *de)
{
pthread_mutex_unlock(&global_lock);
pthread_mutex_unlock(&dvr_thread_mutex);
atomic_dec(&de->de_thread_shutdown, 1);
}

/**
Expand Down Expand Up @@ -1492,6 +1484,9 @@ dvr_thread_epilog(dvr_entry_t *de, const char *dvr_postproc)
{
profile_chain_t *prch = de->de_chain;

if (prch == NULL)
return;

muxer_close(prch->prch_muxer);
muxer_destroy(prch->prch_muxer);
prch->prch_muxer = NULL;
Expand Down Expand Up @@ -1567,7 +1562,6 @@ void
dvr_disk_space_init(void)
{
dvr_config_t *cfg = dvr_config_find_by_name_default(NULL);
pthread_mutex_init(&dvr_thread_mutex, NULL);
pthread_mutex_init(&dvr_disk_space_mutex, NULL);
dvr_get_disk_space_update(cfg->dvr_storage);
gtimer_arm(&dvr_disk_space_timer, dvr_get_disk_space_cb, NULL, 60);
Expand Down

0 comments on commit 2f7fd44

Please sign in to comment.