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 Use atomics to manage fence->flags.



details:   https://anonhg.NetBSD.org/src/rev/a4c98496a433
branches:  trunk
changeset: 835238:a4c98496a433
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Aug 27 13:36:53 2018 +0000

description:
Use atomics to manage fence->flags.

Outside users use this field too, and expect it to be managed with
atomics.

diffstat:

 sys/external/bsd/drm2/include/linux/fence.h |   4 ++--
 sys/external/bsd/drm2/linux/linux_fence.c   |  16 +++++++++-------
 2 files changed, 11 insertions(+), 9 deletions(-)

diffs (71 lines):

diff -r 4bba710c965d -r a4c98496a433 sys/external/bsd/drm2/include/linux/fence.h
--- a/sys/external/bsd/drm2/include/linux/fence.h       Mon Aug 27 13:36:32 2018 +0000
+++ b/sys/external/bsd/drm2/include/linux/fence.h       Mon Aug 27 13:36:53 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fence.h,v 1.11 2018/08/27 13:33:59 riastradh Exp $     */
+/*     $NetBSD: fence.h,v 1.12 2018/08/27 13:36:53 riastradh Exp $     */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -46,7 +46,7 @@
 struct fence {
        struct kref             refcount;
        spinlock_t              *lock;
-       unsigned long           flags;
+       volatile unsigned long  flags;
        unsigned                context;
        unsigned                seqno;
        const struct fence_ops  *ops;
diff -r 4bba710c965d -r a4c98496a433 sys/external/bsd/drm2/linux/linux_fence.c
--- a/sys/external/bsd/drm2/linux/linux_fence.c Mon Aug 27 13:36:32 2018 +0000
+++ b/sys/external/bsd/drm2/linux/linux_fence.c Mon Aug 27 13:36:53 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux_fence.c,v 1.1 2018/08/27 13:33:59 riastradh Exp $        */
+/*     $NetBSD: linux_fence.c,v 1.2 2018/08/27 13:36:53 riastradh Exp $        */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,12 +30,13 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_fence.c,v 1.1 2018/08/27 13:33:59 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_fence.c,v 1.2 2018/08/27 13:36:53 riastradh Exp $");
 
 #include <sys/atomic.h>
 #include <sys/condvar.h>
 #include <sys/queue.h>
 
+#include <linux/atomic.h>
 #include <linux/errno.h>
 #include <linux/kref.h>
 #include <linux/fence.h>
@@ -191,12 +192,14 @@
        if (fence->flags & (1u << FENCE_FLAG_SIGNALED_BIT))
                return -ENOENT;
 
-       /* If the enable signalling callback has been called, success.  */
-       if (fence->flags & (1u << FENCE_FLAG_ENABLE_SIGNAL_BIT))
+       /*
+        * If the enable signaling callback has been called, success.
+        * Otherwise, set the bit indicating it.
+        */
+       if (test_and_set_bit(FENCE_FLAG_ENABLE_SIGNAL_BIT, &fence->flags))
                return 0;
 
        /* Otherwise, note that we've called it and call it.  */
-       fence->flags |= 1u << FENCE_FLAG_ENABLE_SIGNAL_BIT;
        if (!(*fence->ops->enable_signaling)(fence)) {
                /* If it failed, signal and return -ENOENT.  */
                fence_signal_locked(fence);
@@ -377,9 +380,8 @@
        KASSERT(spin_is_locked(fence->lock));
 
        /* If it's been signalled, fail; otherwise set the signalled bit.  */
-       if (fence->flags & (1u << FENCE_FLAG_SIGNALED_BIT))
+       if (test_and_set_bit(FENCE_FLAG_SIGNALED_BIT, &fence->flags))
                return -EINVAL;
-       fence->flags |= 1u << FENCE_FLAG_SIGNALED_BIT;
 
        /* Wake waiters.  */
        cv_broadcast(&fence->f_cv);



Home | Main Index | Thread Index | Old Index