1*de9cd3f9Smartin /* $NetBSD: atomic_cas_8_cas.c,v 1.3 2014/02/21 16:06:48 martin Exp $ */
2e39d980fSmartin
3e39d980fSmartin /*-
4e39d980fSmartin * Copyright (c) 2014 The NetBSD Foundation, Inc.
5e39d980fSmartin * All rights reserved.
6e39d980fSmartin *
7e39d980fSmartin * This code is derived from software contributed to The NetBSD Foundation
8e39d980fSmartin * by Jason R. Thorpe.
9e39d980fSmartin *
10e39d980fSmartin * Redistribution and use in source and binary forms, with or without
11e39d980fSmartin * modification, are permitted provided that the following conditions
12e39d980fSmartin * are met:
13e39d980fSmartin * 1. Redistributions of source code must retain the above copyright
14e39d980fSmartin * notice, this list of conditions and the following disclaimer.
15e39d980fSmartin * 2. Redistributions in binary form must reproduce the above copyright
16e39d980fSmartin * notice, this list of conditions and the following disclaimer in the
17e39d980fSmartin * documentation and/or other materials provided with the distribution.
18e39d980fSmartin *
19e39d980fSmartin * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20e39d980fSmartin * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21e39d980fSmartin * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22e39d980fSmartin * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23e39d980fSmartin * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24e39d980fSmartin * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25e39d980fSmartin * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26e39d980fSmartin * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27e39d980fSmartin * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28e39d980fSmartin * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29e39d980fSmartin * POSSIBILITY OF SUCH DAMAGE.
30e39d980fSmartin */
31e39d980fSmartin
32*de9cd3f9Smartin #include "atomic_op_namespace.h"
33*de9cd3f9Smartin
34e39d980fSmartin #if !defined(_KERNEL) && !defined(_STANDALONE)
35e39d980fSmartin #include <stdbool.h>
36e39d980fSmartin #endif
37e39d980fSmartin #include <sys/atomic.h>
38e39d980fSmartin
39e39d980fSmartin bool bool_compare_and_swap_1(volatile uint8_t *, uint8_t, uint8_t, ...)
40e39d980fSmartin asm("__sync_bool_compare_and_swap_1");
41e39d980fSmartin
42e39d980fSmartin bool
bool_compare_and_swap_1(volatile uint8_t * addr,uint8_t oldval,uint8_t newval,...)43e39d980fSmartin bool_compare_and_swap_1(volatile uint8_t *addr, uint8_t oldval,
44e39d980fSmartin uint8_t newval, ...)
45e39d980fSmartin {
46e39d980fSmartin return atomic_cas_8(addr, oldval, newval) == oldval;
47e39d980fSmartin }
48