Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
1048f236
Commit
1048f236
authored
4 years ago
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util/IntrusiveList: add hook class SafeLinkIntrusiveListHook
Similar to boost::intrusive::safe_link.
parent
8fe8f090
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
13 deletions
+20
-13
IntrusiveList.hxx
src/util/IntrusiveList.hxx
+20
-13
No files found.
src/util/IntrusiveList.hxx
View file @
1048f236
...
@@ -65,21 +65,15 @@ private:
...
@@ -65,21 +65,15 @@ private:
};
};
/**
/**
* A variant of #IntrusiveListHook which auto-unlinks itself from the
* A variant of #IntrusiveListHook which keeps track of whether it is
* list upon destruction. As a side effect, it has an is_linked()
* currently in a list.
* method.
*/
*/
class
AutoUnl
inkIntrusiveListHook
:
public
IntrusiveListHook
{
class
SafeL
inkIntrusiveListHook
:
public
IntrusiveListHook
{
public
:
public
:
AutoUnl
inkIntrusiveListHook
()
noexcept
{
SafeL
inkIntrusiveListHook
()
noexcept
{
siblings
.
next
=
nullptr
;
siblings
.
next
=
nullptr
;
}
}
~
AutoUnlinkIntrusiveListHook
()
noexcept
{
if
(
is_linked
())
unlink
();
}
void
unlink
()
noexcept
{
void
unlink
()
noexcept
{
IntrusiveListHook
::
unlink
();
IntrusiveListHook
::
unlink
();
siblings
.
next
=
nullptr
;
siblings
.
next
=
nullptr
;
...
@@ -90,6 +84,19 @@ public:
...
@@ -90,6 +84,19 @@ public:
}
}
};
};
/**
* A variant of #IntrusiveListHook which auto-unlinks itself from the
* list upon destruction. As a side effect, it has an is_linked()
* method.
*/
class
AutoUnlinkIntrusiveListHook
:
public
SafeLinkIntrusiveListHook
{
public
:
~
AutoUnlinkIntrusiveListHook
()
noexcept
{
if
(
is_linked
())
unlink
();
}
};
template
<
typename
T
>
template
<
typename
T
>
class
IntrusiveList
{
class
IntrusiveList
{
IntrusiveListNode
head
{
&
head
,
&
head
};
IntrusiveListNode
head
{
&
head
,
&
head
};
...
@@ -140,7 +147,7 @@ public:
...
@@ -140,7 +147,7 @@ public:
}
}
~
IntrusiveList
()
noexcept
{
~
IntrusiveList
()
noexcept
{
if
constexpr
(
std
::
is_base_of
<
AutoUnl
inkIntrusiveListHook
,
T
>::
value
)
if
constexpr
(
std
::
is_base_of
<
SafeL
inkIntrusiveListHook
,
T
>::
value
)
clear
();
clear
();
}
}
...
@@ -151,8 +158,8 @@ public:
...
@@ -151,8 +158,8 @@ public:
}
}
void
clear
()
noexcept
{
void
clear
()
noexcept
{
if
constexpr
(
std
::
is_base_of
<
AutoUnl
inkIntrusiveListHook
,
T
>::
value
)
{
if
constexpr
(
std
::
is_base_of
<
SafeL
inkIntrusiveListHook
,
T
>::
value
)
{
/* for
AutoUnl
inkIntrusiveListHook, we need to
/* for
SafeL
inkIntrusiveListHook, we need to
remove each item manually, or else its
remove each item manually, or else its
is_linked() method will not work */
is_linked() method will not work */
while
(
!
empty
())
while
(
!
empty
())
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment