Replace arch specific atomic.h with global atomic.h header using either stdatomic, __atomic or __sync primitives
This commit is contained in:
@@ -19,7 +19,6 @@ VERSION=@BIND9_VERSION@
|
||||
|
||||
CINCLUDES = -I${srcdir}/unix/include \
|
||||
-I${srcdir}/pthreads/include \
|
||||
-I${srcdir}/@ISC_ARCH_DIR@/include \
|
||||
-I./include \
|
||||
-I${srcdir}/include ${DNS_INCLUDES} @OPENSSL_INCLUDES@
|
||||
CDEFINES =
|
||||
@@ -83,7 +82,7 @@ LIBS = @OPENSSL_LIBS@ @LIBS@
|
||||
# Attempt to disable parallel processing.
|
||||
.NOTPARALLEL:
|
||||
.NO_PARALLEL:
|
||||
SUBDIRS = include unix nls pthreads @ISC_ARCH_DIR@
|
||||
SUBDIRS = include unix nls pthreads
|
||||
TARGETS = timestamp
|
||||
TESTDIRS = @UNITTESTS@
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
SUBDIRS = include
|
||||
TARGETS =
|
||||
|
||||
@BIND9_MAKE_RULES@
|
||||
@@ -1,17 +0,0 @@
|
||||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
SUBDIRS = isc
|
||||
TARGETS =
|
||||
|
||||
@BIND9_MAKE_RULES@
|
||||
@@ -1,34 +0,0 @@
|
||||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
VERSION=@BIND9_VERSION@
|
||||
|
||||
HEADERS = atomic.h
|
||||
|
||||
SUBDIRS =
|
||||
TARGETS =
|
||||
|
||||
@BIND9_MAKE_RULES@
|
||||
|
||||
installdirs:
|
||||
$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${includedir}/isc
|
||||
|
||||
install:: installdirs
|
||||
for i in ${HEADERS}; do \
|
||||
${INSTALL_DATA} $(srcdir)/$$i ${DESTDIR}${includedir}/isc ; \
|
||||
done
|
||||
|
||||
uninstall::
|
||||
for i in ${HEADERS}; do \
|
||||
rm -f ${DESTDIR}${includedir}/isc/$$i ; \
|
||||
done
|
||||
@@ -1,120 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* This code was written based on FreeBSD's kernel source whose copyright
|
||||
* follows:
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1998 Doug Rabson
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD: src/sys/alpha/include/atomic.h,v 1.18.6.1 2004/09/13 21:52:04 wilko Exp $
|
||||
*/
|
||||
|
||||
#ifndef ISC_ATOMIC_H
|
||||
#define ISC_ATOMIC_H 1
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <isc/platform.h>
|
||||
#include <isc/types.h>
|
||||
|
||||
#if defined (ISC_PLATFORM_USEGCCASM)
|
||||
static inline int32_t
|
||||
isc_atomic_xadd(int32_t *p, int32_t val) {
|
||||
int32_t temp, prev;
|
||||
|
||||
__asm__ volatile(
|
||||
"mb;"
|
||||
"1:"
|
||||
"ldl_l %0, %1;" /* load old value */
|
||||
"mov %0, %2;" /* copy the old value */
|
||||
"addl %0, %3, %0;" /* calculate new value */
|
||||
"stl_c %0, %1;" /* attempt to store */
|
||||
"beq %0, 1b;" /* spin if failed */
|
||||
"mb;"
|
||||
: "=&r"(temp), "+m"(*p), "=&r"(prev)
|
||||
: "r"(val)
|
||||
: "memory");
|
||||
|
||||
return (prev);
|
||||
}
|
||||
|
||||
static inline void
|
||||
isc_atomic_store(int32_t *p, int32_t val) {
|
||||
int32_t temp;
|
||||
|
||||
__asm__ volatile(
|
||||
"mb;"
|
||||
"1:"
|
||||
"ldl_l %0, %1;" /* load old value */
|
||||
"mov %2, %0;" /* value to store */
|
||||
"stl_c %0, %1;" /* attempt to store */
|
||||
"beq %0, 1b;" /* if it failed, spin */
|
||||
"mb;"
|
||||
: "=&r"(temp), "+m"(*p)
|
||||
: "r"(val)
|
||||
: "memory");
|
||||
}
|
||||
|
||||
static inline int32_t
|
||||
isc_atomic_cmpxchg(int32_t *p, int32_t cmpval, int32_t val) {
|
||||
int32_t temp, prev;
|
||||
|
||||
__asm__ volatile(
|
||||
"mb;"
|
||||
"1:"
|
||||
"ldl_l %0, %1;" /* load old value */
|
||||
"mov %0, %2;" /* copy the old value */
|
||||
"cmpeq %0, %3, %0;" /* compare */
|
||||
"beq %0, 2f;" /* exit if not equal */
|
||||
"mov %4, %0;" /* value to store */
|
||||
"stl_c %0, %1;" /* attempt to store */
|
||||
"beq %0, 1b;" /* if it failed, spin */
|
||||
"2:"
|
||||
"mb;"
|
||||
: "=&r"(temp), "+m"(*p), "=&r"(prev)
|
||||
: "r"(cmpval), "r"(val)
|
||||
: "memory");
|
||||
|
||||
return (prev);
|
||||
}
|
||||
#else
|
||||
|
||||
#error "unsupported compiler. disable atomic ops by --disable-atomic"
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* ISC_ATOMIC_H */
|
||||
@@ -1,17 +0,0 @@
|
||||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
SUBDIRS = include
|
||||
TARGETS =
|
||||
|
||||
@BIND9_MAKE_RULES@
|
||||
@@ -1,17 +0,0 @@
|
||||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
SUBDIRS = isc
|
||||
TARGETS =
|
||||
|
||||
@BIND9_MAKE_RULES@
|
||||
@@ -1,34 +0,0 @@
|
||||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
VERSION=@BIND9_VERSION@
|
||||
|
||||
HEADERS = atomic.h
|
||||
|
||||
SUBDIRS =
|
||||
TARGETS =
|
||||
|
||||
@BIND9_MAKE_RULES@
|
||||
|
||||
installdirs:
|
||||
$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${includedir}/isc
|
||||
|
||||
install:: installdirs
|
||||
for i in ${HEADERS}; do \
|
||||
${INSTALL_DATA} $(srcdir)/$$i ${DESTDIR}${includedir}/isc ; \
|
||||
done
|
||||
|
||||
uninstall::
|
||||
for i in ${HEADERS}; do \
|
||||
rm -f ${DESTDIR}${includedir}/isc/$$i ; \
|
||||
done
|
||||
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ISC_ATOMIC_H
|
||||
#define ISC_ATOMIC_H 1
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <isc/platform.h>
|
||||
#include <isc/types.h>
|
||||
|
||||
#ifdef ISC_PLATFORM_USEGCCASM
|
||||
/*
|
||||
* This routine atomically increments the value stored in 'p' by 'val', and
|
||||
* returns the previous value.
|
||||
*
|
||||
* Open issue: can 'fetchadd' make the code faster for some particular values
|
||||
* (e.g., 1 and -1)?
|
||||
*/
|
||||
static inline int32_t
|
||||
#ifdef __GNUC__
|
||||
__attribute__ ((unused))
|
||||
#endif
|
||||
isc_atomic_xadd(int32_t *p, int32_t val)
|
||||
{
|
||||
int32_t prev, swapped;
|
||||
|
||||
for (prev = *(volatile int32_t *)p; ; prev = swapped) {
|
||||
swapped = prev + val;
|
||||
__asm__ volatile(
|
||||
"mov ar.ccv=%2;;"
|
||||
"cmpxchg4.acq %0=%4,%3,ar.ccv"
|
||||
: "=r" (swapped), "=m" (*p)
|
||||
: "r" (prev), "r" (swapped), "m" (*p)
|
||||
: "memory");
|
||||
if (swapped == prev)
|
||||
break;
|
||||
}
|
||||
|
||||
return (prev);
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine atomically stores the value 'val' in 'p'.
|
||||
*/
|
||||
static inline void
|
||||
#ifdef __GNUC__
|
||||
__attribute__ ((unused))
|
||||
#endif
|
||||
isc_atomic_store(int32_t *p, int32_t val)
|
||||
{
|
||||
__asm__ volatile(
|
||||
"st4.rel %0=%1"
|
||||
: "=m" (*p)
|
||||
: "r" (val)
|
||||
: "memory"
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine atomically replaces the value in 'p' with 'val', if the
|
||||
* original value is equal to 'cmpval'. The original value is returned in any
|
||||
* case.
|
||||
*/
|
||||
static inline int32_t
|
||||
#ifdef __GNUC__
|
||||
__attribute__ ((unused))
|
||||
#endif
|
||||
isc_atomic_cmpxchg(int32_t *p, int32_t cmpval, int32_t val)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
__asm__ volatile(
|
||||
"mov ar.ccv=%2;;"
|
||||
"cmpxchg4.acq %0=%4,%3,ar.ccv"
|
||||
: "=r" (ret), "=m" (*p)
|
||||
: "r" (cmpval), "r" (val), "m" (*p)
|
||||
: "memory");
|
||||
|
||||
return (ret);
|
||||
}
|
||||
#else /* !ISC_PLATFORM_USEGCCASM */
|
||||
|
||||
#error "unsupported compiler. disable atomic ops by --disable-atomic"
|
||||
|
||||
#endif
|
||||
#endif /* ISC_ATOMIC_H */
|
||||
@@ -18,7 +18,7 @@ VERSION=@BIND9_VERSION@
|
||||
# machine generated. The latter are handled specially in the
|
||||
# install target below.
|
||||
#
|
||||
HEADERS = aes.h app.h assertions.h backtrace.h base32.h base64.h \
|
||||
HEADERS = aes.h app.h assertions.h atomic.h backtrace.h base32.h base64.h \
|
||||
bind9.h buffer.h bufferlist.h \
|
||||
commandline.h counter.h crc64.h deprecated.h \
|
||||
errno.h error.h event.h eventclass.h \
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef ISC_ATOMIC_H
|
||||
#define ISC_ATOMIC_H 1
|
||||
|
||||
/* This file is inherently empty. */
|
||||
|
||||
#endif /* ISC_ATOMIC_H */
|
||||
#if HAVE_STDATOMIC_H
|
||||
#include <stdatomic.h>
|
||||
#else
|
||||
#include <isc/stdatomic.h>
|
||||
#endif
|
||||
146
lib/isc/include/isc/stdatomic.h
Normal file
146
lib/isc/include/isc/stdatomic.h
Normal file
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !defined(__has_feature)
|
||||
#define __has_feature(x) 0
|
||||
#endif
|
||||
|
||||
#if !defined(__has_extension)
|
||||
#define __has_extension(x) __has_feature(x)
|
||||
#endif
|
||||
|
||||
#if !defined(__GNUC_PREREQ__)
|
||||
#if defined(__GNUC__) && defined(__GNUC_MINOR__)
|
||||
#define __GNUC_PREREQ__(maj, min) \
|
||||
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
|
||||
#else
|
||||
#define __GNUC_PREREQ__(maj, min) 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(__CLANG_ATOMICS) && !defined(__GNUC_ATOMICS)
|
||||
#if __has_extension(c_atomic) || __has_extension(cxx_atomic)
|
||||
#define __CLANG_ATOMICS
|
||||
#elif __GNUC_PREREQ__(4, 7)
|
||||
#define __GNUC_ATOMICS
|
||||
#elif !defined(__GNUC__)
|
||||
#error "isc/stdatomic.h does not support your compiler"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef __ATOMIC_RELAXED
|
||||
#define __ATOMIC_RELAXED 0
|
||||
#endif
|
||||
#ifndef __ATOMIC_CONSUME
|
||||
#define __ATOMIC_CONSUME 1
|
||||
#endif
|
||||
#ifndef __ATOMIC_ACQUIRE
|
||||
#define __ATOMIC_ACQUIRE 2
|
||||
#endif
|
||||
#ifndef __ATOMIC_RELEASE
|
||||
#define __ATOMIC_RELEASE 3
|
||||
#endif
|
||||
#ifndef __ATOMIC_ACQ_REL
|
||||
#define __ATOMIC_ACQ_REL 4
|
||||
#endif
|
||||
#ifndef __ATOMIC_SEQ_CST
|
||||
#define __ATOMIC_SEQ_CST 5
|
||||
#endif
|
||||
|
||||
|
||||
enum memory_order {
|
||||
memory_order_relaxed = __ATOMIC_RELAXED,
|
||||
memory_order_consume = __ATOMIC_CONSUME,
|
||||
memory_order_acquire = __ATOMIC_ACQUIRE,
|
||||
memory_order_release = __ATOMIC_RELEASE,
|
||||
memory_order_acq_rel = __ATOMIC_ACQ_REL,
|
||||
memory_order_seq_cst = __ATOMIC_SEQ_CST
|
||||
};
|
||||
|
||||
typedef enum memory_order memory_order;
|
||||
|
||||
typedef int_fast32_t atomic_int_fast32_t;
|
||||
typedef uint_fast32_t atomic_uint_fast32_t;
|
||||
typedef int_fast64_t atomic_int_fast64_t;
|
||||
typedef uint_fast64_t atomic_uint_fast64_t;
|
||||
|
||||
#if defined(__CLANG_ATOMICS) /* __c11_atomic builtins */
|
||||
#define atomic_init(obj, desired) \
|
||||
__c11_atomic_init(obj, desired)
|
||||
#define atomic_load_explicit(obj, order) \
|
||||
__c11_atomic_load(obj, order)
|
||||
#define atomic_store_explicit(obj, desired, order) \
|
||||
__c11_atomic_store(obj, desired, order)
|
||||
#define atomic_fetch_add_explicit(obj, arg, order) \
|
||||
__c11_atomic_fetch_add(obj, arg, order)
|
||||
#define atomic_fetch_sub_explicit(obj, arg, order) \
|
||||
__c11_atomic_fetch_sub(obj, arg, order)
|
||||
#define atomic_compare_exchange_strong_explicit(obj, expected, desired, succ, fail) \
|
||||
__c11_atomic_compare_exchange_strong_explicit(obj, expected, desired, succ, fail)
|
||||
#define atomic_compare_exchange_weak_explicit(obj, expected, desired, succ, fail) \
|
||||
__c11_atomic_compare_exchange_weak_explicit(obj, expected, desired, succ, fail)
|
||||
#elif defined(__GNUC_ATOMICS) /* __atomic builtins */
|
||||
#define atomic_init(obj, desired) \
|
||||
(*obj = desired)
|
||||
#define atomic_load_explicit(obj, order) \
|
||||
__atomic_load_n(obj, order)
|
||||
#define atomic_store_explicit(obj, desired, order) \
|
||||
__atomic_store_n(obj, desired, order)
|
||||
#define atomic_fetch_add_explicit(obj, arg, order) \
|
||||
__atomic_fetch_add(obj, arg, order)
|
||||
#define atomic_fetch_sub_explicit(obj, arg, order) \
|
||||
__atomic_fetch_sub(obj, arg, order)
|
||||
#define atomic_compare_exchange_strong_explicit(obj, expected, desired, succ, fail) \
|
||||
__atomic_compare_exchange_n(obj, expected, desired, 0, succ, fail)
|
||||
#define atomic_compare_exchange_weak_explicit(obj, expected, desired, succ, fail) \
|
||||
__atomic_compare_exchange_n(obj, expected, desired, 1, succ, fail)
|
||||
#else /* __sync builtins */
|
||||
#define atomic_init(obj, desired) \
|
||||
(*obj = desired)
|
||||
#define atomic_load_explicit(obj, order) \
|
||||
__sync_fetch_and_add(obj, 0)
|
||||
#define atomic_store_explicit(obj, desired, order) \
|
||||
do { \
|
||||
__sync_synchronize(); \
|
||||
*obj = desired; \
|
||||
__sync_synchronize(); \
|
||||
} while (0);
|
||||
#define atomic_fetch_add_explicit(obj, arg, order) \
|
||||
__sync_fetch_and_add(obj, arg)
|
||||
#define atomic_fetch_sub_explicit(obj, arg, order) \
|
||||
__sync_fetch_and_sub(obj, arg, order)
|
||||
#define atomic_compare_exchange_strong_explicit(obj, expected, desired, succ, fail) \
|
||||
({ \
|
||||
__typeof__(obj) __v; \
|
||||
_Bool __r; \
|
||||
__v = __sync_val_compare_and_swap(obj, *(expected), desired); \
|
||||
__r = *(expected) == __v; \
|
||||
*(expected) = __v; \
|
||||
__r; \
|
||||
})
|
||||
#define atomic_compare_exchange_weak_explicit(obj, expected, desired, succ, fail) \
|
||||
atomic_compare_exchange_strong_explicit(obj, expected, desired, succ, fail)
|
||||
#endif
|
||||
|
||||
#define atomic_load(obj) \
|
||||
atomic_load_explicit(obj, memory_order_seq_cst)
|
||||
#define atomic_store(obj) \
|
||||
atomic_store_explicit(obj, memory_order_seq_cst)
|
||||
#define atomic_fetch_add(obj) \
|
||||
atomic_fetch_add_explicit(obj, arg, memory_order_seq_cst)
|
||||
#define atomic_fetch_sub(obj) \
|
||||
atomic_fetch_sub_explicit(obj, arg, memory_order_seq_cst)
|
||||
#define atomic_compare_exchange_strong(obj, expected, desired) \
|
||||
atomic_compare_exchange_strong_explicit(obj, expected, desired, memory_order_seq_cst, memory_order_seq_cst)
|
||||
#define atomic_compare_exchange_weak(obj, expected, desired) \
|
||||
atomic_compare_exchange_weak_explicit(obj, expected, desired, memory_order_seq_cst, memory_order_seq_cst)
|
||||
@@ -1,17 +0,0 @@
|
||||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
SUBDIRS = include
|
||||
TARGETS =
|
||||
|
||||
@BIND9_MAKE_RULES@
|
||||
@@ -1,17 +0,0 @@
|
||||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
SUBDIRS = isc
|
||||
TARGETS =
|
||||
|
||||
@BIND9_MAKE_RULES@
|
||||
@@ -1,34 +0,0 @@
|
||||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
VERSION=@BIND9_VERSION@
|
||||
|
||||
HEADERS = atomic.h
|
||||
|
||||
SUBDIRS =
|
||||
TARGETS =
|
||||
|
||||
@BIND9_MAKE_RULES@
|
||||
|
||||
installdirs:
|
||||
$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${includedir}/isc
|
||||
|
||||
install:: installdirs
|
||||
for i in ${HEADERS}; do \
|
||||
${INSTALL_DATA} $(srcdir)/$$i ${DESTDIR}${includedir}/isc ; \
|
||||
done
|
||||
|
||||
uninstall::
|
||||
for i in ${HEADERS}; do \
|
||||
rm -f ${DESTDIR}${includedir}/isc/$$i ; \
|
||||
done
|
||||
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ISC_ATOMIC_H
|
||||
#define ISC_ATOMIC_H 1
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <isc/platform.h>
|
||||
#include <isc/types.h>
|
||||
|
||||
#ifdef ISC_PLATFORM_USEGCCASM
|
||||
/*
|
||||
* This routine atomically increments the value stored in 'p' by 'val', and
|
||||
* returns the previous value.
|
||||
*/
|
||||
static inline int32_t
|
||||
isc_atomic_xadd(int32_t *p, int val) {
|
||||
int32_t orig;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
" .set push \n"
|
||||
" .set mips2 \n"
|
||||
" .set noreorder \n"
|
||||
" .set noat \n"
|
||||
"1: ll $1, %1 \n"
|
||||
" addu %0, $1, %2 \n"
|
||||
" sc %0, %1 \n"
|
||||
" beqz %0, 1b \n"
|
||||
" move %0, $1 \n"
|
||||
" .set pop \n"
|
||||
: "=&r" (orig), "+R" (*p)
|
||||
: "r" (val)
|
||||
: "memory");
|
||||
|
||||
return (orig);
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine atomically stores the value 'val' in 'p'.
|
||||
*/
|
||||
static inline void
|
||||
isc_atomic_store(int32_t *p, int32_t val) {
|
||||
*p = val;
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine atomically replaces the value in 'p' with 'val', if the
|
||||
* original value is equal to 'cmpval'. The original value is returned in any
|
||||
* case.
|
||||
*/
|
||||
static inline int32_t
|
||||
isc_atomic_cmpxchg(int32_t *p, int cmpval, int val) {
|
||||
int32_t orig;
|
||||
int32_t tmp;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
" .set push \n"
|
||||
" .set mips2 \n"
|
||||
" .set noreorder \n"
|
||||
" .set noat \n"
|
||||
"1: ll $1, %1 \n"
|
||||
" bne $1, %3, 2f \n"
|
||||
" move %2, %4 \n"
|
||||
" sc %2, %1 \n"
|
||||
" beqz %2, 1b \n"
|
||||
"2: move %0, $1 \n"
|
||||
" .set pop \n"
|
||||
: "=&r"(orig), "+R" (*p), "=r" (tmp)
|
||||
: "r"(cmpval), "r"(val)
|
||||
: "memory");
|
||||
|
||||
return (orig);
|
||||
}
|
||||
|
||||
#else /* !ISC_PLATFORM_USEGCCASM */
|
||||
|
||||
#error "unsupported compiler. disable atomic ops by --disable-atomic"
|
||||
|
||||
#endif
|
||||
#endif /* ISC_ATOMIC_H */
|
||||
@@ -1,17 +0,0 @@
|
||||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
SUBDIRS = include
|
||||
TARGETS =
|
||||
|
||||
@BIND9_MAKE_RULES@
|
||||
@@ -1,17 +0,0 @@
|
||||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
SUBDIRS = isc
|
||||
TARGETS =
|
||||
|
||||
@BIND9_MAKE_RULES@
|
||||
@@ -1,34 +0,0 @@
|
||||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
VERSION=@BIND9_VERSION@
|
||||
|
||||
HEADERS = atomic.h
|
||||
|
||||
SUBDIRS =
|
||||
TARGETS =
|
||||
|
||||
@BIND9_MAKE_RULES@
|
||||
|
||||
installdirs:
|
||||
$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${includedir}/isc
|
||||
|
||||
install:: installdirs
|
||||
for i in ${HEADERS}; do \
|
||||
${INSTALL_DATA} $(srcdir)/$$i ${DESTDIR}${includedir}/isc ; \
|
||||
done
|
||||
|
||||
uninstall::
|
||||
for i in ${HEADERS}; do \
|
||||
rm -f ${DESTDIR}${includedir}/isc/$$i ; \
|
||||
done
|
||||
@@ -1,17 +0,0 @@
|
||||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
SUBDIRS = include
|
||||
TARGETS =
|
||||
|
||||
@BIND9_MAKE_RULES@
|
||||
@@ -1,17 +0,0 @@
|
||||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
SUBDIRS = isc
|
||||
TARGETS =
|
||||
|
||||
@BIND9_MAKE_RULES@
|
||||
@@ -1,34 +0,0 @@
|
||||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
VERSION=@BIND9_VERSION@
|
||||
|
||||
HEADERS = atomic.h
|
||||
|
||||
SUBDIRS =
|
||||
TARGETS =
|
||||
|
||||
@BIND9_MAKE_RULES@
|
||||
|
||||
installdirs:
|
||||
$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${includedir}/isc
|
||||
|
||||
install:: installdirs
|
||||
for i in ${HEADERS}; do \
|
||||
${INSTALL_DATA} $(srcdir)/$$i ${DESTDIR}${includedir}/isc ; \
|
||||
done
|
||||
|
||||
uninstall::
|
||||
for i in ${HEADERS}; do \
|
||||
rm -f ${DESTDIR}${includedir}/isc/$$i ; \
|
||||
done
|
||||
@@ -1,137 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ISC_ATOMIC_H
|
||||
#define ISC_ATOMIC_H 1
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <isc/platform.h>
|
||||
#include <isc/types.h>
|
||||
|
||||
/*!\file
|
||||
* static inline int32_t
|
||||
* isc_atomic_xadd(int32_t *p, int32_t val);
|
||||
*
|
||||
* This routine atomically increments the value stored in 'p' by 'val', and
|
||||
* returns the previous value.
|
||||
*
|
||||
* static inline void
|
||||
* isc_atomic_store(void *p, int32_t val);
|
||||
*
|
||||
* This routine atomically stores the value 'val' in 'p'.
|
||||
*
|
||||
* static inline int32_t
|
||||
* isc_atomic_cmpxchg(int32_t *p, int32_t cmpval, int32_t val);
|
||||
*
|
||||
* This routine atomically replaces the value in 'p' with 'val', if the
|
||||
* original value is equal to 'cmpval'. The original value is returned in any
|
||||
* case.
|
||||
*/
|
||||
|
||||
#if defined(ISC_PLATFORM_USEGCCASM) || defined(ISC_PLATFORM_USEMACASM)
|
||||
static inline int32_t
|
||||
isc_atomic_xadd(int32_t *p, int32_t val) {
|
||||
int32_t orig;
|
||||
|
||||
__asm__ volatile (
|
||||
#ifdef ISC_PLATFORM_USEMACASM
|
||||
"1:"
|
||||
"lwarx r6, 0, %1\n"
|
||||
"mr %0, r6\n"
|
||||
"add r6, r6, %2\n"
|
||||
"stwcx. r6, 0, %1\n"
|
||||
"bne- 1b\n"
|
||||
"sync"
|
||||
#else
|
||||
"1:"
|
||||
"lwarx 6, 0, %1\n"
|
||||
"mr %0, 6\n"
|
||||
"add 6, 6, %2\n"
|
||||
"stwcx. 6, 0, %1\n"
|
||||
"bne- 1b\n"
|
||||
"sync"
|
||||
#endif
|
||||
: "=&r"(orig)
|
||||
: "r"(p), "r"(val)
|
||||
: "r6", "memory"
|
||||
);
|
||||
|
||||
return (orig);
|
||||
}
|
||||
|
||||
static inline void
|
||||
isc_atomic_store(void *p, int32_t val) {
|
||||
__asm__ volatile (
|
||||
#ifdef ISC_PLATFORM_USEMACASM
|
||||
"1:"
|
||||
"lwarx r6, 0, %0\n"
|
||||
"lwz r6, %1\n"
|
||||
"stwcx. r6, 0, %0\n"
|
||||
"bne- 1b\n"
|
||||
"sync"
|
||||
#else
|
||||
"1:"
|
||||
"lwarx 6, 0, %0\n"
|
||||
"lwz 6, %1\n"
|
||||
"stwcx. 6, 0, %0\n"
|
||||
"bne- 1b\n"
|
||||
"sync"
|
||||
#endif
|
||||
:
|
||||
: "r"(p), "m"(val)
|
||||
: "r6", "memory"
|
||||
);
|
||||
}
|
||||
|
||||
static inline int32_t
|
||||
isc_atomic_cmpxchg(int32_t *p, int32_t cmpval, int32_t val) {
|
||||
int32_t orig;
|
||||
|
||||
__asm__ volatile (
|
||||
#ifdef ISC_PLATFORM_USEMACASM
|
||||
"1:"
|
||||
"lwarx r6, 0, %1\n"
|
||||
"mr %0,r6\n"
|
||||
"cmpw r6, %2\n"
|
||||
"bne 2f\n"
|
||||
"mr r6, %3\n"
|
||||
"stwcx. r6, 0, %1\n"
|
||||
"bne- 1b\n"
|
||||
"2:\n"
|
||||
"sync"
|
||||
#else
|
||||
"1:"
|
||||
"lwarx 6, 0, %1\n"
|
||||
"mr %0,6\n"
|
||||
"cmpw 6, %2\n"
|
||||
"bne 2f\n"
|
||||
"mr 6, %3\n"
|
||||
"stwcx. 6, 0, %1\n"
|
||||
"bne- 1b\n"
|
||||
"2:\n"
|
||||
"sync"
|
||||
#endif
|
||||
: "=&r" (orig)
|
||||
: "r"(p), "r"(cmpval), "r"(val)
|
||||
: "r6", "memory"
|
||||
);
|
||||
|
||||
return (orig);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#error "unsupported compiler. disable atomic ops by --disable-atomic"
|
||||
|
||||
#endif
|
||||
#endif /* ISC_ATOMIC_H */
|
||||
@@ -1,17 +0,0 @@
|
||||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
SUBDIRS = include
|
||||
TARGETS =
|
||||
|
||||
@BIND9_MAKE_RULES@
|
||||
@@ -1,17 +0,0 @@
|
||||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
SUBDIRS = isc
|
||||
TARGETS =
|
||||
|
||||
@BIND9_MAKE_RULES@
|
||||
@@ -1,29 +0,0 @@
|
||||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
VERSION=@BIND9_VERSION@
|
||||
|
||||
HEADERS = atomic.h
|
||||
|
||||
SUBDIRS =
|
||||
TARGETS =
|
||||
|
||||
@BIND9_MAKE_RULES@
|
||||
|
||||
installdirs:
|
||||
$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${includedir}/isc
|
||||
|
||||
install:: installdirs
|
||||
for i in ${HEADERS}; do \
|
||||
${INSTALL_DATA} $(srcdir)/$$i ${DESTDIR}${includedir}/isc ; \
|
||||
done
|
||||
@@ -1,122 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* This code was written based on FreeBSD's kernel source whose copyright
|
||||
* follows:
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1998 Doug Rabson.
|
||||
* Copyright (c) 2001 Jake Burkholder.
|
||||
* 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.
|
||||
*
|
||||
* from: FreeBSD: src/sys/i386/include/atomic.h,v 1.20 2001/02/11
|
||||
* $FreeBSD: src/sys/sparc64/include/atomic.h,v 1.8 2004/05/22 00:52:16 marius Exp $
|
||||
*/
|
||||
|
||||
#ifndef ISC_ATOMIC_H
|
||||
#define ISC_ATOMIC_H 1
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <isc/platform.h>
|
||||
#include <isc/types.h>
|
||||
|
||||
#define ASI_P 0x80 /* Primary Address Space Identifier */
|
||||
|
||||
#ifdef ISC_PLATFORM_USEGCCASM
|
||||
|
||||
/*
|
||||
* This routine atomically increments the value stored in 'p' by 'val', and
|
||||
* returns the previous value.
|
||||
*/
|
||||
static inline int32_t
|
||||
isc_atomic_xadd(int32_t *p, int32_t val) {
|
||||
int32_t prev, swapped;
|
||||
|
||||
for (prev = *(volatile int32_t *)p; ; prev = swapped) {
|
||||
swapped = prev + val;
|
||||
__asm__ volatile(
|
||||
"casa [%2] %3, %4, %0"
|
||||
: "+r"(swapped), "=m"(*p)
|
||||
: "r"(p), "n"(ASI_P), "r"(prev), "m"(*p));
|
||||
if (swapped == prev)
|
||||
break;
|
||||
}
|
||||
|
||||
return (prev);
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine atomically stores the value 'val' in 'p'.
|
||||
*/
|
||||
static inline void
|
||||
isc_atomic_store(int32_t *p, int32_t val) {
|
||||
int32_t prev, swapped;
|
||||
|
||||
for (prev = *(volatile int32_t *)p; ; prev = swapped) {
|
||||
swapped = val;
|
||||
__asm__ volatile(
|
||||
"casa [%2] %3, %4, %0"
|
||||
: "+r"(swapped), "=m"(*p)
|
||||
: "r"(p), "n"(ASI_P), "r"(prev), "m"(*p));
|
||||
if (swapped == prev)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine atomically replaces the value in 'p' with 'val', if the
|
||||
* original value is equal to 'cmpval'. The original value is returned in any
|
||||
* case.
|
||||
*/
|
||||
static inline int32_t
|
||||
isc_atomic_cmpxchg(int32_t *p, int32_t cmpval, int32_t val) {
|
||||
int32_t temp = val;
|
||||
|
||||
__asm__ volatile(
|
||||
"casa [%2] %3, %4, %0"
|
||||
: "+r"(temp), "=m"(*p)
|
||||
: "r"(p), "n"(ASI_P), "r"(cmpval), "m"(*p));
|
||||
|
||||
return (temp);
|
||||
}
|
||||
|
||||
#else /* ISC_PLATFORM_USEGCCASM */
|
||||
|
||||
#error "unsupported compiler. disable atomic ops by --disable-atomic"
|
||||
|
||||
#endif /* ISC_PLATFORM_USEGCCASM */
|
||||
|
||||
#endif /* ISC_ATOMIC_H */
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ISC_ATOMIC_H
|
||||
#define ISC_ATOMIC_H 1
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <isc/platform.h>
|
||||
#include <isc/types.h>
|
||||
|
||||
/*
|
||||
* This routine atomically increments the value stored in 'p' by 'val', and
|
||||
* returns the previous value.
|
||||
*/
|
||||
#ifdef ISC_PLATFORM_HAVEXADD
|
||||
static __inline int32_t
|
||||
isc_atomic_xadd(int32_t *p, int32_t val) {
|
||||
return (int32_t) _InterlockedExchangeAdd((long *)p, (long)val);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ISC_PLATFORM_HAVEXADDQ
|
||||
static __inline int64_t
|
||||
isc_atomic_xaddq(int64_t *p, int64_t val) {
|
||||
return (int64_t) _InterlockedExchangeAdd64((__int64 *)p,
|
||||
(__int64) val);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This routine atomically stores the value 'val' in 'p' (32-bit version).
|
||||
*/
|
||||
#ifdef ISC_PLATFORM_HAVEATOMICSTORE
|
||||
static __inline void
|
||||
isc_atomic_store(int32_t *p, int32_t val) {
|
||||
(void) _InterlockedExchange((long *)p, (long)val);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This routine atomically stores the value 'val' in 'p' (64-bit version).
|
||||
*/
|
||||
#ifdef ISC_PLATFORM_HAVEATOMICSTOREQ
|
||||
static __inline void
|
||||
isc_atomic_storeq(int64_t *p, int64_t val) {
|
||||
(void) _InterlockedExchange64((__int64 *)p, (__int64)val);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This routine atomically replaces the value in 'p' with 'val', if the
|
||||
* original value is equal to 'cmpval'. The original value is returned in any
|
||||
* case.
|
||||
*/
|
||||
#ifdef ISC_PLATFORM_HAVECMPXCHG
|
||||
static __inline int32_t
|
||||
isc_atomic_cmpxchg(int32_t *p, int32_t cmpval, int32_t val) {
|
||||
/* beware: swap arguments */
|
||||
return (int32_t) _InterlockedCompareExchange((long *)p,
|
||||
(long)val,
|
||||
(long)cmpval);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ISC_ATOMIC_H */
|
||||
260
lib/isc/win32/include/isc/stdatomic.h
Normal file
260
lib/isc/win32/include/isc/stdatomic.h
Normal file
@@ -0,0 +1,260 @@
|
||||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <isc/util.h>
|
||||
|
||||
#ifndef __ATOMIC_RELAXED
|
||||
#define __ATOMIC_RELAXED 0
|
||||
#endif
|
||||
#ifndef __ATOMIC_CONSUME
|
||||
#define __ATOMIC_CONSUME 1
|
||||
#endif
|
||||
#ifndef __ATOMIC_ACQUIRE
|
||||
#define __ATOMIC_ACQUIRE 2
|
||||
#endif
|
||||
#ifndef __ATOMIC_RELEASE
|
||||
#define __ATOMIC_RELEASE 3
|
||||
#endif
|
||||
#ifndef __ATOMIC_ACQ_REL
|
||||
#define __ATOMIC_ACQ_REL 4
|
||||
#endif
|
||||
#ifndef __ATOMIC_SEQ_CST
|
||||
#define __ATOMIC_SEQ_CST 5
|
||||
#endif
|
||||
|
||||
enum memory_order {
|
||||
memory_order_relaxed = __ATOMIC_RELAXED,
|
||||
memory_order_consume = __ATOMIC_CONSUME,
|
||||
memory_order_acquire = __ATOMIC_ACQUIRE,
|
||||
memory_order_release = __ATOMIC_RELEASE,
|
||||
memory_order_acq_rel = __ATOMIC_ACQ_REL,
|
||||
memory_order_seq_cst = __ATOMIC_SEQ_CST
|
||||
};
|
||||
|
||||
typedef enum memory_order memory_order;
|
||||
|
||||
typedef int_fast32_t volatile atomic_int_fast32_t;
|
||||
typedef uint_fast32_t volatile atomic_uint_fast32_t;
|
||||
typedef int_fast64_t volatile atomic_int_fast64_t;
|
||||
typedef uint_fast64_t volatile atomic_uint_fast64_t;
|
||||
|
||||
#define atomic_init(obj, desired) \
|
||||
(*(obj) = (desired))
|
||||
|
||||
#define atomic_store_explicit32(obj, desired, order) \
|
||||
(order == memory_order_relaxed \
|
||||
? InterlockedExchangeNoFence((atomic_int_fast32_t *)obj, desired) \
|
||||
: (order == memory_order_acquire \
|
||||
? InterlockedExchangeAcquire((atomic_int_fast32_t *)obj, desired) \
|
||||
: InterlockedExchange((atomic_int_fast32_t *)obj, desired)))
|
||||
|
||||
#define atomic_store_explicit64(obj, desired, order) \
|
||||
(order == memory_order_relaxed \
|
||||
? InterlockedExchangeNoFence64((atomic_int_fast64_t *)obj, desired) \
|
||||
: (order == memory_order_acquire \
|
||||
? InterlockedExchangeAcquire64((atomic_int_fast64_t *)obj, desired) \
|
||||
: InterlockedExchange64((atomic_int_fast64_t *)obj, desired)))
|
||||
|
||||
static inline
|
||||
void
|
||||
atomic_store_abort() {
|
||||
INSIST(0);
|
||||
return;
|
||||
}
|
||||
|
||||
#define atomic_store_explicit(obj, desired, order) \
|
||||
(sizeof(*obj) == 8 \
|
||||
? atomic_store_explicit64(obj, desired, order) \
|
||||
: (sizeof(*obj) == 4 \
|
||||
? atomic_store_explicit32(obj, desired, order) \
|
||||
: atomic_store_abort()))
|
||||
|
||||
#define atomic_store(obj, desired) \
|
||||
atomic_store(obj, desider, memory_order_seq_cst)
|
||||
|
||||
#define atomic_load_explicit32(obj, order) \
|
||||
(order == memory_order_relaxed \
|
||||
? (int32_t)InterlockedOrNoFence((atomic_int_fast32_t *)obj, 0) \
|
||||
: (order == memory_order_acquire \
|
||||
? (int32_t)InterlockedOrAcquire((atomic_int_fast32_t *)obj, 0) \
|
||||
: (order == memory_order_release \
|
||||
? (int32_t)InterlockedOrRelease((atomic_int_fast32_t *)obj, 0) \
|
||||
: (int32_t)InterlockedOr((atomic_int_fast32_t *)obj, 0))))
|
||||
|
||||
#define atomic_load_explicit64(obj, order) \
|
||||
(order == memory_order_relaxed \
|
||||
? InterlockedOr64NoFence((atomic_int_fast64_t *)obj, 0) \
|
||||
: (order == memory_order_acquire \
|
||||
? InterlockedOr64Acquire((atomic_int_fast64_t *)obj, 0) \
|
||||
: (order == memory_order_release \
|
||||
? InterlockedOr64Release((atomic_int_fast64_t *)obj, 0) \
|
||||
: InterlockedOr64((atomic_int_fast64_t *)obj, 0))))
|
||||
|
||||
static inline
|
||||
int8_t
|
||||
atomic_load_abort() {
|
||||
INSIST(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
#define atomic_load_explicit(obj, order) \
|
||||
(sizeof(*obj) == 8 \
|
||||
? atomic_load_explicit64(obj, order) \
|
||||
: (sizeof(*obj == 4) \
|
||||
? atomic_load_explicit32(obj, order) \
|
||||
: atomic_load_abort()))
|
||||
|
||||
#define atomic_load(obj) \
|
||||
atomic_load_explicit(obj, memory_order_seq_cst)
|
||||
|
||||
#define atomic_fetch_add_explicit32(obj, arg, order) \
|
||||
(order == memory_order_relaxed \
|
||||
? InterlockedExchangeAddNoFence((atomic_int_fast32_t *)obj, arg) \
|
||||
: (order == memory_order_acquire \
|
||||
? InterlockedExchangeAddAcquire((atomic_int_fast32_t *)obj, arg) \
|
||||
: (order == memory_order_release \
|
||||
? InterlockedExchangeAddRelease((atomic_int_fast32_t *)obj, arg) \
|
||||
: InterlockedExchange((atomic_int_fast32_t *)obj, arg))))
|
||||
|
||||
#define atomic_fetch_add_explicit64(obj, arg, order) \
|
||||
(order == memory_order_relaxed \
|
||||
? InterlockedExchangeAddNoFence64((atomic_int_fast64_t *)obj, arg) \
|
||||
: (order == memory_order_acquire \
|
||||
? InterlockedExchangeAddAcquire64((atomic_int_fast64_t *)obj, arg) \
|
||||
: (order == memory_order_release \
|
||||
? InterlockedExchangeAddRelease64((atomic_int_fast64_t *)obj, arg) \
|
||||
: InterlockedExchange64((atomic_int_fast64_t *)obj, arg))))
|
||||
|
||||
static inline
|
||||
int8_t
|
||||
atomic_add_abort() {
|
||||
INSIST(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
#define atomic_fetch_add_explicit(obj, arg, order) \
|
||||
(sizeof(*obj) == 8 \
|
||||
? atomic_fetch_add_explicit64(obj, arg, order) \
|
||||
: (sizeof(*obj) == 4 \
|
||||
? atomic_fetch_add_explicit32(obj, arg, order) \
|
||||
: atomic_add_abort()))
|
||||
|
||||
#define atomic_fetch_add(obj, arg) \
|
||||
atomic_fetch_add_explicit(obj, arg, memory_order_seq_cst)
|
||||
|
||||
#define atomic_fetch_sub_explicit(obj, arg, order) \
|
||||
atomic_fetch_add_explicit(obj, -arg, order)
|
||||
|
||||
#define atomic_fetch_sub(obj, arg) \
|
||||
atomic_fetch_sub_explicit(obj, arg, memory_order_seq_cst)
|
||||
|
||||
static inline bool
|
||||
atomic_compare_exchange_strong_explicit32(atomic_int_fast32_t *obj,
|
||||
int32_t *expected,
|
||||
int32_t desired,
|
||||
memory_order succ,
|
||||
memory_order fail) {
|
||||
bool __r;
|
||||
int32_t __v;
|
||||
REQUIRE(succ == fail);
|
||||
switch (succ) {
|
||||
case memory_order_relaxed:
|
||||
__v = InterlockedCompareExchangeNoFence((atomic_int_fast32_t *)obj, desired, *expected);
|
||||
break;
|
||||
case memory_order_acquire:
|
||||
__v = InterlockedCompareExchangeAcquire((atomic_int_fast32_t *)obj, desired, *expected);
|
||||
break;
|
||||
case memory_order_release:
|
||||
__v = InterlockedCompareExchangeRelease((atomic_int_fast32_t *)obj, desired, *expected);
|
||||
break;
|
||||
default:
|
||||
__v = InterlockedCompareExchange((atomic_int_fast32_t *)obj, desired, *expected);
|
||||
break;
|
||||
}
|
||||
__r = (*(expected) == __v);
|
||||
if (!__r) {
|
||||
*(expected) = __v;
|
||||
}
|
||||
return (__r);
|
||||
}
|
||||
|
||||
static inline bool
|
||||
atomic_compare_exchange_strong_explicit64(atomic_int_fast64_t *obj,
|
||||
int64_t *expected,
|
||||
int64_t desired,
|
||||
memory_order succ,
|
||||
memory_order fail) {
|
||||
bool __r;
|
||||
int64_t __v;
|
||||
REQUIRE(succ == fail);
|
||||
switch (succ) {
|
||||
case memory_order_relaxed:
|
||||
__v = InterlockedCompareExchange64NoFence((atomic_int_fast64_t *)obj, desired, *expected);
|
||||
break;
|
||||
case memory_order_acquire:
|
||||
__v = InterlockedCompareExchange64Acquire((atomic_int_fast64_t *)obj, desired, *expected);
|
||||
break;
|
||||
case memory_order_release:
|
||||
__v = InterlockedCompareExchange64Release((atomic_int_fast64_t *)obj, desired, *expected);
|
||||
break;
|
||||
default:
|
||||
__v = InterlockedCompareExchange64((atomic_int_fast64_t *)obj, desired, *expected);
|
||||
break;
|
||||
}
|
||||
__r = (*(expected) == __v);
|
||||
if (!__r) {
|
||||
*(expected) = __v;
|
||||
}
|
||||
return (__r);
|
||||
}
|
||||
|
||||
static inline
|
||||
bool
|
||||
atomic_compare_exchange_abort() {
|
||||
INSIST(0);
|
||||
return (false);
|
||||
}
|
||||
|
||||
#define atomic_compare_exchange_strong_explicit(obj, expected, desired, \
|
||||
succ, fail) \
|
||||
(sizeof(*obj) == 8 \
|
||||
? atomic_compare_exchange_strong_explicit64(obj, expected, \
|
||||
desired, \
|
||||
succ, fail) \
|
||||
: (sizeof(*obj) == 4 \
|
||||
? atomic_compare_exchange_strong_explicit32(obj, expected, \
|
||||
desired, \
|
||||
succ, fail) \
|
||||
: atomic_compare_exchange_abort()))
|
||||
|
||||
#define atomic_compare_exchange_strong(obj, expected, desired, \
|
||||
succ, fail) \
|
||||
atomic_compare_exchange_strong_explicit(obj, expected, desired, \
|
||||
memory_order_cst_seq, \
|
||||
memory_order_cst_seq)
|
||||
|
||||
#define atomic_compare_exchange_weak_explicit(obj, expected, desired, \
|
||||
succ, fail) \
|
||||
atomic_compare_exchange_strong_explicit(obj, expected, desired, \
|
||||
succ, fail)
|
||||
|
||||
#define atomic_compare_exchange_weak(obj, expected, desired) \
|
||||
atomic_compare_exchange_weak_explicit(obj, expected, desired, \
|
||||
memory_order_cst_seq, \
|
||||
memory_order_cst_seq)
|
||||
@@ -35,6 +35,9 @@
|
||||
<ClInclude Include="..\include\isc\assertions.h">
|
||||
<Filter>Library Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\isc\atomic.h">
|
||||
<Filter>Library Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\isc\backtrace.h">
|
||||
<Filter>Library Header Files</Filter>
|
||||
</ClInclude>
|
||||
@@ -340,6 +343,9 @@
|
||||
<ClInclude Include="include\isc\stat.h">
|
||||
<Filter>Win32 Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\isc\stdatomic.h">
|
||||
<Filter>Win32 Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\isc\stdtime.h">
|
||||
<Filter>Win32 Header Files</Filter>
|
||||
</ClInclude>
|
||||
@@ -378,13 +384,6 @@
|
||||
<Filter>Win32 Header Files</Filter>
|
||||
</ClInclude>
|
||||
@END PKCS11
|
||||
@IF ATOMIC
|
||||
<ClInclude Include="include\isc\atomic.h">
|
||||
@ELSE ATOMIC
|
||||
<ClInclude Include="..\noatomic\include\isc\atomic.h">
|
||||
@END ATOMIC
|
||||
<Filter>Library Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\config.h">
|
||||
<Filter>Library Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
||||
@@ -293,6 +293,7 @@ copy InstallFiles ..\Build\Release\
|
||||
<ClInclude Include="..\include\isc\aes.h" />
|
||||
<ClInclude Include="..\include\isc\app.h" />
|
||||
<ClInclude Include="..\include\isc\assertions.h" />
|
||||
<ClInclude Include="..\include\isc\atomic.h" />
|
||||
<ClInclude Include="..\include\isc\backtrace.h" />
|
||||
<ClInclude Include="..\include\isc\base32.h" />
|
||||
<ClInclude Include="..\include\isc\base64.h" />
|
||||
@@ -381,11 +382,6 @@ copy InstallFiles ..\Build\Release\
|
||||
<ClInclude Include="..\include\pkcs11\pkcs11f.h" />
|
||||
<ClInclude Include="..\include\pkcs11\pkcs11t.h" />
|
||||
@END PKCS11
|
||||
@IF ATOMIC
|
||||
<ClInclude Include="include\isc\atomic.h" />
|
||||
@ELSE ATOMIC
|
||||
<ClInclude Include="..\noatomic\include\isc\atomic.h" />
|
||||
@END ATOMIC
|
||||
<ClInclude Include="errno2result.h" />
|
||||
<ClInclude Include="include\isc\bindevt.h" />
|
||||
<ClInclude Include="include\isc\bind_registry.h" />
|
||||
@@ -402,6 +398,7 @@ copy InstallFiles ..\Build\Release\
|
||||
<ClInclude Include="include\isc\once.h" />
|
||||
<ClInclude Include="include\isc\platform.h" />
|
||||
<ClInclude Include="include\isc\stat.h" />
|
||||
<ClInclude Include="include\isc\stdatomic.h" />
|
||||
<ClInclude Include="include\isc\stdtime.h" />
|
||||
<ClInclude Include="include\isc\strerror.h" />
|
||||
<ClInclude Include="include\isc\syslog.h" />
|
||||
@@ -409,7 +406,7 @@ copy InstallFiles ..\Build\Release\
|
||||
<ClInclude Include="include\isc\time.h" />
|
||||
<ClInclude Include="include\isc\win32os.h" />
|
||||
<ClInclude Include="../entropy_private.h" />
|
||||
<ClInclude Include="../openssl_shim.h" />
|
||||
<ClInclude Include="../openssl_shim.h" />
|
||||
<ClInclude Include="syslog.h" />
|
||||
<ClInclude Include="unistd.h" />
|
||||
@IF PKCS11
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
SUBDIRS = include
|
||||
TARGETS =
|
||||
|
||||
@BIND9_MAKE_RULES@
|
||||
@@ -1,17 +0,0 @@
|
||||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
SUBDIRS = isc
|
||||
TARGETS =
|
||||
|
||||
@BIND9_MAKE_RULES@
|
||||
@@ -1,34 +0,0 @@
|
||||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
VERSION=@BIND9_VERSION@
|
||||
|
||||
HEADERS = atomic.h
|
||||
|
||||
SUBDIRS =
|
||||
TARGETS =
|
||||
|
||||
@BIND9_MAKE_RULES@
|
||||
|
||||
installdirs:
|
||||
$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${includedir}/isc
|
||||
|
||||
install:: installdirs
|
||||
for i in ${HEADERS}; do \
|
||||
${INSTALL_DATA} $(srcdir)/$$i ${DESTDIR}${includedir}/isc ; \
|
||||
done
|
||||
|
||||
uninstall::
|
||||
for i in ${HEADERS}; do \
|
||||
rm -f ${DESTDIR}${includedir}/isc/$$i ; \
|
||||
done
|
||||
@@ -1,176 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ISC_ATOMIC_H
|
||||
#define ISC_ATOMIC_H 1
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <isc/platform.h>
|
||||
#include <isc/types.h>
|
||||
|
||||
#ifdef ISC_PLATFORM_USEGCCASM
|
||||
/*
|
||||
* This routine atomically increments the value stored in 'p' by 'val', and
|
||||
* returns the previous value.
|
||||
*/
|
||||
static __inline__ int32_t
|
||||
isc_atomic_xadd(int32_t *p, int32_t val) {
|
||||
int32_t prev = val;
|
||||
|
||||
__asm__ volatile(
|
||||
"lock;"
|
||||
"xadd %0, %1"
|
||||
:"=q"(prev)
|
||||
:"m"(*p), "0"(prev)
|
||||
:"memory", "cc");
|
||||
|
||||
return (prev);
|
||||
}
|
||||
|
||||
#ifdef ISC_PLATFORM_HAVEXADDQ
|
||||
static __inline__ int64_t
|
||||
isc_atomic_xaddq(int64_t *p, int64_t val) {
|
||||
int64_t prev = val;
|
||||
|
||||
__asm__ volatile(
|
||||
"lock;"
|
||||
"xaddq %0, %1"
|
||||
:"=q"(prev)
|
||||
:"m"(*p), "0"(prev)
|
||||
:"memory", "cc");
|
||||
|
||||
return (prev);
|
||||
}
|
||||
#endif /* ISC_PLATFORM_HAVEXADDQ */
|
||||
|
||||
/*
|
||||
* This routine atomically stores the value 'val' in 'p' (32-bit version).
|
||||
*/
|
||||
static __inline__ void
|
||||
isc_atomic_store(int32_t *p, int32_t val) {
|
||||
__asm__ volatile(
|
||||
/*
|
||||
* xchg should automatically lock memory, but we add it
|
||||
* explicitly just in case (it at least doesn't harm)
|
||||
*/
|
||||
"lock;"
|
||||
|
||||
"xchgl %1, %0"
|
||||
:
|
||||
: "r"(val), "m"(*p)
|
||||
: "memory");
|
||||
}
|
||||
|
||||
#ifdef ISC_PLATFORM_HAVEATOMICSTOREQ
|
||||
/*
|
||||
* This routine atomically stores the value 'val' in 'p' (64-bit version).
|
||||
*/
|
||||
static __inline__ void
|
||||
isc_atomic_storeq(int64_t *p, int64_t val) {
|
||||
__asm__ volatile(
|
||||
/*
|
||||
* xchg should automatically lock memory, but we add it
|
||||
* explicitly just in case (it at least doesn't harm)
|
||||
*/
|
||||
"lock;"
|
||||
|
||||
"xchgq %1, %0"
|
||||
:
|
||||
: "r"(val), "m"(*p)
|
||||
: "memory");
|
||||
}
|
||||
#endif /* ISC_PLATFORM_HAVEATOMICSTOREQ */
|
||||
|
||||
/*
|
||||
* This routine atomically replaces the value in 'p' with 'val', if the
|
||||
* original value is equal to 'cmpval'. The original value is returned in any
|
||||
* case.
|
||||
*/
|
||||
static __inline__ int32_t
|
||||
isc_atomic_cmpxchg(int32_t *p, int32_t cmpval, int32_t val) {
|
||||
__asm__ volatile(
|
||||
"lock;"
|
||||
"cmpxchgl %1, %2"
|
||||
: "=a"(cmpval)
|
||||
: "r"(val), "m"(*p), "a"(cmpval)
|
||||
: "memory");
|
||||
|
||||
return (cmpval);
|
||||
}
|
||||
|
||||
#elif defined(ISC_PLATFORM_USESTDASM)
|
||||
/*
|
||||
* The followings are "generic" assembly code which implements the same
|
||||
* functionality in case the gcc extension cannot be used. It should be
|
||||
* better to avoid inlining below, since we directly refer to specific
|
||||
* positions of the stack frame, which would not actually point to the
|
||||
* intended address in the embedded mnemonic.
|
||||
*/
|
||||
static int32_t
|
||||
isc_atomic_xadd(int32_t *p, int32_t val) {
|
||||
(void)(p);
|
||||
(void)(val);
|
||||
|
||||
__asm (
|
||||
"movl 8(%ebp), %ecx\n"
|
||||
"movl 12(%ebp), %edx\n"
|
||||
"lock;"
|
||||
"xadd %edx, (%ecx)\n"
|
||||
|
||||
/*
|
||||
* set the return value directly in the register so that we
|
||||
* can avoid guessing the correct position in the stack for a
|
||||
* local variable.
|
||||
*/
|
||||
"movl %edx, %eax"
|
||||
);
|
||||
}
|
||||
|
||||
static void
|
||||
isc_atomic_store(int32_t *p, int32_t val) {
|
||||
(void)(p);
|
||||
(void)(val);
|
||||
|
||||
__asm (
|
||||
"movl 8(%ebp), %ecx\n"
|
||||
"movl 12(%ebp), %edx\n"
|
||||
"lock;"
|
||||
"xchgl (%ecx), %edx\n"
|
||||
);
|
||||
}
|
||||
|
||||
static int32_t
|
||||
isc_atomic_cmpxchg(int32_t *p, int32_t cmpval, int32_t val) {
|
||||
(void)(p);
|
||||
(void)(cmpval);
|
||||
(void)(val);
|
||||
|
||||
__asm (
|
||||
"movl 8(%ebp), %ecx\n"
|
||||
"movl 12(%ebp), %eax\n" /* must be %eax for cmpxchgl */
|
||||
"movl 16(%ebp), %edx\n"
|
||||
"lock;"
|
||||
|
||||
/*
|
||||
* If (%ecx) == %eax then (%ecx) := %edx.
|
||||
% %eax is set to old (%ecx), which will be the return value.
|
||||
*/
|
||||
"cmpxchgl %edx, (%ecx)"
|
||||
);
|
||||
}
|
||||
#else /* !ISC_PLATFORM_USEGCCASM && !ISC_PLATFORM_USESTDASM */
|
||||
|
||||
#error "unsupported compiler. disable atomic ops by --disable-atomic"
|
||||
|
||||
#endif
|
||||
#endif /* ISC_ATOMIC_H */
|
||||
@@ -1,17 +0,0 @@
|
||||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
SUBDIRS = include
|
||||
TARGETS =
|
||||
|
||||
@BIND9_MAKE_RULES@
|
||||
@@ -1,17 +0,0 @@
|
||||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
SUBDIRS = isc
|
||||
TARGETS =
|
||||
|
||||
@BIND9_MAKE_RULES@
|
||||
@@ -1,34 +0,0 @@
|
||||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
VERSION=@BIND9_VERSION@
|
||||
|
||||
HEADERS = atomic.h
|
||||
|
||||
SUBDIRS =
|
||||
TARGETS =
|
||||
|
||||
@BIND9_MAKE_RULES@
|
||||
|
||||
installdirs:
|
||||
$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${includedir}/isc
|
||||
|
||||
install:: installdirs
|
||||
for i in ${HEADERS}; do \
|
||||
${INSTALL_DATA} $(srcdir)/$$i ${DESTDIR}${includedir}/isc ; \
|
||||
done
|
||||
|
||||
uninstall::
|
||||
for i in ${HEADERS}; do \
|
||||
rm -f ${DESTDIR}${includedir}/isc/$$i ; \
|
||||
done
|
||||
@@ -1,129 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ISC_ATOMIC_H
|
||||
#define ISC_ATOMIC_H 1
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <isc/platform.h>
|
||||
#include <isc/types.h>
|
||||
|
||||
#ifdef ISC_PLATFORM_USEGCCASM
|
||||
|
||||
/* We share the gcc-version with x86_32 */
|
||||
#error "impossible case. check build configuration"
|
||||
|
||||
#elif defined(ISC_PLATFORM_USESTDASM)
|
||||
/*
|
||||
* The followings are "generic" assembly code which implements the same
|
||||
* functionality in case the gcc extension cannot be used. It should be
|
||||
* better to avoid inlining below, since we directly refer to specific
|
||||
* registers for arguments, which would not actually correspond to the
|
||||
* intended address or value in the embedded mnemonic.
|
||||
*/
|
||||
|
||||
static int32_t
|
||||
isc_atomic_xadd(int32_t *p, int32_t val) {
|
||||
(void)(p);
|
||||
(void)(val);
|
||||
|
||||
__asm (
|
||||
"movq %rdi, %rdx\n"
|
||||
"movl %esi, %eax\n"
|
||||
"lock;"
|
||||
"xadd %eax, (%rdx)\n"
|
||||
/*
|
||||
* XXX: assume %eax will be used as the return value.
|
||||
*/
|
||||
);
|
||||
}
|
||||
|
||||
#ifdef ISC_PLATFORM_HAVEXADDQ
|
||||
static int64_t
|
||||
isc_atomic_xaddq(int64_t *p, int64_t val) {
|
||||
(void)(p);
|
||||
(void)(val);
|
||||
|
||||
__asm (
|
||||
"movq %rdi, %rdx\n"
|
||||
"movq %rsi, %rax\n"
|
||||
"lock;"
|
||||
"xaddq %rax, (%rdx)\n"
|
||||
/*
|
||||
* XXX: assume %rax will be used as the return value.
|
||||
*/
|
||||
);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
isc_atomic_store(int32_t *p, int32_t val) {
|
||||
(void)(p);
|
||||
(void)(val);
|
||||
|
||||
__asm (
|
||||
"movq %rdi, %rax\n"
|
||||
"movl %esi, %edx\n"
|
||||
"lock;"
|
||||
"xchgl (%rax), %edx\n"
|
||||
);
|
||||
}
|
||||
|
||||
#ifdef ISC_PLATFORM_HAVEATOMICSTOREQ
|
||||
static void
|
||||
isc_atomic_storeq(int64_t *p, int64_t val) {
|
||||
(void)(p);
|
||||
(void)(val);
|
||||
|
||||
__asm (
|
||||
"movq %rdi, %rax\n"
|
||||
"movq %rsi, %rdx\n"
|
||||
"lock;"
|
||||
"xchgq (%rax), %rdx\n"
|
||||
);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int32_t
|
||||
isc_atomic_cmpxchg(int32_t *p, int32_t cmpval, int32_t val) {
|
||||
(void)(p);
|
||||
(void)(cmpval);
|
||||
(void)(val);
|
||||
|
||||
__asm (
|
||||
/*
|
||||
* p is %rdi, cmpval is %esi, val is %edx.
|
||||
*/
|
||||
"movl %edx, %ecx\n"
|
||||
"movl %esi, %eax\n"
|
||||
"movq %rdi, %rdx\n"
|
||||
|
||||
"lock;"
|
||||
/*
|
||||
* If [%rdi] == %eax then [%rdi] := %ecx (equal to %edx
|
||||
* from above), and %eax is untouched (equal to %esi)
|
||||
* from above.
|
||||
*
|
||||
* Else if [%rdi] != %eax then [%rdi] := [%rdi]
|
||||
* (rewritten in write cycle) and %eax := [%rdi].
|
||||
*/
|
||||
"cmpxchgl %ecx, (%rdx)"
|
||||
);
|
||||
}
|
||||
|
||||
#else /* !ISC_PLATFORM_USEGCCASM && !ISC_PLATFORM_USESTDASM */
|
||||
|
||||
#error "unsupported compiler. disable atomic ops by --disable-atomic"
|
||||
|
||||
#endif
|
||||
#endif /* ISC_ATOMIC_H */
|
||||
Reference in New Issue
Block a user