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

Simplify description of the SList data structure #100107

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions src/coreclr/inc/slist.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,20 @@ struct SLink
}
};

class SListBase
{
public:
// used as sentinel
SLink m_link; // slink.m_pNext == Null
PTR_SLink m_pHead;
PTR_SLink m_pTail;
};

//------------------------------------------------------------------
// class SList. Intrusive singly linked list.
//
// To use SList with the default instantiation, your class should
// define a data member of type SLink and named 'm_Link'. To use a
// different field name, you need to provide an explicit LinkPtr
// template argument. For example:
// 'SList<MyClass, false, MyClass*, &MyClass::m_FieldName>'
// define a data member of type SLink and named 'm_Link'.
//
// SList has two different behaviours depending on boolean
// fHead variable,
Expand All @@ -104,25 +110,20 @@ struct SLink
// argument 'fHead'
// so there is no actual code size increase
//--------------------------------------------------------------
template <class T, bool fHead = false, typename __PTR = T*, SLink T::*LinkPtr = &T::m_Link>
class SList
template <class T, bool fHead = false, typename __PTR = T*>
class SList : protected SListBase
{
public:
// typedef used by the Queue class below
typedef T ENTRY_TYPE;

protected:

// used as sentinel
SLink m_link; // slink.m_pNext == Null
PTR_SLink m_pHead;
PTR_SLink m_pTail;

// get the list node within the object
static SLink* GetLink (T* pLink)
{
LIMITED_METHOD_DAC_CONTRACT;
return &(pLink->*LinkPtr);
return &(pLink->m_Link);
}

// move to the beginning of the object given the pointer within the object
Expand All @@ -138,10 +139,10 @@ class SList
#if 1
// Newer compilers define offsetof to be __builtin_offsetof, which doesn't use the
// old-school memory model trick to determine offset.
const UINT_PTR offset = (((UINT_PTR)&(((T *)0x1000)->*LinkPtr))-0x1000);
const UINT_PTR offset = (((UINT_PTR)&(((T *)0x1000)->m_Link))-0x1000);
return (T*)__PTR(dac_cast<TADDR>(pLink) - offset);
#else
return (T*)__PTR(dac_cast<TADDR>(pLink) - offsetof(T, *LinkPtr));
return (T*)__PTR(dac_cast<TADDR>(pLink) - offsetof(T, m_Link));
#endif
}
}
Expand Down
Loading