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

Comparing BasiliskII/src/Unix/timer_unix.cpp (file contents):
Revision 1.16 by gbeauche, 2005-02-21T22:57:03Z vs.
Revision 1.18 by gbeauche, 2005-06-30T10:34:31Z

# Line 297 | Line 297 | void Delay_usec(uint32 usec)
297   #endif
298          } while (was_error && (errno == EINTR));
299   }
300 +
301 +
302 + /*
303 + *  Suspend emulator thread, virtual CPU in idle mode
304 + */
305 +
306 + #ifdef HAVE_PTHREADS
307 + #if defined(HAVE_PTHREAD_COND_INIT)
308 + #define IDLE_USES_COND_WAIT 1
309 + static pthread_mutex_t idle_lock = PTHREAD_MUTEX_INITIALIZER;
310 + static pthread_cond_t idle_cond = PTHREAD_COND_INITIALIZER;
311 + #elif defined(HAVE_SEM_INIT)
312 + #define IDLE_USES_SEMAPHORE 1
313 + #include <semaphore.h>
314 + #ifdef HAVE_SPINLOCKS
315 + static spinlock_t idle_lock = SPIN_LOCK_UNLOCKED;
316 + #define LOCK_IDLE spin_lock(&idle_lock)
317 + #define UNLOCK_IDLE spin_unlock(&idle_lock)
318 + #else
319 + static pthread_mutex_t idle_lock = PTHREAD_MUTEX_INITIALIZER;
320 + #define LOCK_IDLE pthread_mutex_lock(&idle_lock)
321 + #define UNLOCK_IDLE pthread_mutex_unlock(&idle_lock)
322 + #endif
323 + static sem_t idle_sem;
324 + static int idle_sem_ok = -1;
325 + #endif
326 + #endif
327 +
328 + void idle_wait(void)
329 + {
330 + #ifdef IDLE_USES_COND_WAIT
331 +        pthread_mutex_lock(&idle_lock);
332 +        pthread_cond_wait(&idle_cond, &idle_lock);
333 +        pthread_mutex_unlock(&idle_lock);
334 + #else
335 + #ifdef IDLE_USES_SEMAPHORE
336 +        if (idle_sem_ok < 0)
337 +                idle_sem_ok = (sem_init(&idle_sem, 0, 0) == 0);
338 +        if (idle_sem_ok > 0) {
339 +                LOCK_IDLE;
340 +                idle_sem_ok++;
341 +                UNLOCK_IDLE;
342 +                sem_wait(&idle_sem);
343 +                return;
344 +        }
345 + #endif
346 +        Delay_usec(10000);
347 + #endif
348 + }
349 +
350 +
351 + /*
352 + *  Resume execution of emulator thread, events just arrived
353 + */
354 +
355 + void idle_resume(void)
356 + {
357 + #ifdef IDLE_USES_COND_WAIT
358 +        pthread_cond_signal(&idle_cond);
359 + #else
360 + #ifdef IDLE_USES_SEMAPHORE
361 +        if (idle_sem_ok > 1) {
362 +                LOCK_IDLE;
363 +                idle_sem_ok--;
364 +                UNLOCK_IDLE;
365 +                sem_post(&idle_sem);
366 +                return;
367 +        }
368 + #endif
369 + #endif
370 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines