Skip to content

Replace static_lazy<> with normal statics #471

Open
@jonwis

Description

template <class T>
class static_lazy
{
public:
void __cdecl cleanup() WI_NOEXCEPT
{
void* pVoid;
BOOL pending;
// If object is being constructed on another thread, wait until construction completes.
// Need a memory barrier here (see get() and ~Completer below) so use the result that we
// get from InitOnceBeginInitialize(..., &pVoid, ...)
if (::InitOnceBeginInitialize(&m_initOnce, INIT_ONCE_CHECK_ONLY, &pending, &pVoid) && !pending)
{
static_cast<T*>(pVoid)->~T();
}
}

According to https://learn.microsoft.com/en-us/cpp/cpp/storage-classes-cpp?view=msvc-170, function-local "magic statics" are fully supported.

Instead of defining a custom static_lazy type, use the built-in support.

  1. Remove static_lazy<>
  2. On line 2283ish in the Instance() method:
static TraceLoggingClassName* Instance() WI_NOEXCEPT \
{ \
    static TraceLoggingClassName wrapper; \
    return wrapper; \
} \
friend class wil::details::static_lazy<TraceLoggingClassName>;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    improvementSomething that would improve the repo in some way

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions