Fix a race-condition when transferring messages
Fix a race-condition when transferring messages

Since the queue operations which allocate the fresh ids are generated
before the global queue ref is updated, one thread can allocate an id
and trigger another thread to unblock in a transfer. Unfortunately the
unblocked thread will encounter no new messages and wastefully return
this to the client. If the request id never gets seen -- possibly because
a parallel client consumed it -- then the client can spam the server with
rpcs trying to discover this message.

This patch moves the waiting to the effectful-layer in switch_main.ml.
For now we maintain a global condition variable and broadcast on it
whenever the global queues reference is updated. The transfer RPC will
block server-side until the results of the transfer will be non-empty.

Signed-off-by: David Scott <63c9eb0ea83039690fefa11afe17873ba8278a56@citrix.com>

djs55/message-switch,djs55/message-switch-1,djs55/message-switch,xapi-project/message-switch,xapi-project/message-switch,djs55/message-switch,djs55/message-switch-1,djs55/message-switch-1,xapi-project/message-switch