Add atomic_load and store functions without membars, fwiw.

This commit is contained in:
Jake Burkholder 2001-09-03 22:03:25 +00:00
parent e19e5d8968
commit f8da586016
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=82895

View File

@ -1,4 +1,5 @@
/*-
* Copyright (c) 1998 Doug Rabson.
* Copyright (c) 2001 Jake Burkholder.
* All rights reserved.
*
@ -23,6 +24,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: FreeBSD: src/sys/i386/include/atomic.h,v 1.20 2001/02/11
* $FreeBSD$
*/
@ -115,9 +117,12 @@
atomic_op(p, op, v, sz); \
} while (0)
#define atomic_load(p, sz) \
atomic_cas(p, 0, 0, sz)
#define atomic_load_acq(p, sz) ({ \
itype(sz) v; \
v = atomic_cas_ ## sz(p, 0, 0); \
v = atomic_load(p, sz); \
membar(LoadLoad | LoadStore); \
v; \
})
@ -125,23 +130,27 @@
#define atomic_load_clear(p, sz) ({ \
itype(sz) e, r; \
for (e = *(volatile itype(sz) *)p;; e = r) { \
r = atomic_cas_ ## sz(p, e, 0); \
r = atomic_cas(p, e, 0, sz); \
if (r == e) \
break; \
} \
e; \
})
#define atomic_store_rel(p, v, sz) do { \
#define atomic_store(p, v, sz) do { \
itype(sz) e, r; \
membar(LoadStore | StoreStore); \
for (e = *(volatile itype(sz) *)p;; e = r) { \
r = atomic_cas_ ## sz(p, e, v); \
r = atomic_cas(p, e, v, sz); \
if (r == e) \
break; \
} \
} while (0)
#define atomic_store_rel(p, v, sz) do { \
membar(LoadStore | StoreStore); \
atomic_store(p, v, sz); \
} while (0)
#define ATOMIC_GEN(name, ptype, vtype, atype, sz) \
\
static __inline void \
@ -193,6 +202,11 @@ atomic_cmpset_rel_ ## name(volatile ptype p, vtype e, vtype s) \
} \
\
static __inline vtype \
atomic_load_ ## name(volatile ptype p) \
{ \
return ((vtype)atomic_cas(p, 0, 0, sz)); \
} \
static __inline vtype \
atomic_load_acq_ ## name(volatile ptype p) \
{ \
return ((vtype)atomic_cas_acq(p, 0, 0, sz)); \
@ -237,6 +251,11 @@ atomic_subtract_rel_ ## name(volatile ptype p, atype v) \
} \
\
static __inline void \
atomic_store_ ## name(volatile ptype p, vtype v) \
{ \
atomic_store(p, v, sz); \
} \
static __inline void \
atomic_store_rel_ ## name(volatile ptype p, vtype v) \
{ \
atomic_store_rel(p, v, sz); \