Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
timeshift: remove buffering_mutex - state_mutex protection is fine
  • Loading branch information
perexg committed Dec 30, 2015
1 parent 0f069c7 commit 41279ef
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
7 changes: 1 addition & 6 deletions src/timeshift.c
Expand Up @@ -289,7 +289,7 @@ timeshift_packets_clone( timeshift_t *ts, struct streaming_message_queue *dst )
struct streaming_message_queue *sq, *backlogs;
int i;

lock_assert(&ts->buffering_mutex);
lock_assert(&ts->state_mutex);

/* init temporary queues */
backlogs = alloca(ts->backlog_max * sizeof(*backlogs));
Expand Down Expand Up @@ -340,8 +340,6 @@ static void timeshift_input
if (type == SMT_START && ts->state == TS_INIT)
ts->state = TS_LIVE;

pthread_mutex_lock(&ts->buffering_mutex);

/* Change PTS/DTS offsets */
if (ts->packet_mode && ts->start_pts && type == SMT_PACKET) {
pkt2 = pkt_copy_shallow(pkt);
Expand Down Expand Up @@ -410,8 +408,6 @@ static void timeshift_input
}
pktcont:

pthread_mutex_unlock(&ts->buffering_mutex);

/* Exit/Stop */
if (exit) {
timeshift_write_exit(ts->rd_pipe.wr);
Expand Down Expand Up @@ -501,7 +497,6 @@ streaming_target_t *timeshift_create
TAILQ_INIT(&ts->backlog[i]);
pthread_mutex_init(&ts->rdwr_mutex, NULL);
pthread_mutex_init(&ts->state_mutex, NULL);
pthread_mutex_init(&ts->buffering_mutex, NULL);

/* Initialise output */
tvh_pipe(O_NONBLOCK, &ts->rd_pipe);
Expand Down
1 change: 0 additions & 1 deletion src/timeshift/private.h
Expand Up @@ -97,7 +97,6 @@ typedef struct timeshift {
int64_t ref_time; ///< Start time in us (monoclock)
struct streaming_message_queue backlog[TIMESHIFT_BACKLOG_MAX]; ///< Queued packets for time sorting
int backlog_max;///< Maximum component index in backlog
pthread_mutex_t buffering_mutex;///< Protect backlog / write queues

enum {
TS_INIT,
Expand Down
12 changes: 4 additions & 8 deletions src/timeshift/timeshift_reader.c
Expand Up @@ -757,10 +757,12 @@ void *timeshift_reader ( void *p )
end = _timeshift_do_skip(ts, skip_time, last_time, &cur_file, &tsi);
if (tsi) {
pause_time = tsi->time;
tvhtrace("timeshift", "ts %d skip set pause_time %"PRId64" last_time %"PRId64,
ts->id, pause_time, last_time);

/* Adjust time */
if (mono_play_time != mono_now)
tvhtrace("timeshift", "update play time skip - %"PRId64, mono_now);
tvhtrace("timeshift", "ts %d update play time skip - %"PRId64, ts->id, mono_now);
mono_play_time = mono_now;

/* Clear existing packet */
Expand Down Expand Up @@ -898,20 +900,14 @@ void *timeshift_reader ( void *p )
ctrl = NULL;
tvhtrace("timeshift", "reader - set TS_LIVE");

/* Critical section - protect write / backlog queues */
pthread_mutex_lock(&ts->buffering_mutex);

/* Flush timeshift buffer to live */
if (_timeshift_flush_to_live(ts, &cur_file, &sm, &wait) == -1) {
pthread_mutex_unlock(&ts->buffering_mutex);
if (_timeshift_flush_to_live(ts, &cur_file, &sm, &wait) == -1)
break;
}

/* Flush write / backlog queues */
_timeshift_write_queues(ts);

ts->state = TS_LIVE;
pthread_mutex_unlock(&ts->buffering_mutex);

/* Close file (if open) */
if (cur_file && cur_file->rfd >= 0) {
Expand Down

0 comments on commit 41279ef

Please sign in to comment.