aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarius Rad <darius@bluespec.com>2015-09-21 07:36:27 -0400
committerDarius Rad <darius@bluespec.com>2015-11-18 08:28:07 -0500
commitb9961802ce2f774c884d6708beec5e8ac6f264ed (patch)
tree60c9687bbee963dc277a20762ee6c670cca136b0
parent197a8b81e4bbf61c497c93c0ac4630a33ab11b1c (diff)
downloadpk-b9961802ce2f774c884d6708beec5e8ac6f264ed.zip
pk-b9961802ce2f774c884d6708beec5e8ac6f264ed.tar.gz
pk-b9961802ce2f774c884d6708beec5e8ac6f264ed.tar.bz2
Fix macros for emulating atomic operations (--disable-atomics).
-rw-r--r--pk/atomic.h6
-rw-r--r--pk/file.c2
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;