xref: /netbsd-src/common/lib/libc/arch/arm/atomic/atomic_simplelock.c (revision 034de21d59b241cd8d111961f092da3f164d35de)
148a38339Smatt /*-
248a38339Smatt  * Copyright (c) 2013 The NetBSD Foundation, Inc.
348a38339Smatt  * All rights reserved.
448a38339Smatt  *
548a38339Smatt  * This code is derived from software contributed to The NetBSD Foundation
648a38339Smatt  * by Matt Thomas of 3am Software Foundry.
748a38339Smatt  *
848a38339Smatt  * Redistribution and use in source and binary forms, with or without
948a38339Smatt  * modification, are permitted provided that the following conditions
1048a38339Smatt  * are met:
1148a38339Smatt  * 1. Redistributions of source code must retain the above copyright
1248a38339Smatt  *    notice, this list of conditions and the following disclaimer.
1348a38339Smatt  * 2. Redistributions in binary form must reproduce the above copyright
1448a38339Smatt  *    notice, this list of conditions and the following disclaimer in the
1548a38339Smatt  *    documentation and/or other materials provided with the distribution.
1648a38339Smatt  *
1748a38339Smatt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1848a38339Smatt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1948a38339Smatt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2048a38339Smatt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2148a38339Smatt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2248a38339Smatt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2348a38339Smatt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2448a38339Smatt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2548a38339Smatt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2648a38339Smatt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2748a38339Smatt  * POSSIBILITY OF SUCH DAMAGE.
2848a38339Smatt  */
2948a38339Smatt 
3048a38339Smatt #include <sys/cdefs.h>
31*034de21dSmatt __RCSID("$NetBSD: atomic_simplelock.c,v 1.2 2013/08/16 01:47:41 matt Exp $");
3248a38339Smatt 
3348a38339Smatt #include <sys/types.h>
34*034de21dSmatt 
35*034de21dSmatt #if !defined(_ARM_ARCH_T2)
3648a38339Smatt /*
3748a38339Smatt  * We need to use the inlines so redefine out of the way.
3848a38339Smatt  */
3948a38339Smatt #define	__cpu_simple_lock	__arm_simple_lock
4048a38339Smatt #define	__cpu_simple_lock_try	__arm_simple_lock_try
4148a38339Smatt #include <arm/lock.h>
4248a38339Smatt /*
4348a38339Smatt  * Now get rid of them.
4448a38339Smatt  */
4548a38339Smatt #undef __cpu_simple_lock
4648a38339Smatt #undef __cpu_simple_lock_try
4748a38339Smatt 
4848a38339Smatt /*
4948a38339Smatt  * Since we overrode lock.h we have to provide these ourselves.
5048a38339Smatt  */
51*034de21dSmatt #ifdef __LIBPTHREAD_SOURCE__
5248a38339Smatt __dso_hidden void __cpu_simple_lock(__cpu_simple_lock_t *);
5348a38339Smatt __dso_hidden int __cpu_simple_lock_try(__cpu_simple_lock_t *);
54*034de21dSmatt #else
55*034de21dSmatt void __cpu_simple_lock(__cpu_simple_lock_t *);
56*034de21dSmatt int __cpu_simple_lock_try(__cpu_simple_lock_t *);
57*034de21dSmatt #endif
5848a38339Smatt 
5948a38339Smatt void
__cpu_simple_lock(__cpu_simple_lock_t * alp)6048a38339Smatt __cpu_simple_lock(__cpu_simple_lock_t *alp)
6148a38339Smatt {
6248a38339Smatt 
6348a38339Smatt 	__arm_simple_lock(alp);
6448a38339Smatt }
6548a38339Smatt 
6648a38339Smatt int
__cpu_simple_lock_try(__cpu_simple_lock_t * alp)6748a38339Smatt __cpu_simple_lock_try(__cpu_simple_lock_t *alp)
6848a38339Smatt {
6948a38339Smatt 
7048a38339Smatt 	return __arm_simple_lock_try(alp);
7148a38339Smatt }
7248a38339Smatt #endif
73