asyncselect.cpp File Reference#include "lspdef.h" #include <windows.h> #include <strsafe.h>
Include dependency graph for asyncselect.cpp:
Go to the source code of this file.
Define Documentation
Definition at line 54 of file asyncselect.cpp.
Definition at line 53 of file asyncselect.cpp.
Definition at line 42 of file asyncselect.cpp.
Definition at line 43 of file asyncselect.cpp.
Definition at line 33 of file asyncselect.cpp.
Function Documentation
Definition at line 142 of file asyncselect.cpp. 00144 { 00145 HANDLE ReadyEvent = NULL; 00146 int rc; 00147 00148 EnterCriticalSection( &gCriticalSection ); 00149 if ( NULL == WorkerThreadHandle ) 00150 { 00151 // Create an event which the worker thread will signal when its ready 00152 ReadyEvent = CreateEvent( NULL, TRUE, FALSE, NULL ); 00153 if ( NULL == ReadyEvent ) 00154 { 00155 dbgprint("GetWorkerWindow: CreateEvent failed: %d", GetLastError() ); 00156 goto cleanup; 00157 } 00158 00159 // Create the asyn window message thread 00160 WorkerThreadHandle = CreateThread( 00161 NULL, 00162 0, 00163 AsyncMsgHandler, 00164 (LPVOID)ReadyEvent, 00165 0, 00166 NULL 00167 ); 00168 if ( NULL == WorkerThreadHandle ) 00169 { 00170 dbgprint( "GetWorkerWindow: CreateThread failed: %d", GetLastError() ); 00171 goto cleanup; 00172 } 00173 00174 // Wait for the window to become initialized 00175 rc = WaitForSingleObject( ReadyEvent, INFINITE ); 00176 if ( ( WAIT_FAILED == rc ) || ( WAIT_TIMEOUT == rc ) ) 00177 dbgprint( "GetWorkerWindow: WaitForSingleObject failed: %d! (error = %d)", 00178 rc, GetLastError() ); 00179 } 00180 00181 cleanup: 00182 00183 if ( NULL != ReadyEvent ) 00184 { 00185 // Close the ready event 00186 rc = CloseHandle( ReadyEvent ); 00187 if ( 0 == rc ) 00188 { 00189 dbgprint("GetWorkerWindow: CloseHandle failed: %d", GetLastError() ); 00190 } 00191 } 00192 00193 LeaveCriticalSection( &gCriticalSection ); 00194 00195 return AsyncWindow; 00196 }
Definition at line 96 of file asyncselect.cpp. 00098 { 00099 int rc, 00100 code; 00101 00102 if ( NULL != AsyncWindow ) 00103 { 00104 // Post a quit message to the thread 00105 PostMessage( AsyncWindow, WM_DESTROY, 0, 0 ); 00106 00107 // Wait for the thread to cleanup and exit 00108 rc = WaitForSingleObject( WorkerThreadHandle, 10000 ); 00109 if ( WAIT_TIMEOUT == rc ) 00110 { 00111 dbgprint("StopAsyncWindowManager: Timed out waiting for async thread!"); 00112 goto cleanup; 00113 } 00114 00115 // Retrieve the exit code and display a simple message 00116 rc = GetExitCodeThread( WorkerThreadHandle, (LPDWORD) &code ); 00117 if ( 0 == rc ) 00118 dbgprint("StopAsyncWindowManager: Unable to retrieve thread exit code: %d", 00119 GetLastError() ); 00120 else if ( 0 != code ) 00121 dbgprint("StopAsyncWindowManager: Async window thread exited abnormally!"); 00122 00123 cleanup: 00124 00125 CloseHandle( WorkerThreadHandle ); 00126 00127 WorkerThreadHandle = NULL; 00128 } 00129 00130 return 0; 00131 }
|