Browse Source

MT#55283 convert timerthread to int64_t

Change-Id: Ia7bdb7538428edef1ff83d7bd8f6116d5e618510
pull/1938/head
Richard Fuchs 8 months ago
parent
commit
20ffa4f780
10 changed files with 102 additions and 113 deletions
  1. +2
    -2
      daemon/audio_player.c
  2. +23
    -24
      daemon/codec.c
  3. +4
    -4
      daemon/ice.c
  4. +10
    -10
      daemon/jitter_buffer.c
  5. +3
    -3
      daemon/media_player.c
  6. +2
    -2
      daemon/t38.c
  7. +49
    -26
      daemon/timerthread.c
  8. +6
    -6
      include/timerthread.h
  9. +0
    -28
      lib/auxlib.c
  10. +3
    -8
      lib/auxlib.h

+ 2
- 2
daemon/audio_player.c View File

@ -36,7 +36,7 @@ static bool audio_player_run(struct media_player *mp) {
if (!size) {
// error or not active: just reschedule
mp->next_run += ap->ptime_us;
timerthread_obj_schedule_abs(&mp->tt_obj, timeval_from_us(mp->next_run));
timerthread_obj_schedule_abs(&mp->tt_obj, mp->next_run);
return false;
}
buf = g_alloca(size);
@ -171,7 +171,7 @@ void audio_player_start(struct call_media *m) {
mp->next_run = rtpe_now;
mp->next_run += ap->ptime_us;
timerthread_obj_schedule_abs(&mp->tt_obj, timeval_from_us(mp->next_run));
timerthread_obj_schedule_abs(&mp->tt_obj, mp->next_run);
}


+ 23
- 24
daemon/codec.c View File

@ -1289,7 +1289,7 @@ static void __codec_rtcp_timer_schedule(struct call_media *media) {
}
rt->ct.next += rtpe_config.rtcp_interval * 1000 + (ssl_random() % 1000000); // XXX scale to micro
timerthread_obj_schedule_abs(&rt->ct.tt_obj, timeval_from_us(rt->ct.next));
timerthread_obj_schedule_abs(&rt->ct.tt_obj, rt->ct.next);
}
// no lock held
static void __rtcp_timer_run(struct codec_timer *ct) {
@ -1979,7 +1979,7 @@ static void __mqtt_timer_run_summary(struct codec_timer *ct) {
}
static void __codec_mqtt_timer_schedule(struct mqtt_timer *mqt) {
mqt->ct.next += rtpe_config.mqtt_publish_interval * 1000; // XXX scale to micro
timerthread_obj_schedule_abs(&mqt->ct.tt_obj, timeval_from_us(mqt->ct.next));
timerthread_obj_schedule_abs(&mqt->ct.tt_obj, mqt->ct.next);
}
// master lock held in W
void mqtt_timer_start(struct mqtt_timer **mqtp, call_t *call, struct call_media *media) {
@ -2409,7 +2409,7 @@ void codec_output_rtp(struct media_packet *mp, struct codec_scheduler *csch,
// passthrough forwarding (or are handling some other prepared RTP stream) and want
// to send the packet out immediately.
if (seq != -1) {
p->ttq_entry.when = timeval_from_us(rtpe_now);
p->ttq_entry.when = rtpe_now;
goto send;
}
@ -2417,55 +2417,54 @@ void codec_output_rtp(struct media_packet *mp, struct codec_scheduler *csch,
// determine scheduled time to send
if (csch->first_send && handler->dest_pt.clock_rate) {
// scale first_send from first_send_ts to ts
p->ttq_entry.when = timeval_from_us(csch->first_send);
p->ttq_entry.when = csch->first_send;
uint32_t ts_diff = (uint32_t) ts - (uint32_t) csch->first_send_ts; // allow for wrap-around
ts_diff += ts_delay;
ts_diff_us = ts_diff * 1000000LL / handler->dest_pt.clock_rate;
p->ttq_entry.when = timeval_add_usec(p->ttq_entry.when, ts_diff_us);
p->ttq_entry.when += ts_diff_us;
// how far in the future is this?
ts_diff_us = timeval_diff(p->ttq_entry.when, timeval_from_us(rtpe_now));
ts_diff_us = p->ttq_entry.when - rtpe_now;
if (ts_diff_us > 1000000 || ts_diff_us < -1000000) // more than one second, can't be right
csch->first_send = 0; // fix it up below
}
if (!csch->first_send || !p->ttq_entry.when.tv_sec) {
p->ttq_entry.when = timeval_from_us(rtpe_now);
if (!csch->first_send || !p->ttq_entry.when) {
p->ttq_entry.when = rtpe_now;
csch->first_send = rtpe_now;
csch->first_send_ts = ts;
}
ts_diff_us = timeval_diff(p->ttq_entry.when, timeval_from_us(rtpe_now));
ts_diff_us = p->ttq_entry.when - rtpe_now;
csch->output_skew = csch->output_skew * 15 / 16 + ts_diff_us / 16;
if (csch->output_skew > 50000 && ts_diff_us > 10000) { // arbitrary value, 50 ms, 10 ms shift
ilogs(transcoding, LOG_DEBUG, "Steady clock skew of %li.%01li ms detected, shifting send timer back by 10 ms",
csch->output_skew / 1000,
(csch->output_skew % 1000) / 100);
p->ttq_entry.when = timeval_add_usec(p->ttq_entry.when, -10000);
p->ttq_entry.when -= 10000;
csch->output_skew -= 10000;
csch->first_send_ts += handler->dest_pt.clock_rate / 100;
ts_diff_us = timeval_diff(p->ttq_entry.when, timeval_from_us(rtpe_now));
ts_diff_us = p->ttq_entry.when - rtpe_now;
}
else if (ts_diff_us < 0) {
ts_diff_us *= -1;
ilogs(transcoding, LOG_DEBUG, "Negative clock skew of %" PRId64 ".%01" PRId64 " ms detected, shifting send timer forward",
ts_diff_us / 1000,
(ts_diff_us % 1000) / 100);
p->ttq_entry.when = timeval_add_usec(p->ttq_entry.when, ts_diff_us);
p->ttq_entry.when += ts_diff_us;
csch->output_skew = 0;
csch->first_send_ts -= (long long) handler->dest_pt.clock_rate * ts_diff_us / 1000000;
ts_diff_us = timeval_diff(p->ttq_entry.when, timeval_from_us(rtpe_now)); // should be 0 now
csch->first_send_ts -= (int64_t) handler->dest_pt.clock_rate * ts_diff_us / 1000000;
ts_diff_us = p->ttq_entry.when - rtpe_now; // should be 0 now
}
send:
ilogs(transcoding, LOG_DEBUG, "Scheduling to send RTP packet (seq %u TS %lu) in %s%lli.%01lli ms (at %lu.%06lu)",
ilogs(transcoding, LOG_DEBUG, "Scheduling to send RTP packet (seq %u TS %lu) in %" PRId64 ".%01ld ms (at %" PRId64" .%06" PRId64" )",
ntohs(rh->seq_num),
ts,
ts_diff_us < 0 ? "-" : "",
llabs(ts_diff_us / 1000),
llabs((ts_diff_us % 1000) / 100),
(long unsigned) p->ttq_entry.when.tv_sec,
(long unsigned) p->ttq_entry.when.tv_usec);
ts_diff_us / 1000,
labs((ts_diff_us % 1000) / 100),
p->ttq_entry.when / 1000000,
p->ttq_entry.when % 1000000);
t_queue_push_tail_link(&mp->packets_out, &p->link);
}
@ -3141,7 +3140,7 @@ static void __delay_buffer_schedule(struct delay_buffer *dbuf) {
int64_t to_run = dframe->mp.tv;
to_run += dbuf->delay * 1000; // XXX scale up only once
dbuf->ct.next = to_run;
timerthread_obj_schedule_abs(&dbuf->ct.tt_obj, timeval_from_us(dbuf->ct.next));
timerthread_obj_schedule_abs(&dbuf->ct.tt_obj, dbuf->ct.next);
}
static bool __buffer_delay_do_direct(struct delay_buffer *dbuf) {
@ -3327,7 +3326,7 @@ static bool __buffer_dtx(struct dtx_buffer *dtxb, struct codec_ssrc_handler *dec
dtxb->ssrc = mp->ssrc_in->parent->h.ssrc;
dtxb->ct.next = mp->tv;
dtxb->ct.next += rtpe_config.dtx_delay * 1000; // XXX scale to micro
timerthread_obj_schedule_abs(&dtxb->ct.tt_obj, timeval_from_us(dtxb->ct.next));
timerthread_obj_schedule_abs(&dtxb->ct.tt_obj, dtxb->ct.next);
}
// packet now consumed if there was one
@ -3956,7 +3955,7 @@ static void __dtx_send_later(struct codec_timer *ct) {
// schedule next run
dtxb->ct.next += dtxb->ptime * 1000; // XXX scale to micro
timerthread_obj_schedule_abs(&dtxb->ct.tt_obj, timeval_from_us(dtxb->ct.next));
timerthread_obj_schedule_abs(&dtxb->ct.tt_obj, dtxb->ct.next);
mutex_unlock(&dtxb->lock);
@ -6246,7 +6245,7 @@ void codec_timer_callback(call_t *c, void (*func)(call_t *, codec_timer_callback
cb->ct.timer_func = __codec_timer_callback_fire;
cb->ct.next = rtpe_now;
cb->ct.next += delay;
timerthread_obj_schedule_abs(&cb->ct.tt_obj, timeval_from_us(cb->ct.next));
timerthread_obj_schedule_abs(&cb->ct.tt_obj, cb->ct.next);
}
static void codec_timers_run(void *p) {


+ 4
- 4
daemon/ice.c View File

@ -420,7 +420,7 @@ static void __ice_reset(struct ice_agent *ag) {
__ice_agent_free_components(ag);
ZERO(ag->active_components);
ag->start_nominating = 0;
ZERO(ag->tt_obj.last_run);
ag->tt_obj.last_run = 0;
__ice_agent_initialize(ag);
}
@ -682,13 +682,13 @@ static void __agent_schedule_abs(struct ice_agent *ag, int64_t tv) {
struct timerthread_thread *tt = ag->tt_obj.thread;
mutex_lock(&tt->lock);
if (ag->tt_obj.last_run.tv_sec) {
if (ag->tt_obj.last_run) {
/* make sure we don't run more often than we should */
diff = nxt - timeval_us(ag->tt_obj.last_run);
diff = nxt - ag->tt_obj.last_run;
if (diff < TIMER_RUN_INTERVAL * 1000)
nxt += TIMER_RUN_INTERVAL * 1000 - diff;
}
timerthread_obj_schedule_abs_nl(&ag->tt_obj, timeval_from_us(nxt));
timerthread_obj_schedule_abs_nl(&ag->tt_obj, nxt);
mutex_unlock(&tt->lock);
}
static void __agent_deschedule(struct ice_agent *ag) {


+ 10
- 10
daemon/jitter_buffer.c View File

@ -153,33 +153,33 @@ static int queue_packet(struct media_packet *mp, struct jb_packet *p) {
jb->rtptime_delta = ts_diff/seq_diff;
}
p->ttq_entry.when = timeval_from_us(jb->first_send);
p->ttq_entry.when = jb->first_send;
int64_t ts_diff_us =
(ts_diff + (jb->rtptime_delta * jb->buffer_len))* 1000000 / clockrate;
ts_diff_us += jb->clock_drift_val * seq_diff;
ts_diff_us += jb->dtmf_mult_factor * DELAY_FACTOR;
p->ttq_entry.when = timeval_add_usec(p->ttq_entry.when, ts_diff_us);
p->ttq_entry.when += ts_diff_us;
ts_diff_us = timeval_diff(p->ttq_entry.when, timeval_from_us(rtpe_now));
ts_diff_us = p->ttq_entry.when - rtpe_now;
if (ts_diff_us > 1000000) { // more than one second, can't be right
ilog(LOG_DEBUG, "Partial reset due to timestamp");
jb->first_send = 0;
p->ttq_entry.when = timeval_from_us(rtpe_now);
p->ttq_entry.when = rtpe_now;
}
if(jb->prev_seq_ts == 0)
jb->prev_seq_ts = rtpe_now;
if((timeval_diff(p->ttq_entry.when, timeval_from_us(jb->prev_seq_ts)) < 0) && (curr_seq > jb->prev_seq)) {
p->ttq_entry.when = timeval_from_us(jb->prev_seq_ts);
p->ttq_entry.when = timeval_add_usec(p->ttq_entry.when, DELAY_FACTOR);
if((p->ttq_entry.when - jb->prev_seq_ts < 0) && (curr_seq > jb->prev_seq)) {
p->ttq_entry.when = jb->prev_seq_ts;
p->ttq_entry.when += DELAY_FACTOR;
}
if(timeval_diff(p->ttq_entry.when, timeval_from_us(jb->prev_seq_ts)) > 0) {
jb->prev_seq_ts = timeval_us(p->ttq_entry.when);
if(p->ttq_entry.when - jb->prev_seq_ts > 0) {
jb->prev_seq_ts = p->ttq_entry.when;
jb->prev_seq = curr_seq;
}
@ -306,7 +306,7 @@ int buffer_packet(struct media_packet *mp, const str *s) {
goto end_unlock;
}
jb->first_send = rtpe_now;
p->ttq_entry.when = timeval_from_us(rtpe_now);
p->ttq_entry.when = rtpe_now;
jb->first_send_ts = ts;
jb->first_seq = ntohs(mp->rtp->seq_num);
jb->ssrc = ntohl(mp->rtp->ssrc);


+ 3
- 3
daemon/media_player.c View File

@ -579,7 +579,7 @@ retry:;
// schedule our next run
mp->next_run += us_dur;
timerthread_obj_schedule_abs(&mp->tt_obj, timeval_from_us(mp->next_run));
timerthread_obj_schedule_abs(&mp->tt_obj, mp->next_run);
return false;
}
@ -1047,7 +1047,7 @@ void media_player_add_packet(struct media_player *mp, char *buf, size_t len,
struct codec_packet *p = packet.packets_out.head->data;
if (p->rtp) {
mp->sync_ts = ntohl(p->rtp->timestamp);
mp->sync_ts_tv = timeval_us(p->ttq_entry.when);
mp->sync_ts_tv = p->ttq_entry.when;
}
}
@ -1059,7 +1059,7 @@ void media_player_add_packet(struct media_player *mp, char *buf, size_t len,
mutex_unlock(&mp->sink->out_lock);
mp->next_run += us_dur;
timerthread_obj_schedule_abs(&mp->tt_obj, timeval_from_us(mp->next_run));
timerthread_obj_schedule_abs(&mp->tt_obj, mp->next_run);
}
static int media_player_find_file_begin(struct media_player *mp) {


+ 2
- 2
daemon/t38.c View File

@ -274,7 +274,7 @@ static bool t38_pcm_player(struct media_player *mp) {
ilog(LOG_DEBUG, "No T.38 PCM samples generated");
// use a fixed interval of 10 ms
mp->next_run += 10000;
timerthread_obj_schedule_abs(&mp->tt_obj, timeval_from_us(mp->next_run));
timerthread_obj_schedule_abs(&mp->tt_obj, mp->next_run);
mutex_unlock(&tg->lock);
return false;
}
@ -505,7 +505,7 @@ void t38_gateway_start(struct t38_gateway *tg, str_case_value_ht codec_set) {
// start off PCM player
tg->pcm_player->next_run = rtpe_now;
timerthread_obj_schedule_abs(&tg->pcm_player->tt_obj, timeval_from_us(tg->pcm_player->next_run));
timerthread_obj_schedule_abs(&tg->pcm_player->tt_obj, tg->pcm_player->next_run);
}


+ 49
- 26
daemon/timerthread.c View File

@ -9,7 +9,22 @@
static int tt_obj_cmp(const void *a, const void *b) {
const struct timerthread_obj *A = a, *B = b;
return timeval_cmp_ptr(&A->next_check, &B->next_check);
// zero timevals go last
if (A->next_check == 0 && B->next_check != 0)
return 1;
if (B->next_check == 0 && A->next_check != 0)
return -1;
// earlier timevals go first
if (A->next_check < B->next_check)
return -1;
if (A->next_check > B->next_check)
return 1;
// rest sorted by pointer
if (A < B)
return -1;
if (A > B)
return 1;
return 0;
}
static void timerthread_thread_init(struct timerthread_thread *tt, struct timerthread *parent) {
@ -78,7 +93,7 @@ static void timerthread_run(void *p) {
}
// scheduled to run? if not, then we remember this object/reference and go to sleep
sleeptime = timeval_diff(tt_obj->next_check, timeval_from_us(rtpe_now));
sleeptime = tt_obj->next_check - rtpe_now;
if (sleeptime > accuracy) {
tt->obj = tt_obj;
@ -86,10 +101,10 @@ static void timerthread_run(void *p) {
}
// pretend we're running exactly at the scheduled time
rtpe_now = timeval_us(tt_obj->next_check);
ZERO(tt_obj->next_check);
tt_obj->last_run = timeval_from_us(rtpe_now);
ZERO(tt->next_wake);
rtpe_now = tt_obj->next_check;
tt_obj->next_check = 0;
tt_obj->last_run = rtpe_now;
tt->next_wake = 0;
tt->obj = NULL;
mutex_unlock(&tt->lock);
@ -107,10 +122,10 @@ sleep:
/* figure out how long we should sleep */
sleeptime = MIN(10000000, sleeptime);
sleep_now:;
struct timeval tv = timeval_from_us(rtpe_now);
tv = timeval_add_usec(tv, sleeptime);
int64_t tv = rtpe_now;
tv += sleeptime;
tt->next_wake = tv;
cond_timedwait(&tt->cond, &tt->lock, &tv);
cond_timedwait(&tt->cond, &tt->lock, tv);
}
mutex_unlock(&tt->lock);
@ -122,7 +137,7 @@ void timerthread_launch(struct timerthread *tt, const char *scheduler, int prio,
thread_create_detach_prio(timerthread_run, &tt->threads[i], scheduler, prio, name);
}
void timerthread_obj_schedule_abs_nl(struct timerthread_obj *tt_obj, const struct timeval tv) {
void timerthread_obj_schedule_abs_nl(struct timerthread_obj *tt_obj, int64_t tv) {
if (!tt_obj)
return;
struct timerthread_thread *tt = tt_obj->thread;
@ -130,7 +145,7 @@ void timerthread_obj_schedule_abs_nl(struct timerthread_obj *tt_obj, const struc
//ilog(LOG_DEBUG, "scheduling timer object at %llu.%06lu", (unsigned long long) tv->tv_sec,
//(unsigned long) tv->tv_usec);
if (tt_obj->next_check.tv_sec && timeval_cmp(tt_obj->next_check, tv) <= 0)
if (tt_obj->next_check && timeval_cmp(timeval_from_us(tt_obj->next_check), timeval_from_us(tv)) <= 0)
return; /* already scheduled sooner */
if (!g_tree_remove(tt->tree, tt_obj)) {
if (tt->obj == tt_obj)
@ -141,7 +156,7 @@ void timerthread_obj_schedule_abs_nl(struct timerthread_obj *tt_obj, const struc
tt_obj->next_check = tv;
g_tree_insert(tt->tree, tt_obj, tt_obj);
// need to wake the thread?
if (tt->next_wake.tv_sec && timeval_cmp(tv, tt->next_wake) < 0) {
if (tt->next_wake && timeval_cmp(timeval_from_us(tv), timeval_from_us(tt->next_wake)) < 0) {
// make sure we can get picked first: move pre-picked object back into tree
if (tt->obj && tt->obj != tt_obj) {
g_tree_insert(tt->tree, tt->obj, tt->obj);
@ -160,7 +175,7 @@ void timerthread_obj_deschedule(struct timerthread_obj *tt_obj) {
return;
mutex_lock(&tt->lock);
if (!tt_obj->next_check.tv_sec)
if (!tt_obj->next_check)
goto nope; /* already descheduled */
gboolean ret = g_tree_remove(tt->tree, tt_obj);
if (!ret) {
@ -179,8 +194,8 @@ nope:
static int timerthread_queue_run_one(struct timerthread_queue *ttq,
struct timerthread_queue_entry *ttqe,
void (*run_func)(struct timerthread_queue *, void *)) {
if (ttqe->when.tv_sec && timeval_cmp(ttqe->when, timeval_from_us(rtpe_now)) > 0) {
if(timeval_diff(ttqe->when, timeval_from_us(rtpe_now)) > 1000) // not to queue packet less than 1ms
if (ttqe->when && timeval_cmp(timeval_from_us(ttqe->when), timeval_from_us(rtpe_now)) > 0) {
if (ttqe->when - rtpe_now > 1000) // not to queue packet less than 1ms
return -1; // not yet
}
run_func(ttq, ttqe);
@ -193,14 +208,14 @@ void timerthread_queue_run(void *ptr) {
//ilog(LOG_DEBUG, "running timerthread_queue");
struct timeval next_send = {0,};
int64_t next_send = 0;
mutex_lock(&ttq->lock);
while (g_tree_nnodes(ttq->entries)) {
struct timerthread_queue_entry *ttqe = rtpe_g_tree_first(ttq->entries);
assert(ttqe != NULL);
g_tree_remove(ttq->entries, ttqe);
g_tree_remove(ttq->entries, ttqe); // XXX use g_tree_remove_node if ever available
mutex_unlock(&ttq->lock);
@ -218,7 +233,7 @@ void timerthread_queue_run(void *ptr) {
mutex_unlock(&ttq->lock);
if (next_send.tv_sec)
if (next_send)
timerthread_obj_schedule_abs(&ttq->tt_obj, next_send);
}
@ -241,14 +256,22 @@ static void __timerthread_queue_free(void *p) {
static int ttqe_compare(const void *a, const void *b) {
const struct timerthread_queue_entry *t1 = a;
const struct timerthread_queue_entry *t2 = b;
int ret = timeval_cmp_zero(&t1->when, &t2->when);
if (ret)
return ret;
// zero timevals go last
if (t1->when == 0 && t2->when != 0)
return 1;
if (t2->when == 0 && t1->when != 0)
return -1;
// earlier timevals go first
if (t1->when < t2->when)
return -1;
if (t1->when > t2->when)
return 1;
// rest sorted by index
if (t1->idx < t2->idx)
return -1;
if (t1->idx == t2->idx)
return 0;
return 1;
if (t1->idx > t2->idx)
return 1;
return 0;
}
void *timerthread_queue_new(const char *type, size_t size,
@ -277,7 +300,7 @@ int __ttqe_find_last_idx(const void *a, const void *b) {
const struct timerthread_queue_entry *ttqe_a = a;
void **data = (void **) b;
const struct timerthread_queue_entry *ttqe_b = data[0];
int ret = timeval_cmp(ttqe_b->when, ttqe_a->when);
int ret = timeval_cmp(timeval_from_us(ttqe_b->when), timeval_from_us(ttqe_a->when));
if (ret)
return ret;
// same timestamp. track highest seen idx
@ -322,7 +345,7 @@ void timerthread_queue_push(struct timerthread_queue *ttq, struct timerthread_qu
}
// this hands over ownership of cp, so we must copy the timeval out
struct timeval tv_send = ttqe->when;
int64_t tv_send = ttqe->when;
g_tree_insert(ttq->entries, ttqe, ttqe);
struct timerthread_queue_entry *first_ttqe = rtpe_g_tree_first(ttq->entries);
mutex_unlock(&ttq->lock);


+ 6
- 6
include/timerthread.h View File

@ -14,7 +14,7 @@ struct timerthread_thread {
GTree *tree; // XXX investigate other structures
mutex_t lock;
cond_t cond;
struct timeval next_wake;
int64_t next_wake;
struct timerthread_obj *obj;
};
@ -30,8 +30,8 @@ struct timerthread_obj {
struct timerthread *tt;
struct timerthread_thread *thread; // set once and then static
struct timeval next_check; /* protected by ->lock */
struct timeval last_run; /* ditto */
int64_t next_check; /* protected by ->lock */
int64_t last_run; /* ditto */
};
struct timerthread_queue {
@ -46,7 +46,7 @@ struct timerthread_queue {
};
struct timerthread_queue_entry {
struct timeval when;
int64_t when;
unsigned int idx; // for equal timestamps
void *source; // opaque
char __rest[0];
@ -57,7 +57,7 @@ void timerthread_init(struct timerthread *, unsigned int, void (*)(void *));
void timerthread_free(struct timerthread *);
void timerthread_launch(struct timerthread *, const char *scheduler, int prio, const char *name);
void timerthread_obj_schedule_abs_nl(struct timerthread_obj *, const struct timeval);
void timerthread_obj_schedule_abs_nl(struct timerthread_obj *, const int64_t);
void timerthread_obj_deschedule(struct timerthread_obj *);
// run_now_func = called if newly inserted object can be processed immediately by timerthread_queue_push within its calling context
@ -79,7 +79,7 @@ INLINE struct timerthread_thread *timerthread_get_next(struct timerthread *tt) {
return &tt->threads[idx];
}
INLINE void timerthread_obj_schedule_abs(struct timerthread_obj *tt_obj, const struct timeval tv) {
INLINE void timerthread_obj_schedule_abs(struct timerthread_obj *tt_obj, const int64_t tv) {
if (!tt_obj)
return;
struct timerthread_thread *tt = tt_obj->thread;


+ 0
- 28
lib/auxlib.c View File

@ -537,34 +537,6 @@ int in6_addr_eq(const void *a, const void *b) {
return !memcmp(A, B, sizeof(*A));
}
int timeval_cmp_zero(const void *a, const void *b) {
const struct timeval *A = a, *B = b;
/* zero timevals go last */
if (A->tv_sec == 0 && B->tv_sec != 0)
return 1;
if (B->tv_sec == 0 && A->tv_sec == 0)
return -1;
if (A->tv_sec == 0 && B->tv_sec == 0)
return 0;
/* earlier timevals go first */
return timeval_cmp(*A, *B);
}
int timeval_cmp_ptr(const void *a, const void *b) {
const struct timeval *A = a, *B = b;
int ret;
ret = timeval_cmp_zero(A, B);
if (ret)
return ret;
/* equal timeval, so use pointer as tie breaker */
if (A < B)
return -1;
if (A > B)
return 1;
return 0;
}
int rtpe_tree_find_first_cmp(void *k, void *v, void *d) {
struct rtpe_g_tree_find_helper *h = d;
if (!h->func || h->func(v, h->data)) {


+ 3
- 8
lib/auxlib.h View File

@ -175,10 +175,10 @@ typedef pthread_cond_t cond_t;
#define cond_broadcast(c) __debug_cond_broadcast(c, __FILE__, __LINE__)
#define COND_STATIC_INIT PTHREAD_COND_INITIALIZER
INLINE int __cond_timedwait_tv(cond_t *c, mutex_t *m, const struct timeval *tv) {
INLINE int __cond_timedwait_tv(cond_t *c, mutex_t *m, int64_t tv) {
struct timespec ts;
ts.tv_sec = tv->tv_sec;
ts.tv_nsec = tv->tv_usec * 1000;
ts.tv_sec = tv / 1000000;
ts.tv_nsec = (tv % 1000000) * 1000;
return pthread_cond_timedwait(c, m, &ts);
}
@ -390,11 +390,6 @@ INLINE int timeval_cmp(const struct timeval a, const struct timeval b) {
return r;
return long_cmp(a.tv_usec, b.tv_usec);
}
// as a GCompareFunc
__attribute__((warn_unused_result))
int timeval_cmp_zero(const void *a, const void *b);
__attribute__((warn_unused_result))
int timeval_cmp_ptr(const void *a, const void *b);
__attribute__((warn_unused_result))
INLINE struct timeval timeval_lowest(const struct timeval l, const struct timeval n) {


Loading…
Cancel
Save