Back to index

glibc  2.9
atomic.h
Go to the documentation of this file.
00001 /* Copyright (C) 2003, 2006 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #ifndef _BITS_ATOMIC_H
00020 #define _BITS_ATOMIC_H      1
00021 
00022 #include <stdint.h>
00023 
00024 /* Coldfire has no atomic compare-and-exchange operation, and the
00025    kernel provides no userspace atomicity operations.  Here we just
00026    use generic non-atomic implementations instead.  */
00027 
00028 typedef int8_t atomic8_t;
00029 typedef uint8_t uatomic8_t;
00030 typedef int_fast8_t atomic_fast8_t;
00031 typedef uint_fast8_t uatomic_fast8_t;
00032 
00033 typedef int16_t atomic16_t;
00034 typedef uint16_t uatomic16_t;
00035 typedef int_fast16_t atomic_fast16_t;
00036 typedef uint_fast16_t uatomic_fast16_t;
00037 
00038 typedef int32_t atomic32_t;
00039 typedef uint32_t uatomic32_t;
00040 typedef int_fast32_t atomic_fast32_t;
00041 typedef uint_fast32_t uatomic_fast32_t;
00042 
00043 typedef int64_t atomic64_t;
00044 typedef uint64_t uatomic64_t;
00045 typedef int_fast64_t atomic_fast64_t;
00046 typedef uint_fast64_t uatomic_fast64_t;
00047 
00048 typedef intptr_t atomicptr_t;
00049 typedef uintptr_t uatomicptr_t;
00050 typedef intmax_t atomic_max_t;
00051 typedef uintmax_t uatomic_max_t;
00052 
00053 /* The only basic operation needed is compare and exchange.  */
00054 #define atomic_compare_and_exchange_val_acq(mem, newval, oldval) \
00055   ({ __typeof (mem) __gmemp = (mem);                                 \
00056      __typeof (*mem) __gret = *__gmemp;                              \
00057      __typeof (*mem) __gnewval = (newval);                           \
00058                                                               \
00059      if (__gret == (oldval))                                         \
00060        *__gmemp = __gnewval;                                         \
00061      __gret; })
00062 
00063 #define atomic_compare_and_exchange_bool_acq(mem, newval, oldval) \
00064   ({ __typeof (mem) __gmemp = (mem);                                 \
00065      __typeof (*mem) __gnewval = (newval);                           \
00066                                                               \
00067      *__gmemp == (oldval) ? (*__gmemp = __gnewval, 0) : 1; })
00068 
00069 #endif