program wide callstack became thread wide
authorFred T. Hamster <fred@feistymeow.org>
Thu, 12 Feb 2026 11:24:53 +0000 (06:24 -0500)
committerFred T. Hamster <fred@feistymeow.org>
Thu, 12 Feb 2026 11:24:53 +0000 (06:24 -0500)
nucleus/library/application/callstack_tracker.cpp
nucleus/library/application/callstack_tracker.h
nucleus/library/application/memory_checker.cpp
nucleus/library/structures/static_memory_gremlin.cpp

index 1773ce58af39c2f3f6dbcc6d088c53bee40c41f4..eaae7eb41c65514ae7858a5caf5fcae1a0dea0fe 100644 (file)
 #include <stdio.h>
 #include <string.h>
 
-//using namespace application;
 using namespace basis;
-//using namespace configuration;
-//using namespace mathematics;
-//using namespace filesystem;
-//using namespace loggers;
-//using namespace structures;
-//using namespace textual;
-//using namespace timely;
-//using namespace unit_test;
-
-////#undef new
-//is this right way to clean that out..?
 
 namespace application {
 
@@ -68,7 +56,7 @@ basis::mutex &callstack_tracker::__callstack_tracker_synchronizer()
   as the memory checker.  it can allocate c++ objects and that kind of thing
   just fine.
 */
-callstack_tracker &program_wide_stack_trace()
+callstack_tracker &thread_wide_stack_trace()
 {
   auto_synchronizer l(callstack_tracker::__callstack_tracker_synchronizer());
 
@@ -114,15 +102,12 @@ callstack_tracker::callstack_tracker()
   _highest(0),
   _unusable(false)
 {
-//printf("callstack ctor\n");
 }
 
 callstack_tracker::~callstack_tracker()
 {
-//printf("!!!!!!!!!!!!!!!!!!   callstack dtor in\n");
   _unusable = true;
   WHACK(_bt);
-//printf("!!!!!!!!!!!!!!!!!!   callstack dtor out\n");
 }
 
 bool callstack_tracker::push_frame(const char *class_name, const char *func,
@@ -289,7 +274,7 @@ frame_tracking_instance::frame_tracking_instance(const char *class_name,
 {
   if (_frame_involved) {
 //printf("frametrackinst ctor in class=%s func=%s\n", class_name, func);
-    program_wide_stack_trace().push_frame(class_name, func, file, line);
+    thread_wide_stack_trace().push_frame(class_name, func, file, line);
 //printf("frametrackinst ctor out\n");
   }
 }
@@ -310,7 +295,7 @@ void frame_tracking_instance::clean()
 {
   if (_frame_involved) {
 //printf("frametrackinst clean\n");
-    program_wide_stack_trace().pop_frame();
+    thread_wide_stack_trace().pop_frame();
   }
   _frame_involved = false;
   free(_class); _class = NULL_POINTER;
@@ -343,7 +328,7 @@ void frame_tracking_instance::assign(const char *class_name, const char *func,
 void update_current_stack_frame_line_number(int line)
 {
 //printf("frametrackinst updatelinenum in\n");
-  program_wide_stack_trace().update_line(line);
+  thread_wide_stack_trace().update_line(line);
 //printf("frametrackinst updatelinenum out\n");
 }
 
index 0ef6bf44e672e62cb11c0d23df6b5f1105228a64..b01bb9ee9cb8cf3decf0ef8e8d200bd4a3153f67 100644 (file)
@@ -30,7 +30,7 @@ class callstack_tracker;
 
 //////////////
 
-callstack_tracker &program_wide_stack_trace();
+callstack_tracker &thread_wide_stack_trace();
   //!< a global object that can be used to track the runtime callstack.
 
 //hmmm: maybe borked on basis of the conflict between a global stack tracker and the fact that each thread has its own callstack!  argh!
@@ -111,8 +111,8 @@ private:
   from the embedding function.
 */
 #define GET_AND_TEST_STACK_TRACE(header, failure_return) { \
-  int trace_size = program_wide_stack_trace().full_trace_size(); \
-  char *stack_trace = program_wide_stack_trace().full_trace(); \
+  int trace_size = thread_wide_stack_trace().full_trace_size(); \
+  char *stack_trace = thread_wide_stack_trace().full_trace(); \
   ASSERT_TRUE(trace_size >= strlen(stack_trace) + 1, "insufficient estimated stack trace size"); \
   if (trace_size < strlen(stack_trace) + 1) { \
     /* error condition here; we are supposed to get the actual size we would need to allocate! */ \
index 85d46dccce1910f24653fdd0439f09012ef9e84e..b66e80568b2aa9db541ed5828564a174b90fa947 100644 (file)
@@ -1,6 +1,4 @@
 
-
-
 /*****************************************************************************\
 *                                                                             *
 *  Name   : memory_checker                                                    *
@@ -100,7 +98,7 @@ public:
     }
     _line = line;
 #ifdef ENABLE_CALLSTACK_TRACKING
-    _stack = program_wide_stack_trace().full_trace();
+    _stack = thread_wide_stack_trace().full_trace();
 ///printf("stack here:\n%s", _stack);
 #endif
   }
index 88ba32d447a770f71abb8bb774d4a707d06d1fc6..79184d1c13b6787d75840fcac4739dd145c0a7d8 100644 (file)
 using namespace application;
 using namespace basis;
 
-/* no.
-namespace application {
-
-//! the single instance of callstack_tracker.
-/ *! this is also an ultra low-level object, although it's not as far down
-as the memory checker.  it can allocate c++ objects and that kind of thing
-just fine.  the object must be stored here rather than in the static basis
-library due to issues in windows dlls.
-NOTE: this is also not thread safe; it must be initialized before any threads
-have started. * /
-
-//hmmm: why is this here?  because it needs to interact with the progwide memories?
-callstack_tracker &program_wide_stack_trace()
-{
-  static callstack_tracker *_hidden_trace = NULL_POINTER;
-  if (!_hidden_trace) {
-#ifdef ENABLE_MEMORY_HOOK
-    program_wide_memories().disable();
-      // we don't want infinite loops tracking the call stack during this
-      // object's construction.
-#endif
-    _hidden_trace = new callstack_tracker;
-#ifdef ENABLE_MEMORY_HOOK
-    program_wide_memories().enable();
-#endif
-  }
-  return *_hidden_trace;
-}
-
-} //namespace.
-*/
-
 namespace structures {
 
 //#define DEBUG_STATIC_MEMORY_GREMLIN
@@ -253,7 +221,7 @@ static_memory_gremlin &static_memory_gremlin::__hoople_globals()
 #endif
 
 #ifdef ENABLE_CALLSTACK_TRACKING
-    application::program_wide_stack_trace().full_trace_size();
+    application::thread_wide_stack_trace().full_trace_size();
       // invoke now to get callback tracking instantiated.
 #endif