Source-Changes-HG archive

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

[src/trunk]: src/sys/external/bsd/drm2/include/linux Add non-atomic Linux tes...



details:   https://anonhg.NetBSD.org/src/rev/8ed0e79b4444
branches:  trunk
changeset: 797430:8ed0e79b4444
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Thu Jul 17 14:28:28 2014 +0000

description:
Add non-atomic Linux test-and-set operations.

diffstat:

 sys/external/bsd/drm2/include/linux/bitops.h |  44 +++++++++++++++++++++++++++-
 1 files changed, 43 insertions(+), 1 deletions(-)

diffs (58 lines):

diff -r f99bd3929bce -r 8ed0e79b4444 sys/external/bsd/drm2/include/linux/bitops.h
--- a/sys/external/bsd/drm2/include/linux/bitops.h      Thu Jul 17 14:07:44 2014 +0000
+++ b/sys/external/bsd/drm2/include/linux/bitops.h      Thu Jul 17 14:28:28 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bitops.h,v 1.4 2014/07/16 20:59:58 riastradh Exp $     */
+/*     $NetBSD: bitops.h,v 1.5 2014/07/17 14:28:28 riastradh Exp $     */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -97,6 +97,48 @@
 }
 
 static inline unsigned long
+__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;
+
+       v = *p;
+       *p |= mask;
+
+       return (v & mask);
+}
+
+static inline unsigned long
+__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;
+
+       v = *p;
+       *p &= ~mask;
+
+       return (v & mask);
+}
+
+static inline unsigned long
+__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;
+
+       v = *p;
+       *p ^= mask;
+
+       return (v & mask);
+}
+
+static inline unsigned long
 find_first_zero_bit(const unsigned long *ptr, unsigned long nbits)
 {
        const size_t bpl = (CHAR_BIT * sizeof(*ptr));



Home | Main Index | Thread Index | Old Index