usermode/library/mtm/src/atomic.h

00001 /*
00002     Copyright (C) 2011 Computer Sciences Department, 
00003     University of Wisconsin -- Madison
00004 
00005     ----------------------------------------------------------------------
00006 
00007     This file is part of Mnemosyne: Lightweight Persistent Memory, 
00008     originally developed at the University of Wisconsin -- Madison.
00009 
00010     Mnemosyne was originally developed primarily by Haris Volos
00011     with contributions from Andres Jaan Tack.
00012 
00013     ----------------------------------------------------------------------
00014 
00015     Mnemosyne is free software; you can redistribute it and/or
00016     modify it under the terms of the GNU General Public License
00017     as published by the Free Software Foundation, version 2
00018     of the License.
00019  
00020     Mnemosyne is distributed in the hope that it will be useful,
00021     but WITHOUT ANY WARRANTY; without even the implied warranty of
00022     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023     GNU General Public License for more details.
00024 
00025     You should have received a copy of the GNU General Public License
00026     along with this program; if not, write to the Free Software
00027     Foundation, Inc., 51 Franklin Street, Fifth Floor, 
00028     Boston, MA  02110-1301, USA.
00029 
00030 ### END HEADER ###
00031 */
00032 
00033 /*
00034  * Source code is partially derived from TinySTM (license is attached)
00035  *
00036  *
00037  * File:
00038  *   atomic.h
00039  * Author(s):
00040  *   Pascal Felber <pascal.felber@unine.ch>
00041  * Description:
00042  *   Atomic operations.
00043  *
00044  * Copyright (c) 2007-2009.
00045  *
00046  * This program is free software; you can redistribute it and/or
00047  * modify it under the terms of the GNU General Public License
00048  * as published by the Free Software Foundation, version 2
00049  * of the License.
00050  *
00051  * This program is distributed in the hope that it will be useful,
00052  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00053  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00054  * GNU General Public License for more details.
00055  */
00056 
00057 #ifndef _ATOMIC_H_
00058 # define _ATOMIC_H_
00059 
00060 # include <atomic_ops.h>
00061 
00062 typedef AO_t atomic_t;
00063 
00064 # ifdef NO_AO
00065 /* Use only for testing purposes (single thread benchmarks) */
00066 #  define ATOMIC_CAS_FULL(a, e, v)      (*(a) = (v), 1)
00067 #  define ATOMIC_FETCH_INC_FULL(a)      ((*(a))++)
00068 #  define ATOMIC_FETCH_DEC_FULL(a)      ((*(a))--)
00069 #  define ATOMIC_FETCH_ADD_FULL(a, v)   ((*(a)) += (v))
00070 #  define ATOMIC_LOAD_ACQ(a)            (*(a))
00071 #  define ATOMIC_LOAD(a)                (*(a))
00072 #  define ATOMIC_STORE_REL(a, v)        (*(a) = (v))
00073 #  define ATOMIC_STORE(a, v)            (*(a) = (v))
00074 #  define ATOMIC_MB_READ                /* Nothing */
00075 #  define ATOMIC_MB_WRITE               /* Nothing */
00076 #  define ATOMIC_MB_FULL                /* Nothing */
00077 # else /* ! NO_AO */
00078 #  define ATOMIC_CAS_FULL(a, e, v)      (AO_compare_and_swap_full((volatile AO_t *)(a), (AO_t)(e), (AO_t)(v)))
00079 #  define ATOMIC_FETCH_INC_FULL(a)      (AO_fetch_and_add1_full((volatile AO_t *)(a)))
00080 #  define ATOMIC_FETCH_DEC_FULL(a)      (AO_fetch_and_sub1_full((volatile AO_t *)(a)))
00081 #  define ATOMIC_FETCH_ADD_FULL(a, v)   (AO_fetch_and_add_full((volatile AO_t *)(a), (AO_t)(v)))
00082 #  ifdef SAFE
00083 #   define ATOMIC_LOAD_ACQ(a)           (AO_load_full((volatile AO_t *)(a)))
00084 #   define ATOMIC_LOAD(a)               (AO_load_full((volatile AO_t *)(a)))
00085 #   define ATOMIC_STORE_REL(a, v)       (AO_store_full((volatile AO_t *)(a), (AO_t)(v)))
00086 #   define ATOMIC_STORE(a, v)           (AO_store_full((volatile AO_t *)(a), (AO_t)(v)))
00087 #   define ATOMIC_MB_READ               AO_nop_full()
00088 #   define ATOMIC_MB_WRITE              AO_nop_full()
00089 #   define ATOMIC_MB_FULL               AO_nop_full()
00090 #  else /* ! SAFE */
00091 #   define ATOMIC_LOAD_ACQ(a)           (AO_load_acquire_read((volatile AO_t *)(a)))
00092 #   define ATOMIC_LOAD(a)               (*((volatile AO_t *)(a)))
00093 #   define ATOMIC_STORE_REL(a, v)       (AO_store_release((volatile AO_t *)(a), (AO_t)(v)))
00094 #   define ATOMIC_STORE(a, v)           (*((volatile AO_t *)(a)) = (AO_t)(v))
00095 #   define ATOMIC_MB_READ               AO_nop_read()
00096 #   define ATOMIC_MB_WRITE              AO_nop_write()
00097 #   define ATOMIC_MB_FULL               AO_nop_full()
00098 #  endif /* ! SAFE */
00099 # endif /* ! NO_AO */
00100 
00101 // 1
00102 #endif /* _ATOMIC_H_ */

Generated on Sat Apr 23 11:43:36 2011 for Mnemosyne by  doxygen 1.4.7