diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | ce4a32fe52ef09d8f5ff1dd22c001110902b60a2 (patch) | |
tree | 5ac38a06f3dde268dc7927dc155896926aaf7012 /kdecore/malloc/x86.h | |
download | tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.tar.gz tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kdecore/malloc/x86.h')
-rw-r--r-- | kdecore/malloc/x86.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/kdecore/malloc/x86.h b/kdecore/malloc/x86.h new file mode 100644 index 000000000..b21517374 --- /dev/null +++ b/kdecore/malloc/x86.h @@ -0,0 +1,41 @@ +#include <sched.h> +#include <time.h> + +typedef struct { + volatile unsigned int lock; + int pad0_; +} mutex_t; + +#define MUTEX_INITIALIZER { 0, 0 } + +static __inline__ int lock(mutex_t *m) { + int cnt = 0, r; + struct timespec tm; + + for(;;) { + __asm__ __volatile__ + ("xchgl %0, %1" + : "=r"(r), "=m"(m->lock) + : "0"(1), "m"(m->lock) + : "memory"); + if(!r) + return 0; +#ifdef _POSIX_PRIORITY_SCHEDULING + if(cnt < 50) { + sched_yield(); + cnt++; + } else +#endif + { + tm.tv_sec = 0; + tm.tv_nsec = 2000001; + nanosleep(&tm, NULL); + cnt = 0; + } + } +} + +static __inline__ int unlock(mutex_t *m) { + __asm __volatile ("movl $0,%0" : "=m" (m->lock)); + return 0; +} |