#include <stdarg.h>
#include <stdlib.h>
#include <runtime.h>
+#include "mlp_lock.h"
static volatile unsigned int corecount=0;
-
-static inline int atomicinc(volatile unsigned int *lock) {
- int retval=1;
- __asm__ __volatile__("lock; xadd %0,%1"
- : "=r"(retval)
- : "m"(*lock), "0"(retval)
- : "memory");
- return retval;
-}
-
-
void set_affinity() {
int err;
cpu_set_t cpumask;
CPU_ZERO(&cpumask);
- int ourcount=atomicinc(&corecount);
+ int ourcount=atomicincandread(&corecount);
ourcount=ourcount&7;
int newvalue=ourcount>>1;
if (ourcount&1) {
"661:\n\tlock; "
+static inline int atomicincandread(volatile unsigned int *lock) {
+ int retval=1;
+ __asm__ __volatile__("lock; xadd %0,%1"
+ : "=r"(retval)
+ : "m"(*lock), "0"(retval)
+ : "memory");
+ return retval;
+}
+
static inline void atomic_dec(volatile int *v) {
__asm__ __volatile__ (LOCK_PREFIX "decl %0"
: "+m" (*v));