MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Emulator.cpp
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 as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include <ndb_global.h>
19 
20 #include "Emulator.hpp"
21 #include <FastScheduler.hpp>
22 #include <SignalLoggerManager.hpp>
23 #include <TransporterRegistry.hpp>
24 #include <TimeQueue.hpp>
25 
26 #include "Configuration.hpp"
27 #include "WatchDog.hpp"
28 #include "ThreadConfig.hpp"
29 #include "SimBlockList.hpp"
30 
31 #include <NodeState.hpp>
32 #include "ndbd_malloc_impl.hpp"
33 
34 #include <NdbMem.h>
35 #include <NdbMutex.h>
36 
37 #include <EventLogger.hpp>
38 extern EventLogger * g_eventLogger;
39 
44 #ifndef NO_EMULATED_JAM
45 /*
46  This is the jam buffer used for non-threaded ndbd (but present also
47  in threaded ndbd to allow sharing of object files among the two
48  binaries).
49  */
50 EmulatedJamBuffer theEmulatedJamBuffer;
51 #endif
52 
53  GlobalData globalData;
54 
55  TimeQueue globalTimeQueue;
56  FastScheduler globalScheduler;
57  extern TransporterRegistry globalTransporterRegistry;
58 
59 #ifdef VM_TRACE
60  SignalLoggerManager globalSignalLoggers;
61 #endif
62 
63 EmulatorData globalEmulatorData;
64 NdbMutex * theShutdownMutex = 0;
65 
67  theConfiguration = 0;
68  theWatchDog = 0;
69  theThreadConfig = 0;
70  theSimBlockList = 0;
71  theShutdownMutex = 0;
72  m_socket_server = 0;
73  m_mem_manager = 0;
74 }
75 
76 void
78  /*
79  Global jam() buffer, for non-multithreaded operation.
80  For multithreaded ndbd, each thread will set a local jam buffer later.
81  */
82  NdbThread_SetTlsKey(NDB_THREAD_TLS_JAM, (void *)&theEmulatedJamBuffer);
83 
84  NdbMem_Create();
85 
86  theConfiguration = new Configuration();
87  theWatchDog = new WatchDog();
88  theThreadConfig = new ThreadConfig();
89  theSimBlockList = new SimBlockList();
90  m_socket_server = new SocketServer();
91  m_mem_manager = new Ndbd_mem_manager();
92 
93  if (theConfiguration == NULL ||
94  theWatchDog == NULL ||
95  theThreadConfig == NULL ||
96  theSimBlockList == NULL ||
97  m_socket_server == NULL ||
98  m_mem_manager == NULL )
99  {
100  ERROR_SET(fatal, NDBD_EXIT_MEMALLOC,
101  "Failed to create EmulatorData", "");
102  }
103 
104  if (!(theShutdownMutex = NdbMutex_Create()))
105  {
106  ERROR_SET(fatal, NDBD_EXIT_MEMALLOC,
107  "Failed to create shutdown mutex", "");
108  }
109 }
110 
111 void
113  if(theConfiguration)
114  delete theConfiguration; theConfiguration = 0;
115  if(theWatchDog)
116  delete theWatchDog; theWatchDog = 0;
117  if(theThreadConfig)
118  delete theThreadConfig; theThreadConfig = 0;
119  if(theSimBlockList)
120  delete theSimBlockList; theSimBlockList = 0;
121  if(m_socket_server)
122  delete m_socket_server; m_socket_server = 0;
123  NdbMutex_Destroy(theShutdownMutex);
124  if (m_mem_manager)
125  delete m_mem_manager; m_mem_manager = 0;
126 
127  NdbMem_Destroy();
128 }