Small refactoring in wxFileSystemWatcher MSW implementation.
Make wxIOCPService::GetStatus() smarter about its return value, it makes sense to encapsulate the convention used to indicate the thread exit condition inside wxIOCPService class itself instead of sharing it between it wxIOCPThread itself. It will also make it easier to detect more detailed error conditions in this code. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76185 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -206,6 +206,7 @@ public:
|
|||||||
{
|
{
|
||||||
wxCHECK_MSG( m_iocp != INVALID_HANDLE_VALUE, false, "IOCP not init" );
|
wxCHECK_MSG( m_iocp != INVALID_HANDLE_VALUE, false, "IOCP not init" );
|
||||||
|
|
||||||
|
// The special values of 0 will make GetStatus() return Status_Exit.
|
||||||
int ret = PostQueuedCompletionStatus(m_iocp, 0, 0, NULL);
|
int ret = PostQueuedCompletionStatus(m_iocp, 0, 0, NULL);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
{
|
{
|
||||||
@@ -215,25 +216,41 @@ public:
|
|||||||
return ret != 0;
|
return ret != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Possible return values of GetStatus()
|
||||||
|
enum Status
|
||||||
|
{
|
||||||
|
// Status successfully retrieved into the provided arguments.
|
||||||
|
Status_OK,
|
||||||
|
|
||||||
|
// Special status indicating that we should exit retrieved.
|
||||||
|
Status_Exit,
|
||||||
|
|
||||||
|
// Some error occurred.
|
||||||
|
Status_Error
|
||||||
|
};
|
||||||
|
|
||||||
// Wait for completion status to arrive.
|
// Wait for completion status to arrive.
|
||||||
// This function can block forever in it's wait for completion status.
|
// This function can block forever in it's wait for completion status.
|
||||||
// Use PostEmptyStatus() to wake it up (and end the worker thread)
|
// Use PostEmptyStatus() to wake it up (and end the worker thread)
|
||||||
bool GetStatus(unsigned long* count, wxFSWatchEntryMSW** watch,
|
Status
|
||||||
OVERLAPPED** overlapped)
|
GetStatus(unsigned long* count, wxFSWatchEntryMSW** watch,
|
||||||
|
OVERLAPPED** overlapped)
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( m_iocp != INVALID_HANDLE_VALUE, false, "IOCP not init" );
|
wxCHECK_MSG( m_iocp != INVALID_HANDLE_VALUE, Status_Error,
|
||||||
wxCHECK_MSG( count != NULL, false, "Null out parameter 'count'");
|
"Invalid IOCP object" );
|
||||||
wxCHECK_MSG( watch != NULL, false, "Null out parameter 'watch'");
|
wxCHECK_MSG( count && watch && overlapped, Status_Error,
|
||||||
wxCHECK_MSG( overlapped != NULL, false,
|
"Output parameters can't be NULL" );
|
||||||
"Null out parameter 'overlapped'");
|
|
||||||
|
|
||||||
int ret = GetQueuedCompletionStatus(m_iocp, count, (ULONG_PTR *)watch,
|
int ret = GetQueuedCompletionStatus(m_iocp, count, (ULONG_PTR *)watch,
|
||||||
overlapped, INFINITE);
|
overlapped, INFINITE);
|
||||||
if (!ret)
|
if ( ret != 0 )
|
||||||
{
|
{
|
||||||
wxLogSysError(_("Unable to dequeue completion packet"));
|
return *count || *watch || *overlapped ? Status_OK : Status_Exit;
|
||||||
}
|
}
|
||||||
return ret != 0;
|
|
||||||
|
wxLogSysError(_("Unable to dequeue completion packet"));
|
||||||
|
|
||||||
|
return Status_Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@@ -224,12 +224,17 @@ bool wxIOCPThread::ReadEvents()
|
|||||||
unsigned long count = 0;
|
unsigned long count = 0;
|
||||||
wxFSWatchEntryMSW* watch = NULL;
|
wxFSWatchEntryMSW* watch = NULL;
|
||||||
OVERLAPPED* overlapped = NULL;
|
OVERLAPPED* overlapped = NULL;
|
||||||
if (!m_iocp->GetStatus(&count, &watch, &overlapped))
|
switch ( m_iocp->GetStatus(&count, &watch, &overlapped) )
|
||||||
return true; // error was logged already, we don't want to exit
|
{
|
||||||
|
case wxIOCPService::Status_OK:
|
||||||
|
break; // nothing special to do, continue normally
|
||||||
|
|
||||||
// this is our exit condition, so we return false
|
case wxIOCPService::Status_Error:
|
||||||
if (!count && !watch && !overlapped)
|
return true; // error was logged already, we don't want to exit
|
||||||
return false;
|
|
||||||
|
case wxIOCPService::Status_Exit:
|
||||||
|
return false; // stop reading events
|
||||||
|
}
|
||||||
|
|
||||||
// if the thread got woken up but we got an empty packet it means that
|
// if the thread got woken up but we got an empty packet it means that
|
||||||
// there was an overflow, too many events and not all could fit in
|
// there was an overflow, too many events and not all could fit in
|
||||||
|
Reference in New Issue
Block a user