Add a lockless uniprocessor version of atomic_cas_generic.c, which
is currently used by all the archs that previously used cas_generic.
This commit is contained in:
parent
d0e5481abd
commit
566f7922d9
@ -1,4 +1,4 @@
|
||||
# $NetBSD: Makefile.rumpkern,v 1.99 2010/11/21 17:34:11 pooka Exp $
|
||||
# $NetBSD: Makefile.rumpkern,v 1.100 2010/11/21 21:46:43 pooka Exp $
|
||||
#
|
||||
|
||||
.include "${RUMPTOP}/Makefile.rump"
|
||||
@ -167,13 +167,15 @@ KERNMISCCPPFLAGS+= -D_RUMPKERNEL
|
||||
# Some architectures require a little special massage with atomic
|
||||
# compare-and-swap. This is because the kernel version is using
|
||||
# instructions or routines unavailable to us in userspace. We
|
||||
# use effectively the multiprocessor version of the userspace ops.
|
||||
# use a very simple CAS routine which (correctly) assumes non-SMP
|
||||
# and no preemption. If some of these archs later develop MP
|
||||
# support, switch them to use atomic_cas_generic.c
|
||||
#
|
||||
.if ${MACHINE_CPU} == "arm" || ${MACHINE_CPU} == "hppa" \
|
||||
|| ${MACHINE_CPU} == "mips" || ${MACHINE_CPU} == "sh3" \
|
||||
|| ${MACHINE_CPU} == "vax" || ${MACHINE_ARCH} == "m68000"
|
||||
CPPFLAGS+= -I${RUMPTOP}/../../common/lib/libc/atomic
|
||||
SRCS+= atomic_cas_generic.c
|
||||
SRCS+= atomic_cas_up.c
|
||||
.endif
|
||||
|
||||
.include <bsd.lib.mk>
|
||||
|
60
sys/rump/librump/rumpkern/atomic_cas_up.c
Normal file
60
sys/rump/librump/rumpkern/atomic_cas_up.c
Normal file
@ -0,0 +1,60 @@
|
||||
/* $NetBSD: atomic_cas_up.c,v 1.1 2010/11/21 21:46:43 pooka Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2010 Antti Kantee. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: atomic_cas_up.c,v 1.1 2010/11/21 21:46:43 pooka Exp $");
|
||||
|
||||
/*
|
||||
* Uniprocessor version of atomic CAS. Since there is no preemption
|
||||
* in rump, this is a piece of cake.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
uint32_t rumpup_cas_32_up(volatile uint32_t *ptr, uint32_t, uint32_t);
|
||||
|
||||
uint32_t
|
||||
rumpup_cas_32_up(volatile uint32_t *ptr, uint32_t old, uint32_t new)
|
||||
{
|
||||
uint32_t ret;
|
||||
|
||||
ret = *ptr;
|
||||
if (__predict_true(ret == old)) {
|
||||
*ptr = new;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
__strong_alias(atomic_cas_32,rumpup_cas_32_up)
|
||||
__strong_alias(atomic_cas_uint,rumpup_cas_32_up)
|
||||
__strong_alias(atomic_cas_ulong,rumpup_cas_32_up)
|
||||
__strong_alias(atomic_cas_ptr,rumpup_cas_32_up)
|
||||
__strong_alias(atomic_cas_32_ni,rumpup_cas_32_up)
|
||||
__strong_alias(atomic_cas_uint_ni,rumpup_cas_32_up)
|
||||
__strong_alias(atomic_cas_ulong_ni,rumpup_cas_32_up)
|
||||
__strong_alias(atomic_cas_ptr_ni,rumpup_cas_32_up)
|
Loading…
Reference in New Issue
Block a user