Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
Kea
Commits
050c451f
Commit
050c451f
authored
Mar 11, 2011
by
zhanglikun
Browse files
[trac643] Add clear() function to lru list, which is used to clear all the elements of list.
parent
acbd9518
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/lib/cache/message_cache.cc
View file @
050c451f
...
...
@@ -37,6 +37,11 @@ MessageCache::MessageCache(boost::shared_ptr<RRsetCache> rrset_cache,
{
}
MessageCache
::~
MessageCache
()
{
// Destroy all the message entries in the cache.
message_lru_
.
clear
();
}
bool
MessageCache
::
lookup
(
const
isc
::
dns
::
Name
&
qname
,
const
isc
::
dns
::
RRType
&
qtype
,
...
...
src/lib/cache/message_cache.h
View file @
050c451f
...
...
@@ -42,7 +42,7 @@ public:
uint32_t
cache_size
,
uint16_t
message_class
);
/// \brief Destructor function
virtual
~
MessageCache
()
{}
virtual
~
MessageCache
()
;
/// \brief Look up message in cache.
/// \param message generated response message if the message entry
...
...
src/lib/cache/rrset_cache.h
View file @
050c451f
...
...
@@ -40,12 +40,14 @@ private:
RRsetCache
(
const
RRsetCache
&
);
RRsetCache
&
operator
=
(
const
RRsetCache
&
);
public:
/// \brief Constructor
/// \brief Constructor
and Destructor
///
/// \param cache_size the size of rrset cache.
/// \param rrset_class the class of rrset cache.
RRsetCache
(
uint32_t
cache_size
,
uint16_t
rrset_class
);
virtual
~
RRsetCache
()
{}
virtual
~
RRsetCache
()
{
rrset_lru_
.
clear
();
// Clear the rrset entries in the list.
}
//@}
/// \brief Look up rrset in cache.
...
...
src/lib/nsas/lru_list.h
View file @
050c451f
...
...
@@ -109,6 +109,13 @@ public:
/// \param element Reference to the element to touch.
virtual
void
touch
(
boost
::
shared_ptr
<
T
>&
element
);
/// \brief Drop All the Elements in the List .
///
/// All the elements will be dropped from the list container, and their
/// drop handler(if there is one) will be called, left the size of list
/// to 0.
virtual
void
clear
();
/// \brief Return Size of the List
///
/// An independent count is kept of the list size, as list.size() may take
...
...
@@ -228,6 +235,25 @@ void LruList<T>::touch(boost::shared_ptr<T>& element) {
}
}
// Clear the list- left the size of list to 0
template
<
typename
T
>
void
LruList
<
T
>::
clear
()
{
// Protect list against concurrent access
isc
::
locks
::
scoped_lock
<
isc
::
locks
::
mutex
>
lock
(
mutex_
);
// ... and update the count while we have the mutex.
count_
=
0
;
typename
std
::
list
<
boost
::
shared_ptr
<
T
>
>::
iterator
iter
;
if
(
dropped_
)
{
for
(
iter
=
lru_
.
begin
();
iter
!=
lru_
.
end
();
++
iter
)
{
// Call the drop handler.
(
*
dropped_
)(
iter
->
get
());
}
}
lru_
.
clear
();
}
}
// namespace nsas
}
// namespace isc
...
...
src/lib/nsas/tests/lru_list_unittest.cc
View file @
050c451f
...
...
@@ -251,6 +251,35 @@ TEST_F(LruListTest, Dropped) {
EXPECT_EQ
(
0
,
(
entry3_
->
getClass
().
getCode
()
&
0x8000
));
}
// Clear functor tests: tests whether all the elements in
// the list are dropped properly and the size of list is
// set to 0.
TEST_F
(
LruListTest
,
Clear
)
{
// Create an object with an expiration handler.
LruList
<
TestEntry
>
lru
(
3
,
new
Dropped
());
// Fill the list
lru
.
add
(
entry1_
);
lru
.
add
(
entry2_
);
lru
.
add
(
entry3_
);
EXPECT_EQ
(
RRClass
::
IN
(),
entry1_
->
getClass
());
EXPECT_EQ
(
RRClass
::
CH
(),
entry2_
->
getClass
());
EXPECT_EQ
(
RRClass
::
HS
(),
entry3_
->
getClass
());
EXPECT_EQ
(
0
,
(
entry1_
->
getClass
().
getCode
()
&
0x8000
));
EXPECT_EQ
(
0
,
(
entry2_
->
getClass
().
getCode
()
&
0x8000
));
EXPECT_EQ
(
0
,
(
entry3_
->
getClass
().
getCode
()
&
0x8000
));
// Clear the lru list, and check the drop handler run
lru
.
clear
();
EXPECT_NE
(
0
,
(
entry1_
->
getClass
().
getCode
()
&
0x8000
));
EXPECT_NE
(
0
,
(
entry2_
->
getClass
().
getCode
()
&
0x8000
));
EXPECT_NE
(
0
,
(
entry3_
->
getClass
().
getCode
()
&
0x8000
));
EXPECT_EQ
(
0
,
lru
.
size
());
}
// Miscellaneous tests - pathological conditions
TEST_F
(
LruListTest
,
Miscellaneous
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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