Skip to content

Keep the queue free while receiving messages

Zeeshan Ali Khan requested to merge zeenix/queue-lock into main

Apart from other fixes in this MR, the main one is that we now keep the queue unlocked when waiting for new messages on the socket in azync::Connection::receive_specific. E.g imagine the following series of events:

  1. queue is empty and receive_specific is called. The call will lock the queue and since there are no messages on it, it'll go straight to receiving the message directly from the socket. Until a message arrives, this call will yield.
  2. another call is made to receive_specific and this has to wait for the queue to be free. i-e it yields as well.
  3. a 3rd call to receive_specific is made and this one has the same fate as the last one.
  4. A message arrives, continuing the first call but the message is not of its interest so it puts it in the queue. This message is of interest to the 3rd caller though. The loop iteration finishes and so does the block and message queue is unlocked.
  5. The second call gets the queue lock but since the only message in the queue is not of its interest, it now starts to wait on the socket.

Now until another message arrives on the socket, the 3rd call is unable to get its message. This commit fixes the problem by only keeping the queue locked when queue is read or written to.

Merge request reports