Commit a8cf9830 authored by Simon Morlat's avatar Simon Morlat
Browse files

fix double lock when ms_ticker_get_last_late_event() is called from the ticker thread itself

parent 56e02b2f
......@@ -96,6 +96,7 @@ static MS2_INLINE void ms_debug(const char *fmt,...)
#define ms_thread_t ortp_thread_t
#define ms_thread_create ortp_thread_create
#define ms_thread_join ortp_thread_join
#define ms_thread_self ortp_thread_self
typedef ortpTimeSpec MSTimeSpec;
......
......@@ -90,6 +90,7 @@ struct _MSTicker
MSTickerTickFunc wait_next_tick;
void *wait_next_tick_data;
MSTickerLateEvent late_event;
unsigned long thread_id;
bool_t run; /* flag to indicate whether the ticker must be run or not */
};
......
......@@ -414,7 +414,7 @@ void * ms_ticker_run(void *arg)
int late;
precision = set_high_prio(s);
s->thread_id = ms_thread_self();
s->ticks=1;
s->orig=s->get_cur_time_ptr(s->get_cur_time_data);
......@@ -461,6 +461,7 @@ void * ms_ticker_run(void *arg)
ms_message("%s thread exiting",s->name);
ms_thread_exit(NULL);
s->thread_id = 0;
return NULL;
}
......@@ -542,10 +543,13 @@ float ms_ticker_get_average_load(MSTicker *ticker){
return ticker->av_load;
}
void ms_ticker_get_last_late_tick(MSTicker *ticker, MSTickerLateEvent *ev){
ms_mutex_lock(&ticker->lock);
bool_t need_lock = ms_thread_self() != ticker->thread_id;
if (need_lock) ms_mutex_lock(&ticker->lock);
memcpy(ev,&ticker->late_event,sizeof(MSTickerLateEvent));
ms_mutex_unlock(&ticker->lock);
if (need_lock) ms_mutex_unlock(&ticker->lock);
}
static uint64_t get_ms(const MSTimeSpec *ts){
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment