/* List of threads currently waiting for dispatch */
virNetClientCallPtr waitDispatch;
+ /* True if a thread holds the buck */
+ bool haveTheBuck;
size_t nstreams;
virNetClientStreamPtr *streams;
thiscall->msg->bufferLength,
client->waitDispatch);
+ /* Stick ourselves on the end of the wait queue */
+ virNetClientCallQueue(&client->waitDispatch, thiscall);
+
/* Check to see if another thread is dispatching */
- if (client->waitDispatch) {
+ if (client->haveTheBuck) {
char ignore = 1;
- /* Stick ourselves on the end of the wait queue */
- virNetClientCallQueue(&client->waitDispatch, thiscall);
/* Force other thread to wakeup from poll */
if (safewrite(client->wakeupSendFD, &ignore, sizeof(ignore)) != sizeof(ignore)) {
}
/* Grr, someone passed the buck onto us ... */
- } else {
- /* We're the first to arrive */
- virNetClientCallQueue(&client->waitDispatch, thiscall);
}
VIR_DEBUG("We have the buck %p %p", client->waitDispatch, thiscall);
+ client->haveTheBuck = true;
+
/*
* The buck stops here!
*
virGetLastError())
rv = -1;
+ client->haveTheBuck = false;
+
cleanup:
VIR_DEBUG("All done with our call %p %p %d", client->waitDispatch, thiscall, rv);
return rv;
goto done;
/* This should be impossible, but it doesn't hurt to check */
- if (client->waitDispatch)
+ if (client->haveTheBuck)
goto done;
VIR_DEBUG("Event fired %p %d", sock, events);