The next_timeout
value is there to prevent you from calling sp_session_process_events
too frequently, and is not necessarily intended to reduce the number of main thread 'wake-ups'. I don't see anything unusual about the timeout values you're seeing.
The notify_main_thread
callback is often invoked from sp_session_process_events
, which you should be calling from the main thread anyway. This shouldn't cause you huge problems. I suppose you could add some extra logic to stay in the event loop rather than signalling in those cases, but that could require more synchronisation than you already have.