usermode/library/mtm/src/mode/common/mask.h

Go to the documentation of this file.
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 
00042 #ifndef MASK_H_4NASQJFA
00043 #define MASK_H_4NASQJFA
00044 
00045 
00049 static const mtm_word_t whole_word_mask = ~(mtm_word_t)0;
00050 
00051 
00062 static inline
00063 mtm_word_t masked_word(mtm_word_t old_value, mtm_word_t new_value, mtm_word_t mask)
00064 {
00065         return (old_value & ~mask) | (new_value & mask);
00066 }
00067 
00068 
00084 static inline
00085 mtm_word_t mask_new_value(w_entry_t* entry, const volatile mtm_word_t* written_address, const mtm_word_t this_value, const mtm_word_t this_mask)
00086 {
00087         mtm_word_t new_value = this_value;
00088         mtm_word_t new_mask = entry->mask | this_mask;
00089         
00090         if (this_mask != whole_word_mask) {
00091                 if (entry->mask == 0)
00092                         entry->value = ATOMIC_LOAD(written_address);
00093                 
00094                 new_value = masked_word(entry->value, this_value, this_mask);
00095         }
00096         
00097         entry->value = new_value;
00098         entry->mask  = new_mask;
00099         
00100         return entry->value;
00101 }
00102 
00103 #endif /* end of include guard: MASK_H_4NASQJFA */

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