From b9961802ce2f774c884d6708beec5e8ac6f264ed Mon Sep 17 00:00:00 2001 From: Darius Rad Date: Mon, 21 Sep 2015 07:36:27 -0400 Subject: Fix macros for emulating atomic operations (--disable-atomics). --- pk/atomic.h | 6 +++--- pk/file.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pk/atomic.h b/pk/atomic.h index c2adf00..2ec4a04 100644 --- a/pk/atomic.h +++ b/pk/atomic.h @@ -23,19 +23,19 @@ typedef struct { int lock; } spinlock_t; #else # define atomic_add(ptr, inc) ({ \ long flags = disable_irqsave(); \ - typeof(ptr) res = *(volatile typeof(ptr))(ptr); \ + typeof(*(ptr)) res = *(volatile typeof(*(ptr)) *)(ptr); \ *(volatile typeof(ptr))(ptr) = res + (inc); \ enable_irqrestore(flags); \ res; }) # define atomic_swap(ptr, swp) ({ \ long flags = disable_irqsave(); \ - typeof(ptr) res = *(volatile typeof(ptr))(ptr); \ + typeof(*(ptr)) res = *(volatile typeof(*(ptr)) *)(ptr); \ *(volatile typeof(ptr))(ptr) = (swp); \ enable_irqrestore(flags); \ res; }) # define atomic_cas(ptr, cmp, swp) ({ \ long flags = disable_irqsave(); \ - typeof(ptr) res = *(volatile typeof(ptr))(ptr); \ + typeof(*(ptr)) res = *(volatile typeof(*(ptr)) *)(ptr); \ if (res == (cmp)) *(volatile typeof(ptr))(ptr) = (swp); \ enable_irqrestore(flags); \ res; }) diff --git a/pk/file.c b/pk/file.c index ee2f9fd..0c9c96a 100644 --- a/pk/file.c +++ b/pk/file.c @@ -107,7 +107,7 @@ int fd_close(int fd) file_t* f = file_get(fd); if (!f) return -1; - file_t* old = atomic_cas(&fds[fd], (long)f, 0); + file_t* old = atomic_cas(&fds[fd], f, 0); file_decref(f); if (old != f) return -1; -- cgit v1.1