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 Implement <linux/seqlock...



details:   https://anonhg.NetBSD.org/src/rev/0b6a4e4398c2
branches:  trunk
changeset: 1027806:0b6a4e4398c2
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Dec 19 00:47:40 2021 +0000

description:
Implement <linux/seqlock.h>.

diffstat:

 sys/external/bsd/drm2/include/linux/seqlock.h |  69 ++++++++++++++++++++++++++-
 1 files changed, 68 insertions(+), 1 deletions(-)

diffs (81 lines):

diff -r d88932908715 -r 0b6a4e4398c2 sys/external/bsd/drm2/include/linux/seqlock.h
--- a/sys/external/bsd/drm2/include/linux/seqlock.h     Sun Dec 19 00:47:32 2021 +0000
+++ b/sys/external/bsd/drm2/include/linux/seqlock.h     Sun Dec 19 00:47:40 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: seqlock.h,v 1.1 2021/12/19 00:28:12 riastradh Exp $    */
+/*     $NetBSD: seqlock.h,v 1.2 2021/12/19 00:47:40 riastradh Exp $    */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -32,4 +32,71 @@
 #ifndef        _LINUX_SEQLOCK_H_
 #define        _LINUX_SEQLOCK_H_
 
+#include <sys/types.h>
+#include <sys/atomic.h>
+#include <sys/lock.h>
+
+#include <lib/libkern/libkern.h>
+
+struct seqlock {
+       uint64_t        sql_gen;
+};
+
+typedef struct seqlock seqlock_t;
+
+static inline void
+seqlock_init(struct seqlock *seqlock)
+{
+
+       seqlock->sql_gen = 0;
+}
+
+static inline void
+write_seqlock(struct seqlock *seqlock)
+{
+
+       KASSERT((seqlock->sql_gen & 1) == 0);
+       seqlock->sql_gen |= 1;
+       membar_producer();
+}
+
+static inline void
+write_sequnlock(struct seqlock *seqlock)
+{
+
+       KASSERT((seqlock->sql_gen & 1) == 1);
+       membar_producer();
+       seqlock->sql_gen |= 1;  /* paraonia */
+       seqlock->sql_gen++;
+}
+
+#define        write_seqlock_irqsave(SEQLOCK, FLAGS)   do {                          \
+       (FLAGS) = (unsigned long)splvm();                                     \
+       write_seqlock(SEQLOCK);                                               \
+} while (0)
+
+#define        write_sequnlock_irqrestore(SEQLOCK, FLAGS)      do {                  \
+       write_seqlock(SEQLOCK);                                               \
+       splx((int)(FLAGS));                                                   \
+} while (0)
+
+static inline uint64_t
+read_seqbegin(struct seqlock *seqlock)
+{
+       uint64_t gen;
+
+       while ((gen = seqlock->sql_gen) & 1)
+               SPINLOCK_BACKOFF_HOOK;
+       membar_consumer();
+
+       return gen;
+}
+
+static inline bool
+read_seqretry(struct seqlock *seqlock, uint64_t gen)
+{
+
+       return gen != seqlock->sql_gen;
+}
+
 #endif /* _LINUX_SEQLOCK_H_ */



Home | Main Index | Thread Index | Old Index