usermode/library/mcore/src/init.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 <pthread.h>
00034 #include <stdlib.h>
00035 #include "reincarnation_callback.h"
00036 #include "segment.h"
00037 #include "log/log_i.h"
00038 #include "thrdesc.h"
00039 #include "debug.h"
00040 #include "config.h"
00041 
00042 
00043 static pthread_mutex_t global_init_lock = PTHREAD_MUTEX_INITIALIZER;
00044 //static pthread_cond_t  global_init_cond = PTHREAD_COND_INITIALIZER;
00045 //static pthread_mutex_t global_fini_lock = PTHREAD_MUTEX_INITIALIZER;
00046 //static pthread_cond_t  global_fini_cond = PTHREAD_COND_INITIALIZER;
00047 volatile uint32_t      mnemosyne_initialized = 0;
00048 
00049 
00050 __thread mnemosyne_thrdesc_t *_mnemosyne_thr;
00051 
00052 static void do_global_init(void) __attribute__(( constructor ));
00053 static void do_global_fini(void) __attribute__(( destructor ));
00054 
00055 void
00056 do_global_init(void)
00057 {
00058         pcm_storeset_t* pcm_storeset;
00059 #ifdef _M_STATS_BUILD
00060         struct timeval     start_time;
00061         struct timeval     stop_time;
00062         unsigned long long op_time;
00063 #endif
00064 
00065         if (mnemosyne_initialized) {
00066                 return;
00067         }
00068 
00069         pcm_storeset = pcm_storeset_get ();
00070 
00071         pthread_mutex_lock(&global_init_lock);
00072         if (!mnemosyne_initialized) {
00073                 mcore_config_init();
00074 #ifdef _M_STATS_BUILD
00075                 gettimeofday(&start_time, NULL);
00076 #endif
00077                 m_segmentmgr_init();
00078                 mnemosyne_initialized = 1;
00079                 mnemosyne_reincarnation_callback_execute_all();
00080 #ifdef _M_STATS_BUILD
00081                 gettimeofday(&stop_time, NULL);
00082                 op_time = 1000000 * (stop_time.tv_sec - start_time.tv_sec) +
00083                                      stop_time.tv_usec - start_time.tv_usec;
00084                 fprintf(stderr, "reincarnation_latency = %llu (us)\n", op_time);
00085 #endif
00086                 m_logmgr_init(pcm_storeset);
00087                 M_WARNING("Initialize\n");
00088         }       
00089         pthread_mutex_unlock(&global_init_lock);
00090 }
00091 
00092 
00093 void
00094 do_global_fini(void)
00095 {
00096         if (!mnemosyne_initialized) {
00097                 return;
00098         }
00099 
00100         pthread_mutex_lock(&global_init_lock);
00101         if (mnemosyne_initialized) {
00102                 m_logmgr_fini();
00103                 m_segmentmgr_fini();
00104                 mtm_fini_global();
00105                 mnemosyne_initialized = 0;
00106 
00107                 M_WARNING("Shutdown\n");
00108         }       
00109         pthread_mutex_unlock(&global_init_lock);
00110 }
00111 
00112 
00113 void 
00114 mnemosyne_init_global(void)
00115 {
00116         do_global_init();
00117 }
00118 
00119 
00120 void 
00121 mnemosyne_fini_global(void)
00122 {
00123         do_global_fini();
00124 }
00125 
00126 
00127 mnemosyne_thrdesc_t *
00128 mnemosyne_init_thread(void)
00129 {
00130         mnemosyne_thrdesc_t *thr = NULL; //FIXME: get thread descriptor value
00131 
00132         if (thr) {
00133                 M_WARNING("mnemosyne_init_thread:1: thr = %p\n", thr);
00134                 return thr;
00135         }
00136 
00137         mnemosyne_init_global();
00138         thr = (mnemosyne_thrdesc_t *) malloc(sizeof(mnemosyne_thrdesc_t));
00139         //TODO: initialize values
00140         //thr->tx = NULL;
00141         //thr->vtable = defaultVtables->PTM;
00142         M_WARNING("mnemosyne_init_thread:2: thr = %p\n", thr);
00143         return thr;
00144 }
00145 
00146 
00147 void
00148 mnemosyne_fini_thread(void)
00149 {
00150         M_WARNING("mnemosyne_fini_thread:2\n");
00151 }

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