check for thread exit without locking

In order to remove locking on the enqueuing path, we will restrict
the critical section progressively.

Here we start by managing the thread count without locks (except for
spawning which is not a fast path).  Of course, one should prove that
a thread is always there to process a newly submitted request!

If qemu_sem_wait succeeds, the request will always be processed.
If idle_threads > 1, the decrement of idle_threads does not make a
difference to qemu_paio_submit.  Thus, the only "risky" case happens
if there is only one thread (so cur_threads = idle_threads = 1) and the
idle aio_thread receives a timeout.

To fix this case, the patch moves the spawning of the new thread after
the update.  The submitter proceeds merrily, since it guesses the idle
thread will pick up its post.  The aio_thread decreases idle_threads
and cur_threads to zero and then checks for newly submitted request(s).
If there is one, it pushes cur_threads back to one and fetches another
AIOCB.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
lockless access to aiocb->ret and aiocb->queued

aiocb->state can be accessed lockless if we leave the removal from
the request_list to the thread-pool to the worker threads.

With two concurrent cancellations, either both will block waiting
for completion, or one of them will fail the cmpxchg and see
THREAD_CANCELLED or THREAD_DONE.  It will then exit immediately.

Drawback: if the pool is full, cancelling new requests will have
to wait for one request to complete.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
split locks

The lock is now used for two very different things: starting threads
and access to the queue.  Keep them separate.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
change request_list to QSIMPLEQ

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block: add reference counting to BlockDriverAIOCB

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
wait-free enqueuing of requests

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>