Cygwin: FIFO: improve taking ownership in fifo_reader_thread
When a reader takes ownership in fifo_reader_thread, it now goes directly to the part of the main loop that listens for a connection. Previously it went back to the beginning of the loop. Also, if the reader has to delay taking ownership because the previous owner has not finished updating the shared fifo_client handlers, it now checks to see if cancel_evt has been set. Previously it might have had to spin its wheels unnecessarily only to eventually find that its thread had been canceled.
This commit is contained in:
parent
1c0cf5f4f9
commit
6b8a829496
@ -462,26 +462,10 @@ fhandler_fifo::fifo_reader_thread_func ()
|
|||||||
take_ownership = true;
|
take_ownership = true;
|
||||||
else if (cur_owner != me)
|
else if (cur_owner != me)
|
||||||
idle = true;
|
idle = true;
|
||||||
if (take_ownership)
|
else
|
||||||
{
|
/* I'm the owner. */
|
||||||
if (!shared_fc_handler_updated ())
|
goto owner_listen;
|
||||||
{
|
if (idle)
|
||||||
owner_unlock ();
|
|
||||||
yield ();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
set_owner (me);
|
|
||||||
set_pending_owner (null_fr_id);
|
|
||||||
if (update_my_handlers () < 0)
|
|
||||||
api_fatal ("Can't update my handlers, %E");
|
|
||||||
owner_found ();
|
|
||||||
owner_unlock ();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (idle)
|
|
||||||
{
|
{
|
||||||
owner_unlock ();
|
owner_unlock ();
|
||||||
HANDLE w[2] = { owner_needed_evt, cancel_evt };
|
HANDLE w[2] = { owner_needed_evt, cancel_evt };
|
||||||
@ -495,9 +479,28 @@ fhandler_fifo::fifo_reader_thread_func ()
|
|||||||
api_fatal ("WFMO failed, %E");
|
api_fatal ("WFMO failed, %E");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else if (take_ownership)
|
||||||
{
|
{
|
||||||
/* I'm the owner */
|
if (!shared_fc_handler_updated ())
|
||||||
|
{
|
||||||
|
owner_unlock ();
|
||||||
|
if (IsEventSignalled (cancel_evt))
|
||||||
|
goto canceled;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
set_owner (me);
|
||||||
|
set_pending_owner (null_fr_id);
|
||||||
|
if (update_my_handlers () < 0)
|
||||||
|
api_fatal ("Can't update my handlers, %E");
|
||||||
|
owner_found ();
|
||||||
|
owner_unlock ();
|
||||||
|
/* Fall through to owner_listen. */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
owner_listen:
|
||||||
fifo_client_lock ();
|
fifo_client_lock ();
|
||||||
cleanup_handlers ();
|
cleanup_handlers ();
|
||||||
if (add_client_handler () < 0)
|
if (add_client_handler () < 0)
|
||||||
@ -590,7 +593,6 @@ fhandler_fifo::fifo_reader_thread_func ()
|
|||||||
fifo_client_unlock ();
|
fifo_client_unlock ();
|
||||||
if (cancel)
|
if (cancel)
|
||||||
goto canceled;
|
goto canceled;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
canceled:
|
canceled:
|
||||||
if (conn_evt)
|
if (conn_evt)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user