Missing some `Threadpool` APIs
JunkuiZhang opened this issue · comments
I have been studying the Windows API recently, and while going through this example , I noticed that many Threadpool-related APIs are missing in windows-rs
. For instance, functions like InitializeThreadpoolEnvironment
, SetThreadpoolCallbackPool
, and SetThreadpoolCallbackCleanupGroup
are missing. And they all seem to be related to PTP_CALLBACK_ENVIRON
. While I found TP_CALLBACK_ENVIRON_V3
in windows-rs
which is just a struct, and I couldn't find any functions to generate it. So, how should I go about using these APIs?
https://kennykerr.ca/rust-getting-started/how-are-crates-built.html
Strange that some of the thread pool APIs are present but some are missing. I'll transfer to the Win32 metadata repo for resolution.
Most likely because they're inline function and not simply imports.
Ah, yes:
FORCEINLINE
VOID
InitializeThreadpoolEnvironment(
_Out_ PTP_CALLBACK_ENVIRON pcbe
)
{
TpInitializeCallbackEnviron(pcbe);
}
FORCEINLINE
VOID
SetThreadpoolCallbackPool(
_Inout_ PTP_CALLBACK_ENVIRON pcbe,
_In_ PTP_POOL ptpp
)
{
TpSetCallbackThreadpool(pcbe, ptpp);
}
FORCEINLINE
VOID
SetThreadpoolCallbackCleanupGroup(
_Inout_ PTP_CALLBACK_ENVIRON pcbe,
_In_ PTP_CLEANUP_GROUP ptpcg,
_In_opt_ PTP_CLEANUP_GROUP_CANCEL_CALLBACK pfng
)
{
TpSetCallbackCleanupGroup(pcbe, ptpcg, pfng);
}
FORCEINLINE
VOID
SetThreadpoolCallbackRunsLong(
_Inout_ PTP_CALLBACK_ENVIRON pcbe
)
{
TpSetCallbackLongFunction(pcbe);
}
FORCEINLINE
VOID
SetThreadpoolCallbackLibrary(
_Inout_ PTP_CALLBACK_ENVIRON pcbe,
_In_ PVOID mod
)
{
TpSetCallbackRaceWithDll(pcbe, mod);
}
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN7)
FORCEINLINE
VOID
SetThreadpoolCallbackPriority(
_Inout_ PTP_CALLBACK_ENVIRON pcbe,
_In_ TP_CALLBACK_PRIORITY Priority
)
{
TpSetCallbackPriority(pcbe, Priority);
}
#endif
FORCEINLINE
VOID
DestroyThreadpoolEnvironment(
_Inout_ PTP_CALLBACK_ENVIRON pcbe
)
{
TpDestroyCallbackEnviron(pcbe);
}
FORCEINLINE
VOID
SetThreadpoolCallbackPersistent(
_Inout_ PTP_CALLBACK_ENVIRON pcbe
)
{
TpSetCallbackPersistent(pcbe);
}
Of course, in such cases you can just look at the inline implementation and mirror that in Rust. They are generally trivial.
Of course, in such cases you can just look at the inline implementation and mirror that in Rust. They are generally trivial.
Thank you very much for your response. I'm sorry to bother you again, but since I'm still learning, I have another perhaps silly question. I noticed that the function TpInitializeCallbackEnviron
is also missing in Windows-rs, and of course it's an inline function as well.
FORCEINLINE
VOID
TpInitializeCallbackEnviron(
_Out_ PTP_CALLBACK_ENVIRON CallbackEnviron
)
{
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN7)
CallbackEnviron->Version = 3;
#else
CallbackEnviron->Version = 1;
#endif
CallbackEnviron->Pool = NULL;
CallbackEnviron->CleanupGroup = NULL;
CallbackEnviron->CleanupGroupCancelCallback = NULL;
CallbackEnviron->RaceDll = NULL;
CallbackEnviron->ActivationContext = NULL;
CallbackEnviron->FinalizationCallback = NULL;
CallbackEnviron->u.Flags = 0;
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN7)
CallbackEnviron->CallbackPriority = TP_CALLBACK_PRIORITY_NORMAL;
CallbackEnviron->Size = sizeof(TP_CALLBACK_ENVIRON);
#endif
}
So, I guess I need to implement a similar function in Rust?
Yep!
Yep!
I tested, and works fine. Thx!
Most likely because they're inline function and not simply imports.
Thank you!