Temporarily add RISC-V GCC CAS routines to parlib
authorAndrew Waterman <waterman@cs.berkeley.edu>
Mon, 7 Jan 2013 03:39:13 +0000 (19:39 -0800)
committerAndrew Waterman <waterman@cs.berkeley.edu>
Mon, 7 Jan 2013 03:39:13 +0000 (19:39 -0800)
user/parlib/Makefile
user/parlib/riscv/atomic.c [new file with mode: 0644]

index 13565de..5abde99 100644 (file)
@@ -19,6 +19,7 @@ uc = $(shell echo $(1) | tr a-z A-Z)
 LIBUCNAME := $(call uc, $(LIBNAME))
 HEADERS := $(shell find $(INCDIR) -name *.h)
 CFILES  := $(wildcard $(SRCDIR)*.c)
+CFILES  += $(wildcard $(SRCDIR)$(TARGET_ARCH)/*.c)
 SFILES  := $(wildcard $(SRCDIR)$(TARGET_ARCH)/*.S)
 OBJS    := $(patsubst %.c, $(OBJDIR)/%.o, $(CFILES)) \
            $(patsubst %.S, $(OBJDIR)/%.o, $(SFILES))
diff --git a/user/parlib/riscv/atomic.c b/user/parlib/riscv/atomic.c
new file mode 100644 (file)
index 0000000..82510b4
--- /dev/null
@@ -0,0 +1,24 @@
+#include <ros/atomic.h>
+#include <stdint.h>
+#include <spinlock.h>
+
+static spinlock_t lock = SPINLOCK_INITIALIZER;
+
+#define bool_cas_func(size, type) \
+  bool __sync_bool_compare_and_swap_ ## size(type* ptr, type oldval, type newval) \
+  { \
+       bool success = false; \
+       spinlock_lock(&lock); \
+       if (*ptr == oldval) \
+       { \
+         *ptr = newval; \
+         success = true; \
+       } \
+       spinlock_unlock(&lock); \
+       return success; \
+  }
+
+bool_cas_func(1, uint8_t)
+bool_cas_func(2, uint16_t)
+bool_cas_func(4, uint32_t)
+bool_cas_func(8, uint64_t)