Fix a race condition in the mmdevapi message queue thread