A platform for high-performance distributed tool and library development written in C++. It can be deployed in two different cluster modes: standalone or distributed. API for v0.5.0, released on June 13, 2018.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
GetVTable.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * *
3  * Copyright 2018 Rice University *
4  * *
5  * Licensed under the Apache License, Version 2.0 (the "License"); *
6  * you may not use this file except in compliance with the License. *
7  * You may obtain a copy of the License at *
8  * *
9  * http://www.apache.org/licenses/LICENSE-2.0 *
10  * *
11  * Unless required by applicable law or agreed to in writing, software *
12  * distributed under the License is distributed on an "AS IS" BASIS, *
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14  * See the License for the specific language governing permissions and *
15  * limitations under the License. *
16  * *
17  *****************************************************************************/
18 
19 // this contains the GET_V_TABLE macro, which is used to create a shared library
20 // that can send an object type around the compute cluster
21 
23 
24 #ifndef GET_V_TABLE
25 #define GET_V_TABLE(TYPE_NAME) \
26  \
27  namespace pdb { \
28  \
29  /* this returns the name of the type that we are loading */ \
30  char typeName[300]; \
31  \
32  extern VTableMap* theVTable; \
33  extern void* stackBase; \
34  extern void* stackEnd; \
35  extern bool inSharedLibrary; \
36  \
37  extern "C" { \
38  \
39  char* getObjectTypeName() { \
40  std::string typeString = getTypeName<TYPE_NAME>(); \
41  memmove(typeName, typeString.c_str(), typeString.size() + 1); \
42  return typeName; \
43  } \
44  \
45  /* this returns an instance of the vtable of the type that we are loading */ \
46  void* getObjectVTable() { \
47  void* returnVal = nullptr; \
48  const UseTemporaryAllocationBlock myBlock{1024 * 1024 * 4}; \
49  try { \
50  TYPE_NAME temp; \
51  returnVal = temp.getVTablePtr(); \
52  \
53  } catch (NotEnoughSpace & e) { \
54  std::cout << "Not enough memory to allocate TYPE_NAME"; \
55  } \
56  return returnVal; \
57  } \
58  \
59  /* this must be called before getObjectVTable () to correctly set the static */ \
60  /* and global variables that make the object model work correctly. Since */ \
61  /* the shared library has *different* copies of all of these, they must be */ \
62  /* set before the shared library is used to do anything. */ \
63  \
64  void setAllGlobalVariables(Allocator* newAllocator, \
65  VTableMap* theVTableIn, \
66  void* stackBaseIn, \
67  void* stackEndIn) { \
68  stackBase = stackBaseIn; \
69  mainAllocatorPtr = newAllocator; \
70  stackEnd = stackEndIn; \
71  theVTable = theVTableIn; \
72  inSharedLibrary = true; \
73  } \
74  } \
75  }
76 
77 #endif