You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
924 B

​
​
​
​
​
​
Event heap: fix hangs on shutdown (signal / web exit) and dispatch deadlocks Why the shutdown could hang: the event heap was never stopped, and its thread called every handler's dispatchEvent() while holding the handler list mutex. ~mojoKernel deletes the node / module factories, filters, media helper ... - all of them event handlers - while the heap kept calling into them (half-destroyed objects, destroyed mutexes); the deleting thread then waited forever in removeHandler() for the mutex the dispatch thread held. A dispatchEvent() that created or deleted a handler deadlocked the dispatch thread itself (non-recursive mutex). basicEventHeap: - Handlers are called without the list locked (snapshot + "still registered" check per handler); removeHandler() waits until the handler is no longer being called (5 s cap, logged), except when called from that very dispatchEvent(). - New pause() / resume() / flush() / clearQueue() and destroyInstance() (stops the thread; leaves it alone if a handler is stuck instead of hanging); existingInstance(); getInstance() is thread-safe. basicEventHandler: - detachEvents(): stop delivery first thing in a destructor (the base destructor runs only after the derived members are gone); basicEventHandler(false) + attachEvents(): register at the end of the constructor (registration in the base constructor lets the heap call into an object whose members are not built yet). Defaults unchanged. - Removal never creates a new heap (late destructors after exit). la_mojo: - ~mojoKernel: deliver queued events (2 s), pause the heap before deleting the components, drop what was queued during the teardown; the next kernel (restart) resumes it. - mojoBackend: destroyInstance() before the log is deleted at exit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
1 hour ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Event heap: fix hangs on shutdown (signal / web exit) and dispatch deadlocks Why the shutdown could hang: the event heap was never stopped, and its thread called every handler's dispatchEvent() while holding the handler list mutex. ~mojoKernel deletes the node / module factories, filters, media helper ... - all of them event handlers - while the heap kept calling into them (half-destroyed objects, destroyed mutexes); the deleting thread then waited forever in removeHandler() for the mutex the dispatch thread held. A dispatchEvent() that created or deleted a handler deadlocked the dispatch thread itself (non-recursive mutex). basicEventHeap: - Handlers are called without the list locked (snapshot + "still registered" check per handler); removeHandler() waits until the handler is no longer being called (5 s cap, logged), except when called from that very dispatchEvent(). - New pause() / resume() / flush() / clearQueue() and destroyInstance() (stops the thread; leaves it alone if a handler is stuck instead of hanging); existingInstance(); getInstance() is thread-safe. basicEventHandler: - detachEvents(): stop delivery first thing in a destructor (the base destructor runs only after the derived members are gone); basicEventHandler(false) + attachEvents(): register at the end of the constructor (registration in the base constructor lets the heap call into an object whose members are not built yet). Defaults unchanged. - Removal never creates a new heap (late destructors after exit). la_mojo: - ~mojoKernel: deliver queued events (2 s), pause the heap before deleting the components, drop what was queued during the teardown; the next kernel (restart) resumes it. - mojoBackend: destroyInstance() before the log is deleted at exit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
1 hour ago
​
​
​
​
​
​
​
​
​
​
​
Event heap: fix hangs on shutdown (signal / web exit) and dispatch deadlocks Why the shutdown could hang: the event heap was never stopped, and its thread called every handler's dispatchEvent() while holding the handler list mutex. ~mojoKernel deletes the node / module factories, filters, media helper ... - all of them event handlers - while the heap kept calling into them (half-destroyed objects, destroyed mutexes); the deleting thread then waited forever in removeHandler() for the mutex the dispatch thread held. A dispatchEvent() that created or deleted a handler deadlocked the dispatch thread itself (non-recursive mutex). basicEventHeap: - Handlers are called without the list locked (snapshot + "still registered" check per handler); removeHandler() waits until the handler is no longer being called (5 s cap, logged), except when called from that very dispatchEvent(). - New pause() / resume() / flush() / clearQueue() and destroyInstance() (stops the thread; leaves it alone if a handler is stuck instead of hanging); existingInstance(); getInstance() is thread-safe. basicEventHandler: - detachEvents(): stop delivery first thing in a destructor (the base destructor runs only after the derived members are gone); basicEventHandler(false) + attachEvents(): register at the end of the constructor (registration in the base constructor lets the heap call into an object whose members are not built yet). Defaults unchanged. - Removal never creates a new heap (late destructors after exit). la_mojo: - ~mojoKernel: deliver queued events (2 s), pause the heap before deleting the components, drop what was queued during the teardown; the next kernel (restart) resumes it. - mojoBackend: destroyInstance() before the log is deleted at exit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
1 hour ago
  1. #include "basicEventHandler.h"
  2. #include "basicEventHeap.h"
  3. // Constructor implementation
  4. basicEventHandler::basicEventHandler()
  5. {
  6. m_bEventsAttached = false;
  7. attachEvents();
  8. }
  9. basicEventHandler::basicEventHandler(bool attach)
  10. {
  11. m_bEventsAttached = false;
  12. if ( attach ) attachEvents();
  13. }
  14. void basicEventHandler::attachEvents(void)
  15. {
  16. if ( m_bEventsAttached ) return;
  17. m_bEventsAttached = true;
  18. basicEventHeap::getInstance()->addHandler( this, true );
  19. }
  20. void basicEventHandler::detachEvents(void)
  21. {
  22. if ( ! m_bEventsAttached ) return;
  23. m_bEventsAttached = false;
  24. // Only an existing heap: after basicEventHeap::destroyInstance() (application exit) a late
  25. // destructor must not create a new heap and dispatch thread
  26. basicEventHeap * tHeap = basicEventHeap::existingInstance();
  27. if ( tHeap ) tHeap->removeHandler( this );
  28. }
  29. // Destructor implementation
  30. basicEventHandler::~basicEventHandler()
  31. {
  32. detachEvents();
  33. }