<commit_before>#pragma once

extern "C" {
#include "osdep.h"
}

#include "kdebugprint.h"

#ifdef DBG
void NetKvmAssert(bool Statement, ULONG Code);
#define NETKVM_ASSERT(x) NetKvmAssert((x) ? true : false, __LINE__)
#else
#define NETKVM_ASSERT(x) for(;;) break
#endif

class CPlacementAllocatable
{
public:
    void* operator new(size_t size, void *ptr) throw()
    {
        UNREFERENCED_PARAMETER(size);
        return ptr;
    }
};

template <typename T, ULONG Tag>
class CNdisAllocatable
{
public:
    void* operator new(size_t Size, NDIS_HANDLE MiniportHandle) throw()
        { return NdisAllocateMemoryWithTagPriority(MiniportHandle, (UINT) Size, Tag, NormalPoolPriority); }

    static void Destroy(T *ptr, NDIS_HANDLE MiniportHandle)
    {
        ptr->~T();
        NdisFreeMemoryWithTagPriority(MiniportHandle, ptr, Tag);
    }

protected:
    CNdisAllocatable() {};
    ~CNdisAllocatable() {};

    /* Objects's array can't be freed by NdisFreeMemoryWithTagPriority, as C++ array constructor uses the
    * first several bytes for array length. Array  destructor can't get additional argument, so passing
    * NDIS_HANDLE to the array destructor is impossible. Therefore, the array constructors and destructor
    * are declared private and object arrays has be created and destroyed in two steps - construction by
    * allocating array memory with NdisAllocateMemoryWithTagPriority and then in-place constructing the
    * objects and destructing in the reverse order. */
    void* operator new[](size_t Size, NDIS_HANDLE MiniportHandle) throw() = delete;
    void* operator new[](size_t Size) throw() = delete;
    void operator delete[](void *) = delete;

private:
    /* The delete operator can't be disabled like array constructors and destructors, as default destructor
    * and default constructor depend on the delete operator availability */
    void operator delete(void *) {}
};

class CNdisSpinLock
{
public:
    CNdisSpinLock()
    { NdisAllocateSpinLock(&m_Lock); }
    ~CNdisSpinLock()
    { NdisFreeSpinLock(&m_Lock); }

#pragma warning(push)
#pragma warning(disable:28167) // The function changes IRQL and doesn't restore
    void Lock()
    { NdisAcquireSpinLock(&m_Lock); }
#pragma warning(disable:26110) // Caller failing to hold lock before calling function 'KeReleaseSpinLock'
    void Unlock()
    { NdisReleaseSpinLock(&m_Lock); }
#pragma warning(pop)

private:
    NDIS_SPIN_LOCK m_Lock;

    CNdisSpinLock(const CNdisSpinLock&) = delete;
    CNdisSpinLock& operator= (const CNdisSpinLock&) = delete;
};

template <typename T>
class CLockedContext
{
public:
    CLockedContext(T &LockObject)
        : m_LockObject(LockObject)
    { m_LockObject.Lock(); }

    ~CLockedContext()
    { m_LockObject.Unlock(); }

private:
    T &m_LockObject;

    CLockedContext(const CLockedContext&) = delete;
    CLockedContext& operator= (const CLockedContext&) = delete;
};

typedef CLockedContext<CNdisSpinLock> TSpinLocker;

class CNdisRefCounter
{
public:
    CNdisRefCounter() {}

    void AddRef() { NdisInterlockedIncrement(&m_Counter); }
    void AddRef(ULONG RefCnt);
    LONG Release() { return NdisInterlockedDecrement(&m_Counter); }
    LONG Release(ULONG RefCnt);
    operator LONG () { return m_Counter; }<commit_msg>NetKVM: Beautify CNdisRefCounter default constructor<commit_after>#pragma once

extern "C" {
#include "osdep.h"
}

#include "kdebugprint.h"

#ifdef DBG
void NetKvmAssert(bool Statement, ULONG Code);
#define NETKVM_ASSERT(x) NetKvmAssert((x) ? true : false, __LINE__)
#else
#define NETKVM_ASSERT(x) for(;;) break
#endif

class CPlacementAllocatable
{
public:
    void* operator new(size_t size, void *ptr) throw()
    {
        UNREFERENCED_PARAMETER(size);
        return ptr;
    }
};

template <typename T, ULONG Tag>
class CNdisAllocatable
{
public:
    void* operator new(size_t Size, NDIS_HANDLE MiniportHandle) throw()
        { return NdisAllocateMemoryWithTagPriority(MiniportHandle, (UINT) Size, Tag, NormalPoolPriority); }

    static void Destroy(T *ptr, NDIS_HANDLE MiniportHandle)
    {
        ptr->~T();
        NdisFreeMemoryWithTagPriority(MiniportHandle, ptr, Tag);
    }

protected:
    CNdisAllocatable() {};
    ~CNdisAllocatable() {};

    /* Objects's array can't be freed by NdisFreeMemoryWithTagPriority, as C++ array constructor uses the
    * first several bytes for array length. Array  destructor can't get additional argument, so passing
    * NDIS_HANDLE to the array destructor is impossible. Therefore, the array constructors and destructor
    * are declared private and object arrays has be created and destroyed in two steps - construction by
    * allocating array memory with NdisAllocateMemoryWithTagPriority and then in-place constructing the
    * objects and destructing in the reverse order. */
    void* operator new[](size_t Size, NDIS_HANDLE MiniportHandle) throw() = delete;
    void* operator new[](size_t Size) throw() = delete;
    void operator delete[](void *) = delete;

private:
    /* The delete operator can't be disabled like array constructors and destructors, as default destructor
    * and default constructor depend on the delete operator availability */
    void operator delete(void *) {}
};

class CNdisSpinLock
{
public:
    CNdisSpinLock()
    { NdisAllocateSpinLock(&m_Lock); }
    ~CNdisSpinLock()
    { NdisFreeSpinLock(&m_Lock); }

#pragma warning(push)
#pragma warning(disable:28167) // The function changes IRQL and doesn't restore
    void Lock()
    { NdisAcquireSpinLock(&m_Lock); }
#pragma warning(disable:26110) // Caller failing to hold lock before calling function 'KeReleaseSpinLock'
    void Unlock()
    { NdisReleaseSpinLock(&m_Lock); }
#pragma warning(pop)

private:
    NDIS_SPIN_LOCK m_Lock;

    CNdisSpinLock(const CNdisSpinLock&) = delete;
    CNdisSpinLock& operator= (const CNdisSpinLock&) = delete;
};

template <typename T>
class CLockedContext
{
public:
    CLockedContext(T &LockObject)
        : m_LockObject(LockObject)
    { m_LockObject.Lock(); }

    ~CLockedContext()
    { m_LockObject.Unlock(); }

private:
    T &m_LockObject;

    CLockedContext(const CLockedContext&) = delete;
    CLockedContext& operator= (const CLockedContext&) = delete;
};

typedef CLockedContext<CNdisSpinLock> TSpinLocker;

class CNdisRefCounter
{
public:
    CNdisRefCounter() = default;

    void AddRef() { NdisInterlockedIncrement(&m_Counter); }
    void AddRef(ULONG RefCnt);
    LONG Release() { return NdisInterlockedDecrement(&m_Counter); }
    LONG Release(ULONG RefCnt);
    operator LONG () { return m_Counter; }
{'fraction_non_alphanumeric': 0.09769852156683433, 'fraction_numerical': 0.0030483158055174516, 'mean_word_length': 4.28341384863124, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4712429', 'n_tokens_mistral': 2081, 'n_tokens_neox': 2007, 'n_words': 579}