00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef ISC_ATOMIC_H
00020 #define ISC_ATOMIC_H 1
00021
00022 #include <isc/platform.h>
00023 #include <isc/types.h>
00024
00025 #ifdef ISC_PLATFORM_USEGCCASM
00026
00027
00028
00029
00030
00031
00032
00033 static inline isc_int32_t
00034 #ifdef __GNUC__
00035 __attribute__ ((unused))
00036 #endif
00037 isc_atomic_xadd(isc_int32_t *p, isc_int32_t val)
00038 {
00039 isc_int32_t prev, swapped;
00040
00041 for (prev = *(volatile isc_int32_t *)p; ; prev = swapped) {
00042 swapped = prev + val;
00043 __asm__ volatile(
00044 "mov ar.ccv=%2;;"
00045 "cmpxchg4.acq %0=%4,%3,ar.ccv"
00046 : "=r" (swapped), "=m" (*p)
00047 : "r" (prev), "r" (swapped), "m" (*p)
00048 : "memory");
00049 if (swapped == prev)
00050 break;
00051 }
00052
00053 return (prev);
00054 }
00055
00056
00057
00058
00059 static inline void
00060 #ifdef __GNUC__
00061 __attribute__ ((unused))
00062 #endif
00063 isc_atomic_store(isc_int32_t *p, isc_int32_t val)
00064 {
00065 __asm__ volatile(
00066 "st4.rel %0=%1"
00067 : "=m" (*p)
00068 : "r" (val)
00069 : "memory"
00070 );
00071 }
00072
00073
00074
00075
00076
00077
00078 static inline isc_int32_t
00079 #ifdef __GNUC__
00080 __attribute__ ((unused))
00081 #endif
00082 isc_atomic_cmpxchg(isc_int32_t *p, isc_int32_t cmpval, isc_int32_t val)
00083 {
00084 isc_int32_t ret;
00085
00086 __asm__ volatile(
00087 "mov ar.ccv=%2;;"
00088 "cmpxchg4.acq %0=%4,%3,ar.ccv"
00089 : "=r" (ret), "=m" (*p)
00090 : "r" (cmpval), "r" (val), "m" (*p)
00091 : "memory");
00092
00093 return (ret);
00094 }
00095 #else
00096
00097 #error "unsupported compiler. disable atomic ops by --disable-atomic"
00098
00099 #endif
00100 #endif