74 |
|
static volatile bool timer_thread_cancel = false; |
75 |
|
static tm_time_t wakeup_time_max = { 0x7fffffff, 999999999 }; |
76 |
|
static tm_time_t wakeup_time = wakeup_time_max; |
77 |
< |
static sem_t wakeup_time_sem; |
77 |
> |
static pthread_mutex_t wakeup_time_lock = PTHREAD_MUTEX_INITIALIZER; |
78 |
|
static void *timer_func(void *arg); |
79 |
|
#endif |
80 |
|
#endif |
185 |
|
static bool timer_thread_init(void) |
186 |
|
{ |
187 |
|
// Install suspend signal handler |
188 |
< |
sigfillset(&sigsuspend_action.sa_mask); |
188 |
> |
sigemptyset(&sigsuspend_action.sa_mask); |
189 |
> |
sigaddset(&sigsuspend_action.sa_mask, SIGRESUME); |
190 |
|
sigsuspend_action.sa_handler = sigsuspend_handler; |
191 |
|
sigsuspend_action.sa_flags = SA_RESTART; |
192 |
|
#ifdef HAVE_SIGNAL_SA_RESTORER |
196 |
|
return false; |
197 |
|
|
198 |
|
// Install resume signal handler |
199 |
< |
sigfillset(&sigresume_action.sa_mask); |
199 |
> |
sigemptyset(&sigresume_action.sa_mask); |
200 |
|
sigresume_action.sa_handler = sigresume_handler; |
201 |
|
sigresume_action.sa_flags = SA_RESTART; |
202 |
|
#ifdef HAVE_SIGNAL_SA_RESTORER |
274 |
|
resume_thread(timer_thread); |
275 |
|
#endif |
276 |
|
#ifdef PRECISE_TIMING_POSIX |
276 |
– |
sem_init(&wakeup_time_sem, 0, 1); |
277 |
|
timer_thread_active = timer_thread_init(); |
278 |
|
#endif |
279 |
|
#endif |
299 |
|
#endif |
300 |
|
#ifdef PRECISE_TIMING_POSIX |
301 |
|
timer_thread_kill(); |
302 |
– |
sem_destroy(&wakeup_time_sem); |
302 |
|
#endif |
303 |
|
} |
304 |
|
#endif |
357 |
|
suspend_thread(timer_thread); |
358 |
|
#endif |
359 |
|
#if PRECISE_TIMING_POSIX |
361 |
– |
sem_wait(&wakeup_time_sem); |
360 |
|
timer_thread_suspend(); |
361 |
+ |
pthread_mutex_lock(&wakeup_time_lock); |
362 |
|
#endif |
363 |
|
if (ReadMacInt16(tm + qType) & 0x8000) { |
364 |
|
|
392 |
|
} while (info.state == B_THREAD_SUSPENDED); // Sometimes, resume_thread() doesn't work (BeOS bug?) |
393 |
|
#endif |
394 |
|
#if PRECISE_TIMING_POSIX |
395 |
< |
sem_post(&wakeup_time_sem); |
395 |
> |
pthread_mutex_unlock(&wakeup_time_lock); |
396 |
|
timer_thread_resume(); |
397 |
|
assert(suspend_count == 0); |
398 |
|
#endif |
465 |
|
suspend_thread(timer_thread); |
466 |
|
#endif |
467 |
|
#if PRECISE_TIMING_POSIX |
469 |
– |
sem_wait(&wakeup_time_sem); |
468 |
|
timer_thread_suspend(); |
469 |
+ |
pthread_mutex_lock(&wakeup_time_lock); |
470 |
|
#endif |
471 |
|
WriteMacInt16(tm + qType, ReadMacInt16(tm + qType) | 0x8000); |
472 |
|
enqueue_tm(tm); |
487 |
|
} while (info.state == B_THREAD_SUSPENDED); // Sometimes, resume_thread() doesn't work (BeOS bug?) |
488 |
|
#endif |
489 |
|
#ifdef PRECISE_TIMING_POSIX |
490 |
< |
sem_post(&wakeup_time_sem); |
490 |
> |
pthread_mutex_unlock(&wakeup_time_lock); |
491 |
|
timer_thread_resume(); |
492 |
|
assert(suspend_count == 0); |
493 |
|
#endif |
530 |
|
// Wait until time specified by wakeup_time |
531 |
|
clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &wakeup_time, NULL); |
532 |
|
|
534 |
– |
sem_wait(&wakeup_time_sem); |
533 |
|
tm_time_t system_time; |
534 |
|
timer_current_time(system_time); |
535 |
+ |
pthread_mutex_lock(&wakeup_time_lock); |
536 |
|
if (timer_cmp_time(wakeup_time, system_time) < 0) { |
537 |
|
|
538 |
|
// Timer expired, trigger interrupt |
540 |
|
SetInterruptFlag(INTFLAG_TIMER); |
541 |
|
TriggerInterrupt(); |
542 |
|
} |
543 |
< |
sem_post(&wakeup_time_sem); |
543 |
> |
pthread_mutex_unlock(&wakeup_time_lock); |
544 |
|
} |
545 |
|
return NULL; |
546 |
|
} |
587 |
|
suspend_thread(timer_thread); |
588 |
|
#endif |
589 |
|
#if PRECISE_TIMING_POSIX |
591 |
– |
sem_wait(&wakeup_time_sem); |
590 |
|
timer_thread_suspend(); |
591 |
+ |
pthread_mutex_lock(&wakeup_time_lock); |
592 |
|
#endif |
593 |
|
wakeup_time = wakeup_time_max; |
594 |
|
for (int j=0; j<NUM_DESCS; j++) { |
605 |
|
} while (info.state == B_THREAD_SUSPENDED); // Sometimes, resume_thread() doesn't work (BeOS bug?) |
606 |
|
#endif |
607 |
|
#if PRECISE_TIMING_POSIX |
608 |
< |
sem_post(&wakeup_time_sem); |
608 |
> |
pthread_mutex_unlock(&wakeup_time_lock); |
609 |
|
timer_thread_resume(); |
610 |
|
assert(suspend_count == 0); |
611 |
|
#endif |