1 /*
2 Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is also distributed with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 #include <ndb_global.h>
26
27 #include "Emulator.hpp"
28 #include <FastScheduler.hpp>
29 #include <SignalLoggerManager.hpp>
30 #include <TransporterRegistry.hpp>
31 #include <TimeQueue.hpp>
32
33 #include "Configuration.hpp"
34 #include "WatchDog.hpp"
35 #include "ThreadConfig.hpp"
36 #include "SimBlockList.hpp"
37
38 #include <NodeState.hpp>
39 #include "ndbd_malloc_impl.hpp"
40
41 #include <NdbMem.h>
42 #include <NdbMutex.h>
43
44 #include <EventLogger.hpp>
45 extern EventLogger * g_eventLogger;
46
47 /**
48 * Declare the global variables
49 */
50
51 #ifndef NO_EMULATED_JAM
52 /*
53 This is the jam buffer used for non-threaded ndbd (but present also
54 in threaded ndbd to allow sharing of object files among the two
55 binaries).
56 */
57 EmulatedJamBuffer theEmulatedJamBuffer;
58 #endif
59
60 GlobalData globalData;
61
62 TimeQueue globalTimeQueue;
63 FastScheduler globalScheduler;
64 extern TransporterRegistry globalTransporterRegistry;
65
66 #ifdef VM_TRACE
67 SignalLoggerManager globalSignalLoggers;
68 #endif
69
70 EmulatorData globalEmulatorData;
71 NdbMutex * theShutdownMutex = 0;
72
EmulatorData()73 EmulatorData::EmulatorData(){
74 theConfiguration = 0;
75 theWatchDog = 0;
76 theThreadConfig = 0;
77 theSimBlockList = 0;
78 theShutdownMutex = 0;
79 m_socket_server = 0;
80 m_mem_manager = 0;
81 }
82
83 void
create()84 EmulatorData::create(){
85 /*
86 Global jam() buffer, for non-multithreaded operation.
87 For multithreaded ndbd, each thread will set a local jam buffer later.
88 */
89 NdbThread_SetTlsKey(NDB_THREAD_TLS_JAM, (void *)&theEmulatedJamBuffer);
90
91 NdbMem_Create();
92
93 theConfiguration = new Configuration();
94 theWatchDog = new WatchDog();
95 theThreadConfig = new ThreadConfig();
96 theSimBlockList = new SimBlockList();
97 m_socket_server = new SocketServer();
98 m_mem_manager = new Ndbd_mem_manager();
99
100 if (theConfiguration == NULL ||
101 theWatchDog == NULL ||
102 theThreadConfig == NULL ||
103 theSimBlockList == NULL ||
104 m_socket_server == NULL ||
105 m_mem_manager == NULL )
106 {
107 ERROR_SET(fatal, NDBD_EXIT_MEMALLOC,
108 "Failed to create EmulatorData", "");
109 }
110
111 if (!(theShutdownMutex = NdbMutex_Create()))
112 {
113 ERROR_SET(fatal, NDBD_EXIT_MEMALLOC,
114 "Failed to create shutdown mutex", "");
115 }
116 }
117
118 void
destroy()119 EmulatorData::destroy(){
120 if(theConfiguration)
121 delete theConfiguration; theConfiguration = 0;
122 if(theWatchDog)
123 delete theWatchDog; theWatchDog = 0;
124 if(theThreadConfig)
125 delete theThreadConfig; theThreadConfig = 0;
126 if(theSimBlockList)
127 delete theSimBlockList; theSimBlockList = 0;
128 if(m_socket_server)
129 delete m_socket_server; m_socket_server = 0;
130 NdbMutex_Destroy(theShutdownMutex);
131 if (m_mem_manager)
132 delete m_mem_manager; m_mem_manager = 0;
133
134 NdbMem_Destroy();
135 }
136