Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make_event_watcher requires the event handle have EVENT_MODIFY_STATE #482

Open
jonwis opened this issue Oct 30, 2024 · 0 comments
Open

make_event_watcher requires the event handle have EVENT_MODIFY_STATE #482

jonwis opened this issue Oct 30, 2024 · 0 comments
Labels
feature-request New feature or request improvement Something that would improve the repo in some way

Comments

@jonwis
Copy link
Member

jonwis commented Oct 30, 2024

Consider this:

struct event_and_watcher {
    wil::unique_event eventName;
    wil::unique_event_watcher watcher;
};
event_and_watcher make_event_watcher(wchar_t const* name, void (*pfn)()) {
    event_and_watcher retval;
    if (retval.eventName.try_open(name, SYNCHRONIZE)) {
        retval.watcher = wil::make_event_watcher(retval.eventName.get(), pfn);
    }
    return retval;
}
auto g_w = make_event_watcher(L"AnotherEventName", [] { ReactToEvent(); });

When the event is signaled and the TP wait callback is invoked here:

wil/include/wil/resource.h

Lines 3915 to 3924 in 6f60a1b

static void CALLBACK wait_callback(PTP_CALLBACK_INSTANCE, void* context, TP_WAIT* pThreadPoolWait, TP_WAIT_RESULT)
{
auto pThis = static_cast<details::event_watcher_state*>(context);
// Manual events must be re-set to avoid missing the last notification.
pThis->m_event.ResetEvent();
// Call the client before re-arming to ensure that multiple callbacks don't
// run concurrently.
pThis->m_callback();
SetThreadpoolWait(pThreadPoolWait, pThis->m_event.get(), nullptr); // valid params ensure success
}

... the ResetEvent fails with a failfast:

wil/include/wil/resource.h

Lines 2502 to 2505 in 6f60a1b

inline void __stdcall ResetEvent(HANDLE h) WI_NOEXCEPT
{
__FAIL_FAST_ASSERT_WIN32_BOOL_FALSE__(::ResetEvent(h));
}

... because I don't have Reset rights, only Synchronize.

Consider a policy flag to make that Reset optional.

@dunhor dunhor added feature-request New feature or request improvement Something that would improve the repo in some way labels Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request improvement Something that would improve the repo in some way
Projects
None yet
Development

No branches or pull requests

2 participants