util::IntrusiveList: assert member referencing is correct

This commit is contained in:
Michael Scire 2020-01-16 00:30:42 -08:00
parent 0751db5d12
commit 769a57526c
4 changed files with 11 additions and 5 deletions

View file

@ -22,11 +22,11 @@ namespace ams::os::impl {
class WaitableManagerImpl; class WaitableManagerImpl;
class WaitableHolderBase { class WaitableHolderBase {
private:
WaitableManagerImpl *manager = nullptr;
public: public:
util::IntrusiveListNode manager_node; util::IntrusiveListNode manager_node;
util::IntrusiveListNode object_list_node; util::IntrusiveListNode object_list_node;
private:
WaitableManagerImpl *manager = nullptr;
public: public:
/* Gets whether the held waitable is currently signaled. */ /* Gets whether the held waitable is currently signaled. */
virtual TriBool IsSignaled() const = 0; virtual TriBool IsSignaled() const = 0;

View file

@ -561,6 +561,9 @@ namespace ams::util {
static constexpr Derived const &GetParent(IntrusiveListNode const &node) { static constexpr Derived const &GetParent(IntrusiveListNode const &node) {
return util::GetParentReference<Member, Derived>(&node); return util::GetParentReference<Member, Derived>(&node);
} }
private:
static constexpr TYPED_STORAGE(Derived) DerivedStorage = {};
static_assert(std::addressof(GetParent(GetNode(GetReference(DerivedStorage)))) == GetPointer(DerivedStorage));
}; };
template<class Derived> template<class Derived>

View file

@ -250,11 +250,11 @@ namespace ams::util {
friend class IntrusiveRedBlackTree; friend class IntrusiveRedBlackTree;
static constexpr IntrusiveRedBlackTreeNode *GetNode(Derived *parent) { static constexpr IntrusiveRedBlackTreeNode *GetNode(Derived *parent) {
return &(parent->*Member); return std::addressof(parent->*Member);
} }
static constexpr IntrusiveRedBlackTreeNode const *GetNode(Derived const *parent) { static constexpr IntrusiveRedBlackTreeNode const *GetNode(Derived const *parent) {
return &(parent->*Member); return std::addressof(parent->*Member);
} }
static constexpr Derived *GetParent(IntrusiveRedBlackTreeNode *node) { static constexpr Derived *GetParent(IntrusiveRedBlackTreeNode *node) {
@ -264,6 +264,9 @@ namespace ams::util {
static constexpr Derived const *GetParent(IntrusiveRedBlackTreeNode const *node) { static constexpr Derived const *GetParent(IntrusiveRedBlackTreeNode const *node) {
return util::GetParentPointer<Member, Derived>(node); return util::GetParentPointer<Member, Derived>(node);
} }
private:
static constexpr TYPED_STORAGE(Derived) DerivedStorage = {};
static_assert(std::addressof(GetParent(GetNode(GetPointer(DerivedStorage)))) == GetPointer(DerivedStorage));
}; };
template<class Derived> template<class Derived>

View file

@ -169,7 +169,7 @@ namespace ams::util {
/* Defines, for use by other code. */ /* Defines, for use by other code. */
#define OFFSETOF(parent, member) (::ams::util::OffsetOf<&parent::member, parent>) #define OFFSETOF(parent, member) (::ams::util::impl::OffsetOf<&parent::member, parent>)
#define GET_PARENT_PTR(parent, member, _arg) (::ams::util::GetParentPointer<&parent::member, parent>(_arg)) #define GET_PARENT_PTR(parent, member, _arg) (::ams::util::GetParentPointer<&parent::member, parent>(_arg))