ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/timer.cpp
(Generate patch)

Comparing SheepShaver/src/timer.cpp (file contents):
Revision 1.5 by gbeauche, 2005-03-15T20:46:50Z vs.
Revision 1.6 by gbeauche, 2005-03-16T00:35:51Z

# Line 74 | Line 74 | static bool timer_thread_active = false;
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
# Line 185 | Line 185 | static void sigresume_handler(int sig)
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
# Line 195 | Line 196 | static bool timer_thread_init(void)
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
# Line 273 | Line 274 | void TimerInit(void)
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
# Line 299 | Line 299 | void TimerExit(void)
299   #endif
300   #ifdef PRECISE_TIMING_POSIX
301                  timer_thread_kill();
302                sem_destroy(&wakeup_time_sem);
302   #endif
303          }
304   #endif
# Line 358 | Line 357 | int16 RmvTime(uint32 tm)
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  
# Line 393 | Line 392 | int16 RmvTime(uint32 tm)
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
# Line 466 | Line 465 | int16 PrimeTime(uint32 tm, int32 time)
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);
# Line 488 | Line 487 | int16 PrimeTime(uint32 tm, int32 time)
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
# Line 531 | Line 530 | static void *timer_func(void *arg)
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
# Line 541 | Line 540 | static void *timer_func(void *arg)
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   }
# Line 588 | Line 587 | void TimerInterrupt(void)
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++) {
# Line 606 | Line 605 | void TimerInterrupt(void)
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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines