atomic_store.c revision 1.4
11.4Sriastrad/*	$NetBSD: atomic_store.c,v 1.4 2022/04/09 23:38:57 riastradh Exp $	*/
21.1Sjoerg
31.1Sjoerg/*-
41.1Sjoerg * Copyright (c) 2014 The NetBSD Foundation, Inc.
51.1Sjoerg * All rights reserved.
61.1Sjoerg *
71.1Sjoerg * Redistribution and use in source and binary forms, with or without
81.1Sjoerg * modification, are permitted provided that the following conditions
91.1Sjoerg * are met:
101.1Sjoerg * 1. Redistributions of source code must retain the above copyright
111.1Sjoerg *    notice, this list of conditions and the following disclaimer.
121.1Sjoerg * 2. Redistributions in binary form must reproduce the above copyright
131.1Sjoerg *    notice, this list of conditions and the following disclaimer in the
141.1Sjoerg *    documentation and/or other materials provided with the distribution.
151.1Sjoerg *
161.1Sjoerg * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
171.1Sjoerg * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
181.1Sjoerg * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
191.1Sjoerg * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
201.1Sjoerg * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
211.1Sjoerg * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
221.1Sjoerg * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
231.1Sjoerg * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
241.1Sjoerg * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
251.1Sjoerg * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
261.1Sjoerg * POSSIBILITY OF SUCH DAMAGE.
271.1Sjoerg */
281.1Sjoerg
291.1Sjoerg#include <sys/cdefs.h>
301.4Sriastrad__RCSID("$NetBSD: atomic_store.c,v 1.4 2022/04/09 23:38:57 riastradh Exp $");
311.1Sjoerg
321.1Sjoerg#include "atomic_op_namespace.h"
331.1Sjoerg
341.1Sjoerg#include <sys/types.h>
351.1Sjoerg#include <sys/atomic.h>
361.1Sjoerg
371.1Sjoerg#define atomic_store_n(n,b) \
381.3Smrgvoid __atomic_store_ ## n(volatile void *, uint ## b ## _t, int); \
391.1Sjoergvoid \
401.3Smrg__atomic_store_ ## n(volatile void *ptr, uint ## b ## _t val, \
411.2Sjoerg                     int memmodel) \
421.1Sjoerg{ \
431.4Sriastrad	membar_release(); \
441.3Smrg	*(volatile uint ## b ## _t *)ptr = val; \
451.1Sjoerg}
461.1Sjoerg
471.1Sjoergatomic_store_n(1, 8)
481.1Sjoergatomic_store_n(2, 16)
491.1Sjoergatomic_store_n(4, 32)
501.1Sjoerg#ifdef	__HAVE_ATOMIC_CAS_64_UP
511.1Sjoergatomic_store_n(8, 64)
521.1Sjoerg#endif
53