WaitChainCallback callback function
An application-defined callback function that receives a wait chain. Specify this address when calling the OpenThreadWaitChainSession function.
The PWAITCHAINCALLBACK type defines a pointer to this callback function. WaitChainCallback is a placeholder for the application-defined function name.
Syntax
VOID CALLBACK WaitChainCallback( HWCT WctHandle, DWORD_PTR Context, DWORD CallbackStatus, LPDWORD NodeCount, PWAITCHAIN_NODE_INFO NodeInfoArray, LPBOOL IsCycle );
Parameters
- WctHandle
-
A handle to the WCT session created by the OpenThreadWaitChainSession function.
- Context
-
A optional pointer to an application-defined context structure specified by the GetThreadWaitChain function.
- CallbackStatus
-
The callback status. This parameter can be one of the following values, or one of the other system error codes.
Value Meaning - ERROR_ACCESS_DENIED
The caller did not have sufficient privilege to open a target thread.
- ERROR_CANCELLED
The asynchronous session was canceled by a call to the CloseThreadWaitChainSession function.
- ERROR_MORE_DATA
The NodeInfoArray buffer is not large enough to contain all the nodes in the wait chain. The NodeCount parameter contains the number of nodes in the chain. The wait chain returned is still valid.
- ERROR_OBJECT_NOT_FOUND
The specified thread could not be located.
- ERROR_SUCCESS
The operation completed successfully.
- ERROR_TOO_MANY_THREADS
The number of nodes exceeds WCT_MAX_NODE_COUNT. The wait chain returned is still valid.
- NodeCount
-
The number of nodes retrieved, up to WCT_MAX_NODE_COUNT. If the array cannot contain all the nodes of the wait chain, the function fails, CallbackStatus is ERROR_MORE_DATA, and this parameter receives the number of array elements required to contain all the nodes.
- NodeInfoArray
-
An array of WAITCHAIN_NODE_INFO structures that receives the wait chain.
- IsCycle
-
If the function detects a deadlock, this variable is set to TRUE; otherwise, it is set to FALSE.
Return value
This callback function does not return a value.
Examples
It is common to pass an event handle to the callback function for communication purposes, as shown in the following code snippet.
///////////////////////////////////////////////////////// // Application-defined context data structure struct MyContext { HANDLE EventHnd; }; ///////////////////////////////////////////////////////// // Callback implementation void CALLBACK AppCallback( HWCT WctHnd, DWORD_PTR Context, DWORD CallbackStatus, LPDWORD NodeCount, PWAITCHAIN_NODE_INFO NodeInfoArray, LPBOOL IsCycle) { UNREFERENCED_PARAMETER(WctHnd); UNREFERENCED_PARAMETER(CallbackStatus); UNREFERENCED_PARAMETER(NodeCount); UNREFERENCED_PARAMETER(NodeInfoArray); UNREFERENCED_PARAMETER(IsCycle); SetEvent(((MyContext*)Context)->EventHnd); } void foo() { ///////////////////////////////////////////////////////// // Main query thread MyContext Cnxt; Cnxt.EventHnd = CreateEvent(NULL, TRUE, TRUE, TEXT("MyEvent")); DWORD NumNodeInfo = WCT_MAX_NODE_COUNT; WAITCHAIN_NODE_INFO NodeInfo[WCT_MAX_NODE_COUNT]; HWCT WctHnd = OpenThreadWaitChainSession(WCT_ASYNC_OPEN_FLAG, AppCallback); if (!GetThreadWaitChain(WctHnd, (DWORD_PTR)&Cnxt, 0, GetCurrentThreadId(), &NumNodeInfo, NodeInfo, FALSE)) { if (ERROR_IO_PENDING == GetLastError()) { // Wait for callback to run... WaitForSingleObject(Cnxt.EventHnd, INFINITE); } }
Requirements
|
Minimum supported client |
Windows Vista [desktop apps only] |
|---|---|
|
Minimum supported server |
Windows Server 2008 [desktop apps only] |
|
Header |
|
See also