kdecore Library API Documentation

x86.h

00001 #include <sched.h>
00002 #include <time.h>
00003 
00004 typedef struct {
00005   volatile unsigned int lock;
00006   int pad0_;
00007 } mutex_t;
00008 
00009 #define MUTEX_INITIALIZER          { 0, 0 }
00010 
00011 static __inline__ int lock(mutex_t *m) {
00012   int cnt = 0, r;
00013   struct timespec tm;
00014 
00015   for(;;) {
00016     __asm__ __volatile__
00017       ("xchgl %0, %1"
00018        : "=r"(r), "=m"(m->lock)
00019        : "0"(1), "m"(m->lock)
00020        : "memory");
00021     if(!r)
00022       return 0;
00023 #ifdef _POSIX_PRIORITY_SCHEDULING
00024     if(cnt < 50) {
00025       sched_yield();
00026       cnt++;
00027     } else
00028 #endif
00029         {
00030       tm.tv_sec = 0;
00031       tm.tv_nsec = 2000001;
00032       nanosleep(&tm, NULL);
00033       cnt = 0;
00034     }
00035   }
00036 }
00037 
00038 static __inline__ int unlock(mutex_t *m) {
00039   __asm __volatile ("movl $0,%0" : "=m" (m->lock));
00040   return 0;
00041 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 27 22:14:48 2005 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001