#include "data_structure_dll.h"#include <basis/callstack_tracker.h>#include <basis/memory_checker.h>#include <basis/mutex.h>#include <basis/portable.h>Include dependency graph for static_memory_gremlin.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.
Classes | |
| class | static_memory_gremlin |
| Holds onto memory chunks that are allocated globally within the program. More... | |
| class | library_wide_cleanup |
| per-library class roots global statics and handles static destruction. More... | |
| class | program_wide_cleanup |
| per-application class roots global statics and handles static destruction. More... | |
Defines | |
| #define | SAFE_STATIC(type, func_name, parms) type &func_name() { SAFE_STATIC_IMPLEMENTATION(type, parms, __LINE__); } |
| Statically defines a singleton object whose scope is the program's lifetime. | |
| #define | SAFE_STATIC_CONST(type, func_name, parms) |
| this version returns a constant object instead. | |
| #define | STATIC_STRING(str) SAFE_STATIC_IMPLEMENTATION(istring_object, (str), __LINE__) |
| Statically defines a string for the rest of the program's life. | |
| #define | UNIQUE_NAME_BASED_ON_SOURCE(name, linenum) static const char *name = "file:" __FILE__ ":line:" #linenum |
| this macro creates a unique const char pointer based on file location. | |
| #define | SAFE_STATIC_IMPLEMENTATION(type, parms, linenum) |
| this blob is just a chunk of macro implementation for SAFE_STATIC... | |
| #define | HOOPLE_STARTUP_CODE_DLL |
| this must be deployed in the root file of dynamic libraries. | |
| #define | HOOPLE_STARTUP_CODE |
| this must be deployed in the root application's file. | |
| #define | BASIS_STARTUP_CODE_DLL HOOPLE_STARTUP_CODE_DLL |
| legacy macros from the time when all of the startup code lived in basis. | |
| #define | BASIS_STARTUP_CODE HOOPLE_STARTUP_CODE |
Functions | |
| bool DATA_STRUCTURE_FUNCTION_STYLE | program_is_dying () |
| Reports whether the program is shutting down currently. | |
| static_memory_gremlin DATA_STRUCTURE_FUNCTION_STYLE & | HOOPLE_GLOBALS () |
| Holds onto objects that have been allocated in a program-wide scope. | |
| mutex DATA_STRUCTURE_FUNCTION_STYLE & | __memory_gremlin_synchronizer () |
| Internally used synchronization--not for outsiders. | |
| const char DATA_STRUCTURE_FUNCTION_STYLE * | EXCEPTION_INFO_FOR_SHUTTING_DOWN () |
| exception string thrown for usage errors. | |
Definition at line 275 of file static_memory_gremlin.h.
legacy macros from the time when all of the startup code lived in basis.
Definition at line 274 of file static_memory_gremlin.h.
| #define HOOPLE_STARTUP_CODE |
Value:
HOOPLE_STARTUP_CODE_DLL; \ /* the creation of this static cleanup object also establishes the \ * static objects that are provided as global hoople services. */ \ static program_wide_cleanup _harvey_keitel
this is placed where main, WinMain, CWinApp, etc. reside to ensure that the static synchronization scheme, program wide objects, and other useful bits are properly initialized.
Definition at line 268 of file static_memory_gremlin.h.
| #define HOOPLE_STARTUP_CODE_DLL |
Value:
DEFINE_ARGC_AND_ARGV; /* any OS specific code. */ \ DEFINE_INSTANCE_HANDLE; /* set up the instance handle. */ \ static library_wide_cleanup _jean_reno
the file <basis/dll_root.cpp> can be used for most of the dll setup.
Definition at line 259 of file static_memory_gremlin.h.
| #define SAFE_STATIC | ( | type, | |||
| func_name, | |||||
| parms | ) | type &func_name() { SAFE_STATIC_IMPLEMENTATION(type, parms, __LINE__); } |
Statically defines a singleton object whose scope is the program's lifetime.
SAFE_STATIC is a macro that creates a function that returns a particular data type. the object is allocated statically, so that the same object will be returned ever after until the program is shut down. the allocation is guarded so that multiple threads cannot create conflicting static objects. note: in ms-win32, if you use this macro in a static library (rather than a DLL), then the heap context is different. thus you could actually have multiple copies of the underlying object. if the object is supposed to be global and unique, then that's a problem. relocating the definitions to a dll while keeping declarations in the static lib works (see the program wide logger approach in <basis/program_wide_logger.h>). "type" is the object class to return. "func_name" is the function to be created. "parms" must be a list of parameters in parentheses or nothing. example usage:
SAFE_STATIC(connection_table, conntab, (parm1, parm2))
SAFE_STATIC(istring_object, static_string_doodle, )
Definition at line 159 of file static_memory_gremlin.h.
| #define SAFE_STATIC_CONST | ( | type, | |||
| func_name, | |||||
| parms | ) |
Value:
const type &func_name() \ { SAFE_STATIC_IMPLEMENTATION(type, parms, __LINE__); }
Definition at line 163 of file static_memory_gremlin.h.
| #define SAFE_STATIC_IMPLEMENTATION | ( | type, | |||
| parms, | |||||
| linenum | ) |
this blob is just a chunk of macro implementation for SAFE_STATIC...
if the static object isn't initialized yet, we'll create it and store it in the static_memory_gremlin. we make sure that the program isn't shutting down, because that imposes a new requirement--previously created statics might have already been destroyed. thus, during the program shutdown, we carefully recreate any objects that were already toast.
Definition at line 186 of file static_memory_gremlin.h.
Referenced by __our_kids(), __process_synchronizer(), __uptime_synchronizer(), and real_program_wide_logger().
| #define STATIC_STRING | ( | str | ) | SAFE_STATIC_IMPLEMENTATION(istring_object, (str), __LINE__) |
Statically defines a string for the rest of the program's life.
This macro can be used to make functions returning a string a little simpler. This can only be used when the string is constant. The usual way to use this macro is in a function that returns a constant reference to a string. The macro allocates the string to be returned statically so that all future calls will refer to the stored string rather than recreating it again.
Definition at line 173 of file static_memory_gremlin.h.
Referenced by dorf(), path_configuration::GLOBAL_SECTION_NAME(), path_configuration::LOCAL_FOLDER_NAME(), and path_configuration::LOGGING_FOLDER_NAME().
| #define UNIQUE_NAME_BASED_ON_SOURCE | ( | name, | |||
| linenum | ) | static const char *name = "file:" __FILE__ ":line:" #linenum |
this macro creates a unique const char pointer based on file location.
Definition at line 177 of file static_memory_gremlin.h.
| mutex DATA_STRUCTURE_FUNCTION_STYLE& __memory_gremlin_synchronizer | ( | ) |
Internally used synchronization--not for outsiders.
This is a very low level, private function that should not be invoked by the average user of the libraries. it is critical that it not be mis- used because a deadlock could result if it is used improperly. it returns a statically allocated mutex that can be used for the proper synchronization of our memory allocation manager. this particular function must be invoked at least once from the main thread before any other threads have been spawned. this ensures that all threads are seeing the same lock. this mutex is NOT to be used for anything other than securing static object creations from race conditions.
Definition at line 416 of file static_memory_gremlin.cpp.
References static_memory_gremlin::get(), HOOPLE_GLOBALS(), and static_memory_gremlin::put().
Referenced by library_wide_cleanup::library_wide_cleanup().
| const char DATA_STRUCTURE_FUNCTION_STYLE* EXCEPTION_INFO_FOR_SHUTTING_DOWN | ( | ) |
exception string thrown for usage errors.
this string will be thrown as an exception if a program is trying to use global objects when it should be shutting down instead.
Definition at line 56 of file static_memory_gremlin.cpp.
References _EXCEPTION_INFO_FOR_SHUTTING_DOWN.
| static_memory_gremlin DATA_STRUCTURE_FUNCTION_STYLE& HOOPLE_GLOBALS | ( | ) |
Holds onto objects that have been allocated in a program-wide scope.
These objects will have a lifetime up to the point of normal static object destruction and then they will be cleaned up.
Definition at line 228 of file static_memory_gremlin.cpp.
References __argv, FUNCDEF, NIL, and program_wide_memories.
Referenced by __memory_gremlin_synchronizer(), and program_wide_cleanup::~program_wide_cleanup().
| bool DATA_STRUCTURE_FUNCTION_STYLE program_is_dying | ( | ) |
Reports whether the program is shutting down currently.
If this flag is true, then code should generally just return without doing anything where possible. It's especially important for long running loops or active threads to stop if they see this, although the normal program exit processes usually make it unnecessary.
Definition at line 54 of file static_memory_gremlin.cpp.
Referenced by static_memory_gremlin::~static_memory_gremlin().
1.5.1