RPA Toolkit
dev
authormstoilov <mstoilov@b0bb84a5-424d-4f98-af44-3ef3f117eb03>
Tue, 13 Jul 2010 11:53:34 +0000 (04:53 -0700)
committermstoilov <mstoilov@b0bb84a5-424d-4f98-af44-3ef3f117eb03>
Tue, 13 Jul 2010 11:53:34 +0000 (04:53 -0700)
git-svn-id: svn+ssh://svn.crossrain.com/svn/rpase/trunk/rtk@123 b0bb84a5-424d-4f98-af44-3ef3f117eb03

arch/linux/x86_64/rtypes.h
rlib/build/linux/rlib.mk
rlib/ratomic.c [new file with mode: 0644]
rlib/rmem.c

index 01efc97..a9bdce4 100644 (file)
@@ -33,6 +33,14 @@ typedef signed long rint64;
 typedef unsigned long ruint64;
 typedef unsigned long rword;
 
+/*
+ * Atomic operations (Architecture Dependent)
+ */
+#define R_COMPARE_AND_EXCHANGE(ptr, oldval, newval, res) \
+               do { __asm__ __volatile__ ("lock; cmpxchgl %2, %1" \
+                       : "=a" (res), "=m" (*ptr) \
+                       : "r" (newval), "m" (*ptr), "0" (oldval)); } while (0)
+
 
 #ifndef NULL
 #ifdef __cplusplus
index 86d8e21..c30c393 100644 (file)
@@ -4,6 +4,7 @@ RLIB_SO = $(OUTDIR)/librlib.so.1.0
 
 RLIB_OBJECTS = \
        $(OUTDIR)/rmem.o \
+       $(OUTDIR)/ratomic.o \
 
 
 ifeq ($(OS), linux)
diff --git a/rlib/ratomic.c b/rlib/ratomic.c
new file mode 100644 (file)
index 0000000..45903ff
--- /dev/null
@@ -0,0 +1,10 @@
+#include "rtypes.h"
+
+
+rboolean r_atomic_compare_and_exchange(volatile rint *ptr, rint oldval, rint newval)
+{
+       rint result;
+
+       R_COMPARE_AND_EXCHANGE(ptr, oldval, newval, result);
+       return (result == oldval);
+}
index ce35783..39efca3 100644 (file)
@@ -42,7 +42,6 @@ void r_free(void *ptr)
                return;
        size = *mem;
        g_allocmem -= size;
-//     fprintf(stdout, "%p (%ld de-allocated)\n", (void*)mem, size);
        free((void*)mem);
 #else
        free(ptr);