changeset 697:07966e8f9ed3

atomic: add atomic_cas_ptr to atomically swap an ordinary pointer The normal cas macro assumes we are operating on an atomic_t. Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Sun, 17 Mar 2019 09:56:12 -0400
parents 03eeee76f646
children 6a94380509f8
files include/jeffpc/atomic.h
diffstat 1 files changed, 4 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/include/jeffpc/atomic.h	Tue Mar 12 21:08:50 2019 -0400
+++ b/include/jeffpc/atomic.h	Sun Mar 17 09:56:12 2019 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2018 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ * Copyright (c) 2014-2019 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -47,8 +47,9 @@
 #define atomic_inc(var)		atomic_add((var), 1)
 #define atomic_dec(var)		atomic_sub((var), 1)
 #define atomic_cas(var, old, new)	\
-				__sync_val_compare_and_swap(&(var)->v, \
-							    (old), (new))
+		__sync_val_compare_and_swap(&(var)->v, (old), (new))
+#define atomic_cas_ptr(var, old, new)	\
+		__sync_val_compare_and_swap((var), (old), (new))
 
 #define ATOMIC_INITIALIZER(val)		{ .v = (val) }