commaai / msgq

MSGQ: A lock free single producer multi consumer message queue
184 stars 251 forks source link

msgq: refactor blocking recv for improved robustness and performance #616

Open deanlee opened 5 months ago

deanlee commented 5 months ago

Replaced the previous method of installing, saving, and restoring signal handlers with a more streamlined and standard approach using signal masks (pthread_sigmask, sigtimedwait) for blocking receive operations. This update enhances the consistency and reliability of signal handling, aligning with best practices. It also removes the need for msgq_poll, thereby improving the efficiency of the receive function.

Additionally, a new test case, test_receive_interrupts_on_sigint, has been added to confirm and verify the functionality of the updated signal handling.

Since signal blocking is now managed in the C++ code, nogil is used in the Cython code to ensure the GIL is released during the execution of the receive function. This prevents it from impacting other Python threads.