Module Name: src
Committed By: pooka
Date: Tue Aug 10 18:17:12 UTC 2010
Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c
Log Message:
* use atomic ops instead of __cpu_simple_luck
* this interface is un-IFF_SIMPLEX
To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/rump/net/lib/libshmif/if_shmem.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.12 src/sys/rump/net/lib/libshmif/if_shmem.c:1.13
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.12 Thu Jul 29 22:48:11 2010
+++ src/sys/rump/net/lib/libshmif/if_shmem.c Tue Aug 10 18:17:12 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: if_shmem.c,v 1.12 2010/07/29 22:48:11 pooka Exp $ */
+/* $NetBSD: if_shmem.c,v 1.13 2010/08/10 18:17:12 pooka Exp $ */
/*
* Copyright (c) 2009 Antti Kantee. All Rights Reserved.
@@ -28,9 +28,10 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.12 2010/07/29 22:48:11 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.13 2010/08/10 18:17:12 pooka Exp $");
#include <sys/param.h>
+#include <sys/atomic.h>
#include <sys/fcntl.h>
#include <sys/kmem.h>
#include <sys/kthread.h>
@@ -89,6 +90,9 @@
static uint32_t numif;
+#define LOCK_UNLOCKED 0
+#define LOCK_LOCKED 1
+
/*
* This locking needs work and will misbehave severely if:
* 1) the backing memory has to be paged in
@@ -98,14 +102,20 @@
lockbus(struct shmif_sc *sc)
{
- __cpu_simple_lock((__cpu_simple_lock_t *)sc->sc_busmem);
+ while (atomic_cas_uint((void *)sc->sc_busmem,
+ LOCK_UNLOCKED, LOCK_LOCKED) == LOCK_LOCKED)
+ continue;
+ membar_enter();
}
static void
unlockbus(struct shmif_sc *sc)
{
+ unsigned int old;
- __cpu_simple_unlock((__cpu_simple_lock_t *)sc->sc_busmem);
+ membar_exit();
+ old = atomic_swap_uint((void *)sc->sc_busmem, LOCK_UNLOCKED);
+ KASSERT(old == LOCK_LOCKED);
}
static uint32_t
@@ -221,7 +231,7 @@
sprintf(ifp->if_xname, "shmif%d", mynum);
ifp->if_softc = sc;
- ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
+ ifp->if_flags = IFF_BROADCAST | IFF_MULTICAST;
ifp->if_init = shmif_init;
ifp->if_ioctl = shmif_ioctl;
ifp->if_start = shmif_start;