This is an archive of the discontinued LLVM Phabricator instance.

tsan: add intrusive doubly-linked list
ClosedPublic

Authored by dvyukov on Jul 29 2021, 2:42 AM.

Details

Summary

Add intrusive doubly-linked list container template, IList.
It will be used in the new tsan runtime.

Diff Detail

Event Timeline

dvyukov created this revision.Jul 29 2021, 2:42 AM
dvyukov requested review of this revision.Jul 29 2021, 2:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 29 2021, 2:42 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
melver accepted this revision.Jul 29 2021, 6:51 AM
melver added inline comments.
compiler-rt/lib/tsan/rtl/tsan_ilist.h
20

I thought about if some of it could be made nicer/safer, but don't think it can.

In theory, this could be nicer if you only ever needed to add an element to 1 list, which would allow doing template <typename Node> class INode and requiring the containing class Foo to inherit from INode<Foo>.

But looking at the rest of tsanv3 changes, it seems you need the ability to add an INode more than once since an element might be added to more than 1 list.

While not the prettiest, I think it requires INode* to be part of template arguments of IList, and no other way to do better.

It would be nice to document this requirement, because it makes it clearer why you came up with this design.

176

reinterpret_cast<Base*> instead of C-style (Base*) ?

This revision is now accepted and ready to land.Jul 29 2021, 6:51 AM
dvyukov updated this revision to Diff 362781.Jul 29 2021, 7:54 AM
dvyukov marked an inline comment as done.

added comment re template arguments
replaced C casts with C++ casts

dvyukov added inline comments.Jul 29 2021, 7:56 AM
compiler-rt/lib/tsan/rtl/tsan_ilist.h
20

Added an explanatory comment.
In practice it's not that bad, because the verbose template arguments are specified only once on the list type declarations.

This revision was landed with ongoing or failed builds.Jul 29 2021, 8:07 AM
This revision was automatically updated to reflect the committed changes.

Hi @dvyukov, this patch was causing a failure on clang-ppc64le-rhel bot https://lab.llvm.org/buildbot/#/builders/57/builds/8932 with a unmatching type issue - line 30 EXPECT_EQ(list.Size(), 0); in compiler-rt/lib/tsan/tests/unit/tsan_ilist_test.cpp.
To unblock our bot, I have committed a fix ac2ffdef9cc8d152801ca87d81736fb1dec9cb88. The latest build passed at https://lab.llvm.org/buildbot/#/builders/57/builds/8971 If you want a different fix, feel free to commit a follow-up fix patch. Thanks.

Hi @dvyukov, this patch was causing a failure on clang-ppc64le-rhel bot https://lab.llvm.org/buildbot/#/builders/57/builds/8932 with a unmatching type issue - line 30 EXPECT_EQ(list.Size(), 0); in compiler-rt/lib/tsan/tests/unit/tsan_ilist_test.cpp.
To unblock our bot, I have committed a fix ac2ffdef9cc8d152801ca87d81736fb1dec9cb88. The latest build passed at https://lab.llvm.org/buildbot/#/builders/57/builds/8971 If you want a different fix, feel free to commit a follow-up fix patch. Thanks.

Thanks, Victor! That's a fine fix.