My idea was how to get rid of the loop, since you were mentioning that would be nice — with the standard Cond, Mutex, bool pattern. We use it a lot with eg SafeCond; you could look at people who use that in the Ceph code.