MT#55283 convert time_t to int64_t

Change-Id: I9664249782355f7363a46bafcca6504415585875
pull/1855/merge
Richard Fuchs 1 week ago
parent e097ee3701
commit a4bd720105

@ -1883,12 +1883,12 @@ static void cli_incoming_media_list_files(str *instr, struct cli_writer *cw, con
str_q list = media_player_list_files();
while (list.head) {
str *name = t_queue_pop_head(&list);
time_t atime, mtime;
int64_t atime, mtime;
if (media_player_get_file_times(name, &mtime, &atime))
cw->cw_printf(cw, STR_FORMAT ", loaded %" PRId64 " s ago, last used %" PRId64 " s ago\n",
STR_FMT(name),
timeval_from_us(rtpe_now).tv_sec - mtime,
timeval_from_us(rtpe_now).tv_sec - atime);
(rtpe_now - mtime) / 1000000L,
(rtpe_now - atime) / 1000000L);
str_free(name);
}
}
@ -1898,11 +1898,11 @@ static void cli_incoming_media_list_dbs(str *instr, struct cli_writer *cw, const
while (list.head) {
void *idp = g_queue_pop_head(&list);
unsigned long long id = GPOINTER_TO_UINT(idp);
time_t atime, mtime;
int64_t atime, mtime;
if (media_player_get_db_times(id, &mtime, &atime))
cw->cw_printf(cw, "%llu, loaded %" PRId64 " s ago, last used %" PRId64 " s ago\n", id,
timeval_from_us(rtpe_now).tv_sec - mtime,
timeval_from_us(rtpe_now).tv_sec - atime);
(rtpe_now - mtime) / 1000000L,
(rtpe_now - atime) / 1000000L);
}
}
@ -2068,11 +2068,11 @@ static void cli_incoming_media_list_caches(str *instr, struct cli_writer *cw, co
while (list.head) {
void *idp = g_queue_pop_head(&list);
unsigned long long id = GPOINTER_TO_UINT(idp);
time_t atime, mtime;
int64_t atime, mtime;
if (media_player_get_cache_times(id, &mtime, &atime))
cw->cw_printf(cw, "%llu, loaded %lu s ago, last used %lu s ago\n", id,
(long) timeval_from_us(rtpe_now).tv_sec - mtime,
(long) timeval_from_us(rtpe_now).tv_sec - atime);
cw->cw_printf(cw, "%llu, loaded %" PRId64 " s ago, last used %" PRId64 " s ago\n", id,
(rtpe_now - mtime) / 1000000L,
(rtpe_now - atime) / 1000000L);
}
}

@ -98,8 +98,8 @@ struct media_player_media_file {
str_list *str_link;
GList *gen_link;
};
time_t mtime;
time_t atime;
int64_t mtime_us;
int64_t atime_us;
};
static mutex_t media_player_cache_lock = MUTEX_STATIC_INIT;
@ -1253,7 +1253,7 @@ static struct media_player_media_file *media_player_media_file_new(str blob) {
fo->blob = blob;
fo->blob.dup = call_ref; // string is allocated by reference on `fo`
RTPE_GAUGE_ADD(media_cache, blob.len);
fo->atime = fo->mtime = timeval_from_us(rtpe_now).tv_sec;
fo->atime_us = fo->mtime_us = rtpe_now;
return fo;
}
@ -1302,7 +1302,7 @@ static struct media_player_media_file *media_player_media_files_get_only(const s
return NULL;
obj_hold(fo);
fo->atime = timeval_from_us(rtpe_now).tv_sec;
fo->atime_us = rtpe_now;
}
return fo;
@ -1321,7 +1321,7 @@ static struct media_player_media_file *media_player_db_id_get_only(unsigned long
return NULL;
obj_hold(fo);
fo->atime = timeval_from_us(rtpe_now).tv_sec;
fo->atime_us = rtpe_now;
}
return fo;
@ -2267,7 +2267,7 @@ bool media_player_reload_file(str *name) {
if (fail)
ilog(LOG_WARN, "Failed to stat() media file '" STR_FORMAT "': %s",
STR_FMT(name), strerror(errno));
else if (sb.st_mtim.tv_sec > fo->mtime) {
else if (timespec_us(sb.st_mtim) > fo->mtime_us) {
__auto_type fonew = media_player_media_file_read_c(file_s);
if (fonew) {
// got a new entry. swap it out against the old one
@ -2518,28 +2518,28 @@ GQueue media_player_list_dbs(void) {
return ret;
}
bool media_player_get_file_times(const str *s, time_t *mtime, time_t *atime) {
bool media_player_get_file_times(const str *s, int64_t *mtime, int64_t *atime) {
#ifdef WITH_TRANSCODING
LOCK(&media_player_media_files_lock);
__auto_type fo = t_hash_table_lookup(media_player_media_files, s);
if (!fo)
return false;
*mtime = fo->mtime;
*atime = fo->atime;
*mtime = fo->mtime_us / 1000000L;
*atime = fo->atime_us / 1000000L;
return true;
#else
return false;
#endif
}
bool media_player_get_db_times(unsigned long long id, time_t *mtime, time_t *atime) {
bool media_player_get_db_times(unsigned long long id, int64_t *mtime, int64_t *atime) {
#ifdef WITH_TRANSCODING
LOCK(&media_player_db_media_lock);
__auto_type fo = t_hash_table_lookup(media_player_db_media, GUINT_TO_POINTER(id));
if (!fo)
return false;
*mtime = fo->mtime;
*atime = fo->atime;
*mtime = fo->mtime_us / 1000000L;
*atime = fo->atime_us / 1000000L;
return true;
#else
return false;
@ -2587,7 +2587,7 @@ GQueue media_player_list_caches(void) {
return ret;
}
bool media_player_get_cache_times(unsigned long long id, time_t *mtime, time_t *atime) {
bool media_player_get_cache_times(unsigned long long id, int64_t *mtime, int64_t *atime) {
#ifdef WITH_TRANSCODING
g_autoptr(char) fn = media_player_make_cache_entry_name(id);
struct stat sb;
@ -2764,7 +2764,7 @@ static void media_player_expire_files(void) {
if (rtpe_config.media_expire <= 0)
return;
time_t limit = timeval_from_us(rtpe_now).tv_sec - rtpe_config.media_expire;
int64_t limit = rtpe_now - rtpe_config.media_expire * 1000000L; // XXX scale to micro
unsigned int num = 0;
{
@ -2778,7 +2778,7 @@ static void media_player_expire_files(void) {
__auto_type fo = t_hash_table_lookup(media_player_media_files, l->data);
if (!fo)
continue;
if (fo->atime >= limit)
if (fo->atime_us >= limit)
continue;
name = str_dup_str(l->data);
}
@ -2795,7 +2795,7 @@ static void media_player_expire_dbs(void) {
if (rtpe_config.db_expire <= 0)
return;
time_t limit = timeval_from_us(rtpe_now).tv_sec - rtpe_config.db_expire;
int64_t limit = rtpe_now - rtpe_config.db_expire * 1000000L; // XXX scale to micro
unsigned int num = 0;
{
@ -2809,7 +2809,7 @@ static void media_player_expire_dbs(void) {
__auto_type fo = t_hash_table_lookup(media_player_db_media, l->data);
if (!fo)
continue;
if (fo->atime >= limit)
if (fo->atime_us >= limit)
continue;
id = GPOINTER_TO_UINT(l->data);
}
@ -2823,10 +2823,10 @@ static void media_player_expire_dbs(void) {
}
static void media_player_expire_cache_entry(unsigned long long id, unsigned int *num) {
time_t mtime, atime;
int64_t mtime, atime;
if (!media_player_get_cache_times(id, &mtime, &atime))
return;
time_t limit = timeval_from_us(rtpe_now).tv_sec - rtpe_config.db_expire;
int64_t limit = rtpe_now - rtpe_config.db_expire * 1000000L; // XXX scale to micro
if (atime >= limit)
return;
if (media_player_evict_cache(id))

@ -167,9 +167,9 @@ unsigned int media_player_evict_db_medias(void);
str_q media_player_list_files(void);
GQueue media_player_list_dbs(void);
GQueue media_player_list_caches(void);
bool media_player_get_file_times(const str *, time_t *mtime, time_t *atime);
bool media_player_get_db_times(unsigned long long, time_t *mtime, time_t *atime);
bool media_player_get_cache_times(unsigned long long, time_t *mtime, time_t *atime);
bool media_player_get_file_times(const str *, int64_t *mtime, int64_t *atime);
bool media_player_get_db_times(unsigned long long, int64_t *mtime, int64_t *atime);
bool media_player_get_cache_times(unsigned long long, int64_t *mtime, int64_t *atime);
bool media_player_evict_cache(unsigned long long);
unsigned int media_player_evict_caches(void);
bool media_player_preload_cache(char **);

@ -347,7 +347,10 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(rwlock_w_lock_t, rwlock_ptr_unlock_w)
__attribute__((warn_unused_result))
INLINE int64_t timeval_us(const struct timeval t) {
return ((int64_t) t.tv_sec * 1000000LL) + t.tv_usec;
return ((int64_t) t.tv_sec * 1000000L) + t.tv_usec;
}
INLINE int64_t timespec_us(const struct timespec t) {
return ((int64_t) t.tv_sec * 1000000L) + t.tv_nsec / 1000L;
}
__attribute__((warn_unused_result))
INLINE int64_t now_us(void) {

Loading…
Cancel
Save