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.4 by gbeauche, 2005-03-05T19:07:35Z vs.
Revision 1.5 by gbeauche, 2005-03-15T20:46:50Z

# Line 70 | Line 70 | static int32 timer_func(void *arg);
70   #endif
71   #ifdef PRECISE_TIMING_POSIX
72   static pthread_t timer_thread;
73 < static volatile bool thread_active = false;
73 > 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;
# Line 165 | Line 166 | static struct sigaction sigresume_action
166   static int suspend_count = 0;
167   static pthread_mutex_t suspend_count_lock = PTHREAD_MUTEX_INITIALIZER;
168   static sem_t suspend_ack_sem;
169 + static sigset_t suspend_handler_mask;
170  
171   // Signal handler for suspended thread
172   static void sigsuspend_handler(int sig)
173   {
174          sem_post(&suspend_ack_sem);
175 <
174 <        sigset_t mask;
175 <        sigfillset(&mask);
176 <        sigdelset(&mask, SIGRESUME);
177 <        sigsuspend(&mask);
175 >        sigsuspend(&suspend_handler_mask);
176   }
177  
178   // Signal handler for resumed thread
# Line 210 | Line 208 | static bool timer_thread_init(void)
208          if (sem_init(&suspend_ack_sem, 0, 0) < 0)
209                  return false;
210  
211 +        // Initialize suspend_handler_mask, it excludes SIGRESUME
212 +        if (sigfillset(&suspend_handler_mask) != 0)
213 +                return false;
214 +        if (sigdelset(&suspend_handler_mask, SIGRESUME) != 0)
215 +                return false;
216 +
217          // Create thread in running state
218          suspend_count = 0;
219          return (pthread_create(&timer_thread, NULL, timer_func, NULL) == 0);
# Line 218 | Line 222 | static bool timer_thread_init(void)
222   // Kill timer thread
223   static void timer_thread_kill(void)
224   {
225 +        timer_thread_cancel = true;
226   #ifdef HAVE_PTHREAD_CANCEL
227          pthread_cancel(timer_thread);
228   #endif
# Line 269 | Line 274 | void TimerInit(void)
274   #endif
275   #ifdef PRECISE_TIMING_POSIX
276          sem_init(&wakeup_time_sem, 0, 1);
277 <        thread_active = timer_thread_init();
277 >        timer_thread_active = timer_thread_init();
278   #endif
279   #endif
280   }
# Line 293 | Line 298 | void TimerExit(void)
298                  delete_sem(wakeup_time_sem);
299   #endif
300   #ifdef PRECISE_TIMING_POSIX
296                thread_active = false;
301                  timer_thread_kill();
302                  sem_destroy(&wakeup_time_sem);
303   #endif
# Line 522 | Line 526 | static int32 timer_func(void *arg)
526   #ifdef PRECISE_TIMING_POSIX
527   static void *timer_func(void *arg)
528   {
529 <        while (thread_active) {
529 >        while (!timer_thread_cancel) {
530  
531                  // Wait until time specified by wakeup_time
532                  clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &wakeup_time, NULL);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines