11.3Smartin/* $NetBSD: atomic_cas_16_cas.c,v 1.3 2014/02/21 16:06:48 martin Exp $ */ 21.2Smartin 31.2Smartin/*- 41.2Smartin * Copyright (c) 2014 The NetBSD Foundation, Inc. 51.2Smartin * All rights reserved. 61.2Smartin * 71.2Smartin * This code is derived from software contributed to The NetBSD Foundation 81.2Smartin * by Jason R. Thorpe. 91.2Smartin * 101.2Smartin * Redistribution and use in source and binary forms, with or without 111.2Smartin * modification, are permitted provided that the following conditions 121.2Smartin * are met: 131.2Smartin * 1. Redistributions of source code must retain the above copyright 141.2Smartin * notice, this list of conditions and the following disclaimer. 151.2Smartin * 2. Redistributions in binary form must reproduce the above copyright 161.2Smartin * notice, this list of conditions and the following disclaimer in the 171.2Smartin * documentation and/or other materials provided with the distribution. 181.2Smartin * 191.2Smartin * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.2Smartin * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.2Smartin * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.2Smartin * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.2Smartin * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.2Smartin * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.2Smartin * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.2Smartin * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.2Smartin * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.2Smartin * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.2Smartin * POSSIBILITY OF SUCH DAMAGE. 301.2Smartin */ 311.2Smartin 321.3Smartin#include "atomic_op_namespace.h" 331.3Smartin 341.2Smartin#if !defined(_KERNEL) && !defined(_STANDALONE) 351.2Smartin#include <stdbool.h> 361.2Smartin#endif 371.2Smartin#include <sys/atomic.h> 381.2Smartin 391.2Smartinbool bool_compare_and_swap_2(volatile uint16_t *, uint16_t, uint16_t, ...) 401.2Smartin asm("__sync_bool_compare_and_swap_2"); 411.2Smartin 421.2Smartinbool 431.2Smartinbool_compare_and_swap_2(volatile uint16_t *addr, uint16_t oldval, 441.2Smartin uint16_t newval, ...) 451.2Smartin{ 461.2Smartin return atomic_cas_16(addr, oldval, newval) == oldval; 471.2Smartin} 48