TIMER: Fix overflow error in sim_idle_ms_sleep() timespec tv_nsec field
Backed out commit 484889ea5a
since the overflow of the timespec tv_nsec
field was the real cause of the problem. No need for an extra mutex.
As reported in #595
This commit is contained in:
parent
9e60a8e783
commit
97bee79faa
3 changed files with 6 additions and 19 deletions
1
scp.c
1
scp.c
|
@ -326,7 +326,6 @@
|
||||||
#if defined (SIM_ASYNCH_IO)
|
#if defined (SIM_ASYNCH_IO)
|
||||||
pthread_mutex_t sim_asynch_lock = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t sim_asynch_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
pthread_cond_t sim_asynch_wake = PTHREAD_COND_INITIALIZER;
|
pthread_cond_t sim_asynch_wake = PTHREAD_COND_INITIALIZER;
|
||||||
pthread_mutex_t sim_idle_lock = PTHREAD_MUTEX_INITIALIZER;
|
|
||||||
|
|
||||||
pthread_mutex_t sim_timer_lock = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t sim_timer_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
pthread_cond_t sim_timer_wake = PTHREAD_COND_INITIALIZER;
|
pthread_cond_t sim_timer_wake = PTHREAD_COND_INITIALIZER;
|
||||||
|
|
|
@ -1063,7 +1063,6 @@ struct MEMFILE {
|
||||||
|
|
||||||
extern pthread_mutex_t sim_asynch_lock;
|
extern pthread_mutex_t sim_asynch_lock;
|
||||||
extern pthread_cond_t sim_asynch_wake;
|
extern pthread_cond_t sim_asynch_wake;
|
||||||
extern pthread_mutex_t sim_idle_lock;
|
|
||||||
extern pthread_mutex_t sim_timer_lock;
|
extern pthread_mutex_t sim_timer_lock;
|
||||||
extern pthread_cond_t sim_timer_wake;
|
extern pthread_cond_t sim_timer_wake;
|
||||||
extern t_bool sim_timer_event_canceled;
|
extern t_bool sim_timer_event_canceled;
|
||||||
|
@ -1176,7 +1175,6 @@ extern int32 sim_asynch_inst_latency;
|
||||||
do { \
|
do { \
|
||||||
pthread_mutex_destroy(&sim_asynch_lock); \
|
pthread_mutex_destroy(&sim_asynch_lock); \
|
||||||
pthread_cond_destroy(&sim_asynch_wake); \
|
pthread_cond_destroy(&sim_asynch_wake); \
|
||||||
pthread_mutex_destroy(&sim_idle_lock); \
|
|
||||||
pthread_mutex_destroy(&sim_timer_lock); \
|
pthread_mutex_destroy(&sim_timer_lock); \
|
||||||
pthread_cond_destroy(&sim_timer_wake); \
|
pthread_cond_destroy(&sim_timer_wake); \
|
||||||
pthread_mutex_destroy(&sim_tmxr_poll_lock); \
|
pthread_mutex_destroy(&sim_tmxr_poll_lock); \
|
||||||
|
@ -1226,7 +1224,6 @@ extern int32 sim_asynch_inst_latency;
|
||||||
do { \
|
do { \
|
||||||
pthread_mutex_destroy(&sim_asynch_lock); \
|
pthread_mutex_destroy(&sim_asynch_lock); \
|
||||||
pthread_cond_destroy(&sim_asynch_wake); \
|
pthread_cond_destroy(&sim_asynch_wake); \
|
||||||
pthread_mutex_destroy(&sim_idle_lock); \
|
|
||||||
pthread_mutex_destroy(&sim_timer_lock); \
|
pthread_mutex_destroy(&sim_timer_lock); \
|
||||||
pthread_cond_destroy(&sim_timer_wake); \
|
pthread_cond_destroy(&sim_timer_wake); \
|
||||||
pthread_mutex_destroy(&sim_tmxr_poll_lock); \
|
pthread_mutex_destroy(&sim_tmxr_poll_lock); \
|
||||||
|
|
21
sim_timer.c
21
sim_timer.c
|
@ -244,27 +244,18 @@ int stat;
|
||||||
clock_gettime(CLOCK_REALTIME, &done_time);
|
clock_gettime(CLOCK_REALTIME, &done_time);
|
||||||
done_time.tv_sec += (msec/1000);
|
done_time.tv_sec += (msec/1000);
|
||||||
done_time.tv_nsec += 1000000*(msec%1000);
|
done_time.tv_nsec += 1000000*(msec%1000);
|
||||||
if (done_time.tv_nsec > 1000000000) {
|
if (done_time.tv_nsec >= 1000000000) {
|
||||||
done_time.tv_sec += done_time.tv_nsec/1000000000;
|
done_time.tv_sec += done_time.tv_nsec/1000000000;
|
||||||
done_time.tv_nsec = done_time.tv_nsec%1000000000;
|
done_time.tv_nsec = done_time.tv_nsec%1000000000;
|
||||||
}
|
}
|
||||||
pthread_mutex_lock (&sim_idle_lock);
|
pthread_mutex_lock (&sim_asynch_lock);
|
||||||
sim_idle_wait = TRUE;
|
sim_idle_wait = TRUE;
|
||||||
stat = pthread_cond_timedwait (&sim_asynch_wake, &sim_idle_lock, &done_time);
|
if (pthread_cond_timedwait (&sim_asynch_wake, &sim_asynch_lock, &done_time))
|
||||||
if (stat == 0)
|
|
||||||
sim_asynch_check = 0; /* force check of asynch queue now */
|
|
||||||
else
|
|
||||||
if (stat == ETIMEDOUT)
|
|
||||||
timedout = TRUE;
|
timedout = TRUE;
|
||||||
else {
|
else
|
||||||
char ans[32];
|
sim_asynch_check = 0; /* force check of asynch queue now */
|
||||||
|
|
||||||
fprintf (stderr, "sim_idle_ms_sleep(%u): pthread_cond_timedwait() return %d - %s\r\n", msec, stat, strerror (stat));
|
|
||||||
read_line_p ("Hit Return to exit: ", ans, sizeof (ans) - 1, stdin);
|
|
||||||
abort ();
|
|
||||||
}
|
|
||||||
sim_idle_wait = FALSE;
|
sim_idle_wait = FALSE;
|
||||||
pthread_mutex_unlock (&sim_idle_lock);
|
pthread_mutex_unlock (&sim_asynch_lock);
|
||||||
if (!timedout) {
|
if (!timedout) {
|
||||||
AIO_UPDATE_QUEUE;
|
AIO_UPDATE_QUEUE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue