usermode/library/mcore/src/reincarnation_callback.c

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 
00039 #include "reincarnation_callback.h"
00040 #include "init.h"
00041 #include <list.h>
00042 #include <stdlib.h>
00043 
00044 
00046 LIST_HEAD(theRegisteredCallbacks);
00047 
00049 struct reincarnation_callback
00050 {
00051         void (*routine)();      
00052         struct list_head list;  
00053 };
00054 typedef struct reincarnation_callback reincarnation_callback_t;
00055 
00056 
00057 void mnemosyne_reincarnation_callback_register(void(*initializer)())
00058 {
00059         if (!mnemosyne_initialized) {
00060                 reincarnation_callback_t* callback = (reincarnation_callback_t*) malloc(sizeof(struct reincarnation_callback));
00061                 callback->routine = initializer;
00062                 list_add_tail(&callback->list, &theRegisteredCallbacks);
00063         } else {
00064                 initializer();  // We're already ready already!
00065         }
00066 }
00067 
00068 
00069 void mnemosyne_reincarnation_callback_execute_all()
00070 {
00071         struct list_head* callback_node;
00072         struct list_head* next;
00073         list_for_each_safe(callback_node, next, &theRegisteredCallbacks) {
00074                 list_del(callback_node);
00075                 reincarnation_callback_t* callback = list_entry(callback_node, reincarnation_callback_t, list);
00076                 callback->routine();
00077                 free(callback);
00078         }
00079 }

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