summaryrefslogtreecommitdiffstats
path: root/lib/libcompiler_rt/__sync_fetch_and_op_n.h
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2011-12-27 22:13:51 +0000
committered <ed@FreeBSD.org>2011-12-27 22:13:51 +0000
commit52306b41a65349c9fb64a1e03d2b593af6927dbd (patch)
tree55052b5fbd1048f4b1c9e2fdcd09939c5337b577 /lib/libcompiler_rt/__sync_fetch_and_op_n.h
parentc8ed04c26b6758354853a6bed4629f71d0d01a7d (diff)
downloadFreeBSD-src-52306b41a65349c9fb64a1e03d2b593af6927dbd.zip
FreeBSD-src-52306b41a65349c9fb64a1e03d2b593af6927dbd.tar.gz
Add locally implemented atomic intrinsics to libcompiler_rt.
The built-in atomic operations are not implemented in our version of GCC 4.2 for the ARM and MIPS architectures. Instead of emitting locked instructions, they generate calls to functions that can be implemented in the C runtime. Only implement the atomic operations that are used by <stdatomic.h> for datatype sizes that are supported by atomic(9). This means that on these architectures, we can only use atomic operations on 32-bits and 64-bits variables, which is typically sufficient. This makes <stdatomic.h> work on all architectures except MIPS, since MIPS and SPARC64 still use libgcc. Converting these architectures to libcompiler_rt is on my todo list.
Diffstat (limited to 'lib/libcompiler_rt/__sync_fetch_and_op_n.h')
-rw-r--r--lib/libcompiler_rt/__sync_fetch_and_op_n.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/libcompiler_rt/__sync_fetch_and_op_n.h b/lib/libcompiler_rt/__sync_fetch_and_op_n.h
new file mode 100644
index 0000000..f7f0e06
--- /dev/null
+++ b/lib/libcompiler_rt/__sync_fetch_and_op_n.h
@@ -0,0 +1,47 @@
+/*-
+ * Copyright (c) 2011 Ed Schouten <ed@FreeBSD.org>
+ * 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 THE 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>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <machine/atomic.h>
+
+TYPE
+NAME(volatile TYPE *ptr, TYPE value)
+{
+ TYPE t;
+
+#ifdef FETCHADD
+ t = FETCHADD(ptr, value);
+#else
+ do {
+ t = *ptr;
+ } while (!CMPSET(ptr, t, EXPRESSION));
+#endif
+
+ return (t);
+}
OpenPOWER on IntegriCloud