Ticket #174: spinlock_yield.diff

File spinlock_yield.diff, 932 bytes (added by bart, 4 years ago)
  • x86_spinlocks.h

     
    2525   $Id: x86_spinlocks.h 178 2006-03-06 09:08:40Z bart $ 
    2626*/ 
    2727 
     28#ifdef HAVE_SCHED_H 
     29#  include <sched.h> 
     30#endif 
     31 
    2832typedef struct { volatile unsigned int lock; 
    2933                 volatile pid_t pid; 
    3034                 volatile int locked; 
     
    3539#define spinlock_try_lock(rw)  asm volatile("lock ; decl %0" :"=m" ((rw)->lock) : : "memory") 
    3640#define _spinlock_unlock(rw)   asm volatile("lock ; incl %0" :"=m" ((rw)->lock) : : "memory") 
    3741 
     42 
     43#ifdef HAVE_SCHED_YIELD 
     44#  define yield sched_yield 
     45#else 
    3846static inline void yield() 
    3947{ 
    4048  struct timeval t; 
     
    4351  t.tv_usec = 100; 
    4452  select(0, NULL, NULL, NULL, &t); 
    4553} 
     54#endif 
    4655 
    4756static inline void spinlock_unlock(spinlock_t* rw) { 
    4857  if (rw->locked && (rw->pid == getpid())) {