usermode/library/mtm/src/mode/pwbnl/pwbnl.c

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 #include <pcm.h>
00034 #include <log.h>
00035 
00036 #include "pwb_i.h"
00037 
00038 
00039 #ifndef RW_SET_SIZE
00040 #define RW_SET_SIZE (256*1024)
00041 #endif
00042 
00043 #undef _DTABLE_MEMBER
00044 #define _DTABLE_MEMBER(result, function, args, ARG)   ARG##function,
00045 
00046 
00047 mtm_dtable_t mtm_pwbnl_dtable =
00048 {
00049         FOREACH_ABI_FUNCTION      (_DTABLE_MEMBER, mtm_pwbnl_)
00050         FOREACH_READ_BARRIER      (_DTABLE_MEMBER, mtm_pwbnl_)
00051         FOREACH_WRITE_BARRIER     (_DTABLE_MEMBER, mtm_pwbnl_)
00052         _ITM_FOREACH_MEMCPY       (_DTABLE_MEMBER, mtm_pwbnl_)
00053         _ITM_FOREACH_LOG_TRANSFER (_DTABLE_MEMBER, mtm_local_)
00054         _ITM_FOREACH_MEMSET       (_DTABLE_MEMBER, mtm_pwbnl_)
00055         _ITM_FOREACH_MEMMOVE      (_DTABLE_MEMBER, mtm_pwbnl_)
00056 };
00057 
00058 
00059 /* Called by mtm_init_thread */
00060 m_result_t
00061 mtm_pwbnl_create(mtm_tx_t *tx, mtm_mode_data_t **datap)
00062 {
00063         mtm_pwb_mode_data_t *data;
00064 
00065 #if CM == CM_PRIORITY
00066         COMPILE_TIME_ASSERT((sizeof(w_entry_t) & ALIGNMENT_MASK) == 0); /* Multiple of ALIGNMENT */
00067 #endif /* CM == CM_PRIORITY */
00068 
00069         if ((data = (mtm_pwb_mode_data_t *) malloc(sizeof(mtm_pwb_mode_data_t)))
00070             == NULL)
00071         {
00072                 return M_R_FAILURE;
00073         }
00074 
00075         /* Read set */
00076         data->r_set.nb_entries = 0;
00077         data->r_set.size = RW_SET_SIZE;
00078         mtm_allocate_rs_entries(tx, data, 0);
00079 
00080         /* Volatile write set */
00081         data->w_set.nb_entries = 0;
00082         data->w_set.size = RW_SET_SIZE;
00083         data->w_set.reallocate = 0;
00084         mtm_allocate_ws_entries(tx, data, 0);
00085 
00086         /* Non-volatile log */
00087 #ifdef SYNC_TRUNCATION  
00088         m_logmgr_alloc_log(tx->pcm_storeset, M_TMLOG_LF_TYPE, 0, &data->ptmlog_dsc);
00089 #else
00090         m_logmgr_alloc_log(tx->pcm_storeset, M_TMLOG_LF_TYPE, LF_ASYNC_TRUNCATION, &data->ptmlog_dsc);
00091 #endif  
00092         data->ptmlog = (M_TMLOG_T *) data->ptmlog_dsc->log;
00093 
00094         *datap = (mtm_mode_data_t *) data;
00095 
00096         return M_R_SUCCESS;
00097 }
00098 
00099 
00100 m_result_t
00101 mtm_pwbnl_destroy(mtm_mode_data_t *_data)
00102 {
00103         mode_data_t *data = (mode_data_t *) _data;
00104 #ifdef EPOCH_GC
00105         mtm_word_t t;
00106 #endif /* EPOCH_GC */
00107         
00108         m_logmgr_free_log(data->ptmlog_dsc);
00109 
00110 #ifdef EPOCH_GC
00111         t = GET_CLOCK;
00112         gc_free(data->r_set.entries, t);
00113         gc_free(data->w_set.entries, t);
00114 #else /* ! EPOCH_GC */
00115         free(data->r_set.entries);
00116         free(data->w_set.entries);
00117 #endif /* ! EPOCH_GC */
00118 }

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