Rewrite raw memcard threading code. Intended to fix issue 7484.

Also, what happens here if the flush trigger was set and a thread calls WaitFlushComplete() before the flush thread has had the occasion to schedule? This seems unsafe from a quick glance.