"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.11.23/lib/isc/mips/include/isc/atomic.h" (7 Sep 2020, 1916 Bytes) of package /linux/misc/dns/bind9/9.11.23/bind-9.11.23.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "atomic.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
    3  *
    4  * This Source Code Form is subject to the terms of the Mozilla Public
    5  * License, v. 2.0. If a copy of the MPL was not distributed with this
    6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    7  *
    8  * See the COPYRIGHT file distributed with this work for additional
    9  * information regarding copyright ownership.
   10  */
   11 
   12 
   13 #ifndef ISC_ATOMIC_H
   14 #define ISC_ATOMIC_H 1
   15 
   16 #include <inttypes.h>
   17 
   18 #include <isc/platform.h>
   19 #include <isc/types.h>
   20 
   21 #ifdef ISC_PLATFORM_USEGCCASM
   22 /*
   23  * This routine atomically increments the value stored in 'p' by 'val', and
   24  * returns the previous value.
   25  */
   26 static inline int32_t
   27 isc_atomic_xadd(int32_t *p, int val) {
   28     int32_t orig;
   29 
   30     __asm__ __volatile__ (
   31     "   .set    push        \n"
   32     "   .set    mips2       \n"
   33     "   .set    noreorder   \n"
   34     "   .set    noat        \n"
   35     "1: ll  $1, %1      \n"
   36     "   addu    %0, $1, %2  \n"
   37     "   sc  %0, %1      \n"
   38     "   beqz    %0, 1b      \n"
   39     "   move    %0, $1      \n"
   40     "   .set    pop     \n"
   41     : "=&r" (orig), "+R" (*p)
   42     : "r" (val)
   43     : "memory");
   44 
   45     return (orig);
   46 }
   47 
   48 /*
   49  * This routine atomically stores the value 'val' in 'p'.
   50  */
   51 static inline void
   52 isc_atomic_store(int32_t *p, int32_t val) {
   53     *p = val;
   54 }
   55 
   56 /*
   57  * This routine atomically replaces the value in 'p' with 'val', if the
   58  * original value is equal to 'cmpval'.  The original value is returned in any
   59  * case.
   60  */
   61 static inline int32_t
   62 isc_atomic_cmpxchg(int32_t *p, int cmpval, int val) {
   63     int32_t orig;
   64     int32_t tmp;
   65 
   66     __asm__ __volatile__ (
   67     "   .set    push        \n"
   68     "   .set    mips2       \n"
   69     "   .set    noreorder   \n"
   70     "   .set    noat        \n"
   71     "1: ll  $1, %1      \n"
   72     "   bne $1, %3, 2f  \n"
   73     "   move    %2, %4      \n"
   74     "   sc  %2, %1      \n"
   75     "   beqz    %2, 1b      \n"
   76     "2: move    %0, $1      \n"
   77     "   .set    pop     \n"
   78     : "=&r"(orig), "+R" (*p), "=r" (tmp)
   79     : "r"(cmpval), "r"(val)
   80     : "memory");
   81 
   82     return (orig);
   83 }
   84 
   85 #else /* !ISC_PLATFORM_USEGCCASM */
   86 
   87 #error "unsupported compiler.  disable atomic ops by --disable-atomic"
   88 
   89 #endif
   90 #endif /* ISC_ATOMIC_H */