John Baldwin <[EMAIL PROTECTED]> writes:
> On Tuesday 28 March 2006 13:05, Dag-Erling Smørgrav wrote:
> > John Baldwin <[EMAIL PROTECTED]> writes:
> > > One reason for not having the casts, btw, is that you lose type
> > > checking.
> > Huh?  Before my patch, any use of atomic_*_ptr with warnings turned
> > off would result in a slew of warnings because you'd be passing
> > pointers to a function which is declared to take u_int.  The only way
> > to make this type safe is to use inline functions instead of the
> > macros I wrote.
>
> s/off/on/ I trust
>
> Not true.  The tinderbox would attest to that.  Please see code such as
> this:  [...]

which uses uintptr_t, not actual pointers, to avoid warnings.  In
effect, that code is broken.

Apply the attached patch, see how far a buildkernel gets...

I think the proper thing to do, to cover all your bases, would be to
define a MD atomic_*_intptr family which operated on uintptr_t, and
define an MI atomic_*_ptr family which operates on void * based on
that.

> Even userland uses casts when it uses void * rather than uintptr_t for
> the underlying type.  See src/lib/libpthread/sys/lock.c or
> src/lib/libthr/thr_umtx.h.

The latter only works because libthr is built with warnings disabled.
I just finished working on making it build at WARNS level 2; higher
levels will require a major overhaul, because the kernel interface it
uses is fundamentally broken.

DES
-- 
Dag-Erling Smørgrav - [EMAIL PROTECTED]

Index: sys/i386/include/atomic.h
===================================================================
RCS file: /home/ncvs/src/sys/i386/include/atomic.h,v
retrieving revision 1.42
diff -u -r1.42 atomic.h
--- sys/i386/include/atomic.h	28 Mar 2006 14:34:48 -0000	1.42
+++ sys/i386/include/atomic.h	28 Mar 2006 19:24:17 -0000
@@ -415,42 +415,116 @@
 #define	atomic_fetchadd_32	atomic_fetchadd_int
 
 /* Operations on pointers. */
-#define	atomic_set_ptr(p, v) \
-	atomic_set_int((volatile u_int *)(p), (u_int)(v))
-#define	atomic_set_acq_ptr(p, v) \
-	atomic_set_acq_int((volatile u_int *)(p), (u_int)(v))
-#define	atomic_set_rel_ptr(p, v) \
-	atomic_set_rel_int((volatile u_int *)(p), (u_int)(v))
-#define	atomic_clear_ptr(p, v) \
-	atomic_clear_int((volatile u_int *)(p), (u_int)(v))
-#define	atomic_clear_acq_ptr(p, v) \
-	atomic_clear_acq_int((volatile u_int *)(p), (u_int)(v))
-#define	atomic_clear_rel_ptr(p, v) \
-	atomic_clear_rel_int((volatile u_int *)(p), (u_int)(v))
-#define	atomic_add_ptr(p, v) \
-	atomic_add_int((volatile u_int *)(p), (u_int)(v))
-#define	atomic_add_acq_ptr(p, v) \
-	atomic_add_acq_int((volatile u_int *)(p), (u_int)(v))
-#define	atomic_add_rel_ptr(p, v) \
-	atomic_add_rel_int((volatile u_int *)(p), (u_int)(v))
-#define	atomic_subtract_ptr(p, v) \
-	atomic_subtract_int((volatile u_int *)(p), (u_int)(v))
-#define	atomic_subtract_acq_ptr(p, v) \
-	atomic_subtract_acq_int((volatile u_int *)(p), (u_int)(v))
-#define	atomic_subtract_rel_ptr(p, v) \
-	atomic_subtract_rel_int((volatile u_int *)(p), (u_int)(v))
-#define	atomic_load_acq_ptr(p) \
-	atomic_load_acq_int((volatile u_int *)(p))
-#define	atomic_store_rel_ptr(p, v) \
-	atomic_store_rel_int((volatile u_int *)(p), (v))
-#define	atomic_cmpset_ptr(dst, old, new) \
-	atomic_cmpset_int((volatile u_int *)(dst), (u_int)(old), (u_int)(new))
-#define	atomic_cmpset_acq_ptr(dst, old, new) \
-	atomic_cmpset_acq_int((volatile u_int *)(dst), (u_int)(old), (u_int)(new))
-#define	atomic_cmpset_rel_ptr(dst, old, new) \
-	atomic_cmpset_rel_int((volatile u_int *)(dst), (u_int)(old), (u_int)(new))
-#define	atomic_readandclear_ptr(p) \
-	atomic_readandclear_int((volatile u_int *)(p))
+/* Implemented as inline functions for the sake of type safety */
+static __inline void
+atomic_set_ptr(volatile void **p, void *v)
+{
+	atomic_set_int((volatile uintptr_t *)p, (uintptr_t)v);
+}
+
+static __inline void
+atomic_set_acq_ptr(volatile void **p, void *v)
+{
+	atomic_set_acq_int((volatile uintptr_t *)p, (uintptr_t)v);
+}
+
+static __inline void
+atomic_set_rel_ptr(volatile void **p, void *v)
+{
+	atomic_set_rel_int((volatile uintptr_t *)p, (uintptr_t)v);
+}
+
+static __inline void
+atomic_clear_ptr(volatile void **p, void *v)
+{
+	atomic_clear_int((volatile uintptr_t *)p, (uintptr_t)v);
+}
+
+static __inline void
+atomic_clear_acq_ptr(volatile void **p, void *v)
+{
+	atomic_clear_acq_int((volatile uintptr_t *)p, (uintptr_t)v);
+}
+
+static __inline void
+atomic_clear_rel_ptr(volatile void **p, void *v)
+{
+	atomic_clear_rel_int((volatile uintptr_t *)p, (uintptr_t)v);
+}
+
+static __inline void
+atomic_add_ptr(volatile void **p, void *v)
+{
+	atomic_add_int((volatile uintptr_t *)p, (uintptr_t)v);
+}
+
+static __inline void
+atomic_add_acq_ptr(volatile void **p, void *v)
+{
+	atomic_add_acq_int((volatile uintptr_t *)p, (uintptr_t)v);
+}
+
+static __inline void
+atomic_add_rel_ptr(volatile void **p, void *v)
+{
+	atomic_add_rel_int((volatile uintptr_t *)p, (uintptr_t)v);
+}
+
+static __inline void
+atomic_subtract_ptr(volatile void **p, void *v)
+{
+	atomic_subtract_int((volatile uintptr_t *)p, (uintptr_t)v);
+}
+
+static __inline void
+atomic_subtract_acq_ptr(volatile void **p, void *v)
+{
+	atomic_subtract_acq_int((volatile uintptr_t *)p, (uintptr_t)v);
+}
+
+static __inline void
+atomic_subtract_rel_ptr(volatile void **p, void *v)
+{
+	atomic_subtract_rel_int((volatile uintptr_t *)p, (uintptr_t)v);
+}
+
+static __inline void *
+atomic_load_acq_ptr(volatile void **p)
+{
+	return ((void *)(uintptr_t)atomic_load_acq_int((volatile uintptr_t *)p));
+}
+
+static __inline void
+atomic_store_rel_ptr(volatile void **p, void *v)
+{
+	atomic_store_rel_int((volatile uintptr_t *)p, (uintptr_t)v);
+}
+
+static __inline int
+atomic_cmpset_ptr(volatile void **dst, void *old, void *new)
+{
+	return (atomic_cmpset_int((volatile uintptr_t *)dst, (uintptr_t)old, (uintptr_t)new));
+}
+
+static __inline int
+atomic_cmpset_acq_ptr(volatile void **dst, void *old, void *new)
+{
+	return (atomic_cmpset_acq_int((volatile uintptr_t *)dst,
+	    (uintptr_t)old, (uintptr_t)new));
+}
+
+static __inline int
+atomic_cmpset_rel_ptr(volatile void **dst, void *old, void *new)
+{
+	return (atomic_cmpset_rel_int((volatile uintptr_t *)dst,
+	    (uintptr_t)old, (uintptr_t)new));
+}
+
+static __inline void *
+atomic_readandclear_ptr(volatile void **p)
+{
+	return ((void *)(uintptr_t)atomic_readandclear_int((volatile uintptr_t *)p));
+}
 
 #endif	/* !defined(WANT_FUNCTIONS) */
 #endif /* ! _MACHINE_ATOMIC_H_ */
_______________________________________________
cvs-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/cvs-all
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to