Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/riastradh-drm2]: src/sys/external/bsd/drm2/include/linux Fix Linux atomi...



details:   https://anonhg.NetBSD.org/src/rev/14193c134869
branches:  riastradh-drm2
changeset: 788512:14193c134869
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Sep 08 15:37:04 2013 +0000

description:
Fix Linux atomic set/clear/change_bit to work on arrays.

diffstat:

 sys/external/bsd/drm2/include/linux/atomic.h |  50 +++++++++++++++++++--------
 1 files changed, 34 insertions(+), 16 deletions(-)

diffs (103 lines):

diff -r d6d333c98b68 -r 14193c134869 sys/external/bsd/drm2/include/linux/atomic.h
--- a/sys/external/bsd/drm2/include/linux/atomic.h      Sun Sep 08 15:36:35 2013 +0000
+++ b/sys/external/bsd/drm2/include/linux/atomic.h      Sun Sep 08 15:37:04 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: atomic.h,v 1.1.2.9 2013/07/24 03:35:50 riastradh Exp $ */
+/*     $NetBSD: atomic.h,v 1.1.2.10 2013/09/08 15:37:04 riastradh Exp $        */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -34,6 +34,8 @@
 
 #include <sys/atomic.h>
 
+#include <machine/limits.h>
+
 struct atomic {
        union {
                int au_int;
@@ -125,53 +127,69 @@
 }
 
 static inline void
-set_bit(unsigned long bit, volatile unsigned long *ptr)
+set_bit(unsigned int bit, volatile unsigned long *ptr)
 {
-       atomic_or_ulong(ptr, (1 << bit));
+       const unsigned int units = (sizeof(*ptr) * CHAR_BIT);
+
+       atomic_or_ulong(&ptr[bit / units], (1UL << (bit % units)));
 }
 
 static inline void
-clear_bit(unsigned long bit, volatile unsigned long *ptr)
+clear_bit(unsigned int bit, volatile unsigned long *ptr)
 {
-       atomic_and_ulong(ptr, ~(1 << bit));
+       const unsigned int units = (sizeof(*ptr) * CHAR_BIT);
+
+       atomic_and_ulong(&ptr[bit / units], ~(1UL << (bit % units)));
 }
 
 static inline void
-change_bit(unsigned long bit, volatile unsigned long *ptr)
+change_bit(unsigned int bit, volatile unsigned long *ptr)
 {
+       const unsigned int units = (sizeof(*ptr) * CHAR_BIT);
+       volatile unsigned long *const p = &ptr[bit / units];
+       const unsigned long mask = (1UL << (bit % units));
        unsigned long v;
 
-       do v = *ptr; while (atomic_cas_ulong(ptr, v, v ^ (1 << bit)) != v);
+       do v = *p; while (atomic_cas_ulong(p, v, (v ^ mask)) != v);
 }
 
 static inline unsigned long
-test_and_set_bit(unsigned long bit, volatile unsigned long *ptr)
+test_and_set_bit(unsigned int bit, volatile unsigned long *ptr)
 {
+       const unsigned int units = (sizeof(*ptr) * CHAR_BIT);
+       volatile unsigned long *const p = &ptr[bit / units];
+       const unsigned long mask = (1UL << (bit % units));
        unsigned long v;
 
-       do v = *ptr; while (atomic_cas_ulong(ptr, v, v | (1 << bit)) != v);
+       do v = *p; while (atomic_cas_ulong(p, v, (v | mask)) != v);
 
-       return (v & (1 << bit));
+       return (v & mask);
 }
 
 static inline unsigned long
-test_and_clear_bit(unsigned long bit, volatile unsigned long *ptr)
+test_and_clear_bit(unsigned int bit, volatile unsigned long *ptr)
 {
+       const unsigned int units = (sizeof(*ptr) * CHAR_BIT);
+       volatile unsigned long *const p = &ptr[bit / units];
+       const unsigned long mask = (1UL << (bit % units));
        unsigned long v;
 
-       do v = *ptr; while (atomic_cas_ulong(ptr, v, v &~ (1 << bit)) != v);
+       do v = *p; while (atomic_cas_ulong(p, v, (v & ~mask)) != v);
 
-       return (v & (1 << bit));
+       return (v & mask);
 }
 
 static inline unsigned long
-test_and_change_bit(unsigned long bit, volatile unsigned long *ptr)
+test_and_change_bit(unsigned int bit, volatile unsigned long *ptr)
 {
+       const unsigned int units = (sizeof(*ptr) * CHAR_BIT);
+       volatile unsigned long *const p = &ptr[bit / units];
+       const unsigned long mask = (1UL << (bit % units));
        unsigned long v;
 
-       do v = *ptr; while (atomic_cas_ulong(ptr, v, v ^ (1 << bit)) != v);
+       do v = *p; while (atomic_cas_ulong(p, v, (v ^ mask)) != v);
 
-       return (v & (1 << bit));
+       return (v & mask);
 }
 
 #if defined(MULTIPROCESSOR) && !defined(__HAVE_ATOMIC_AS_MEMBAR)



Home | Main Index | Thread Index | Old Index