Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
rewrite timers, remove avgstat
  • Loading branch information
perexg committed Mar 4, 2016
1 parent 6ff6709 commit a6a23e1
Show file tree
Hide file tree
Showing 85 changed files with 846 additions and 824 deletions.
1 change: 0 additions & 1 deletion Makefile
Expand Up @@ -189,7 +189,6 @@ SRCS-1 = \
src/settings.c \
src/htsbuf.c \
src/trap.c \
src/avg.c \
src/htsstr.c \
src/tvhpoll.c \
src/huffman.c \
Expand Down
4 changes: 2 additions & 2 deletions src/access.c
Expand Up @@ -130,7 +130,7 @@ access_ticket_create(const char *resource, access_t *a)
at->at_access = access_copy(a);

TAILQ_INSERT_TAIL(&access_tickets, at, at_link);
gtimer_arm(&at->at_timer, access_ticket_timout, at, 60*5);
mtimer_arm_rel(&at->at_timer, access_ticket_timout, at, 60*5);

return at->at_id;
}
Expand All @@ -146,7 +146,7 @@ access_ticket_delete(const char *id)
if((at = access_ticket_find(id)) == NULL)
return -1;

gtimer_disarm(&at->at_timer);
mtimer_disarm(&at->at_timer);
access_ticket_destroy(at);

return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/access.h
Expand Up @@ -170,7 +170,7 @@ typedef struct access_ticket {

TAILQ_ENTRY(access_ticket) at_link;

gtimer_t at_timer;
mtimer_t at_timer;
char *at_resource;
access_t *at_access;
} access_ticket_t;
Expand Down
112 changes: 0 additions & 112 deletions src/avg.c

This file was deleted.

49 changes: 0 additions & 49 deletions src/avg.h

This file was deleted.

8 changes: 4 additions & 4 deletions src/bouquet.c
Expand Up @@ -28,7 +28,7 @@
typedef struct bouquet_download {
bouquet_t *bq;
download_t download;
gtimer_t timer;
mtimer_t timer;
} bouquet_download_t;

bouquet_tree_t bouquets;
Expand Down Expand Up @@ -1029,8 +1029,8 @@ bouquet_download_trigger0(void *aux)
bouquet_t *bq = bqd->bq;

download_start(&bqd->download, bq->bq_ext_url, bqd);
gtimer_arm(&bqd->timer, bouquet_download_trigger0, bqd,
MAX(1, bq->bq_ext_url_period) * 60);
mtimer_arm_rel(&bqd->timer, bouquet_download_trigger0, bqd,
mono4sec(MAX(1, bq->bq_ext_url_period) * 60));
}

static void
Expand All @@ -1047,7 +1047,7 @@ static void
bouquet_download_stop(void *aux)
{
bouquet_download_t *bqd = aux;
gtimer_disarm(&bqd->timer);
mtimer_disarm(&bqd->timer);
}

static int
Expand Down
108 changes: 108 additions & 0 deletions src/clock.h
@@ -0,0 +1,108 @@
/*
* Tvheadend - structures
* Copyright (C) 2007 Andreas Öman
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef TVHEADEND_CLOCK_H
#define TVHEADEND_CLOCK_H

#include <time.h>

#ifndef CLOCK_MONOTONIC_COARSE
#define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC
#endif

#ifdef PLATFORM_DARWIN
#define CLOCK_MONOTONIC 0
#define CLOCK_REALTIME 0

static inline int clock_gettime(int clk_id, struct timespec* t) {
struct timeval now;
int rv = gettimeofday(&now, NULL);
if (rv) return rv;
t->tv_sec = now.tv_sec;
t->tv_nsec = now.tv_usec * 1000;
return 0;
}
#endif

extern int64_t mdispatch_clock;
extern time_t gdispatch_clock;

#define MONOCLOCK_RESOLUTION 1000000LL /* microseconds */

static inline int64_t
mono4sec(int64_t sec)
{
return sec * MONOCLOCK_RESOLUTION;
}

static inline int64_t
sec4mono(int64_t monosec)
{
return monosec / MONOCLOCK_RESOLUTION;
}

static inline int64_t
mono4ms(int64_t ms)
{
return ms * (MONOCLOCK_RESOLUTION / 1000LL);
}

static inline int64_t
ms4mono(int64_t monosec)
{
return monosec / (MONOCLOCK_RESOLUTION / 1000LL);
}

static inline int64_t
getmonoclock(void)
{
struct timespec tp;

clock_gettime(CLOCK_MONOTONIC, &tp);

return tp.tv_sec * MONOCLOCK_RESOLUTION +
(tp.tv_nsec / (1000000000LL/MONOCLOCK_RESOLUTION));
}

static inline int64_t
getfastmonoclock(void)
{
struct timespec tp;

clock_gettime(CLOCK_MONOTONIC_COARSE, &tp);

return tp.tv_sec * MONOCLOCK_RESOLUTION +
(tp.tv_nsec / (1000000000LL/MONOCLOCK_RESOLUTION));
}

time_t gdispatch_clock_update(void);
int64_t mdispatch_clock_update(void);

void time_t_out_of_range_notify(int64_t val);

static inline time_t time_t_out_of_range(uint64_t val)
{
time_t r = val;
if ((int64_t)r != val) {
time_t_out_of_range_notify(val);
r = INT32_MAX;
}
return r;
}

#endif /* TVHEADEND_CLOCK_H */
12 changes: 6 additions & 6 deletions src/descrambler.h
Expand Up @@ -72,12 +72,12 @@ typedef struct th_descrambler_runtime {
uint8_t dr_key_index;
uint8_t dr_key_valid;
uint8_t dr_key_changed;
uint32_t dr_key_interval;
time_t dr_key_start;
time_t dr_key_timestamp[2];
time_t dr_ecm_start[2];
time_t dr_ecm_last_key_time;
time_t dr_last_err;
uint64_t dr_key_interval;
int64_t dr_key_start;
int64_t dr_key_timestamp[2];
int64_t dr_ecm_start[2];
int64_t dr_ecm_last_key_time;
int64_t dr_last_err;
TAILQ_HEAD(, th_descrambler_data) dr_queue;
uint32_t dr_queue_total;
tvhlog_limit_t dr_loglimit_key;
Expand Down
9 changes: 7 additions & 2 deletions src/descrambler/capmt.c
Expand Up @@ -1642,6 +1642,7 @@ capmt_thread(void *aux)
capmt_adapter_t *ca;
capmt_opaque_t *t;
int d, i, j, fatal;
int64_t mono;

tvhlog(LOG_INFO, "capmt", "%s active", capmt_name(capmt));

Expand Down Expand Up @@ -1771,8 +1772,12 @@ capmt_thread(void *aux)

tvhlog(LOG_INFO, "capmt", "%s: Automatic reconnection attempt in in %d seconds", idnode_get_title(&capmt->cac_id, NULL), d);

tvh_cond_timedwait(&capmt->capmt_cond, &capmt->capmt_mutex,
getmonoclock() + d * MONOCLOCK_RESOLUTION);
mono = mdispatch_clock + mono4sec(d);
do {
i = tvh_cond_timedwait(&capmt->capmt_cond, &capmt->capmt_mutex, mono);
if (i == ETIMEDOUT)
break;
} while (ERRNO_AGAIN(i));

pthread_mutex_unlock(&capmt->capmt_mutex);
}
Expand Down

0 comments on commit a6a23e1

Please sign in to comment.