1/* 2 Title: rts_module.cpp - Base class for the run-time system modules. 3 4 Copyright (c) 2006, 2020 David C.J. Matthews 5 6 This library is free software; you can redistribute it and/or 7 modify it under the terms of the GNU Lesser General Public 8 License as published by the Free Software Foundation; either 9 version 2.1 of the License, or (at your option) any later version. 10 11 This library is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 Lesser General Public License for more details. 15 16 You should have received a copy of the GNU Lesser General Public 17 License along with this library; if not, write to the Free Software 18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 20*/ 21 22#ifdef HAVE_CONFIG_H 23#include "config.h" 24#elif defined(_WIN32) 25#include "winconfig.h" 26#else 27#error "No configuration file" 28#endif 29 30#ifdef HAVE_STRING_H 31#include <string.h> 32#endif 33 34#ifdef HAVE_ASSERT_H 35#include <assert.h> 36#define ASSERT(x) assert(x) 37 38#else 39#define ASSERT(x) 40#endif 41 42#include "rts_module.h" 43 44#define MAX_MODULES 30 45 46static RtsModule *module_table[MAX_MODULES]; 47static unsigned modCount = 0; 48 49// Add a module to the table. This will be done during the static 50// initialisation phase. 51void RtsModule::RegisterModule(void) 52{ 53 ASSERT(modCount < MAX_MODULES); 54 module_table[modCount++] = this; 55} 56 57void InitModules(void) 58{ 59 for(unsigned i = 0; i < modCount; i++) 60 module_table[i]->Init(); 61} 62 63void StartModules(void) 64{ 65 for(unsigned i = 0; i < modCount; i++) 66 module_table[i]->Start(); 67} 68 69void StopModules(void) 70{ 71 for(unsigned i = 0; i < modCount; i++) 72 module_table[i]->Stop(); 73} 74 75void GCModules(ScanAddress *process) 76{ 77 for(unsigned i = 0; i < modCount; i++) 78 module_table[i]->GarbageCollect(process); 79} 80 81// Called on Unix in the child process. 82void ForkChildModules(void) 83{ 84 for (unsigned i = 0; i < modCount; i++) 85 module_table[i]->ForkChild(); 86} 87