projects
/
libcds.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fixed Clang build
[libcds.git]
/
cds
/
intrusive
/
impl
/
iterable_list.h
diff --git
a/cds/intrusive/impl/iterable_list.h
b/cds/intrusive/impl/iterable_list.h
index 169496dfb853a3b8bc7620c4254f681974150b84..fe85cc98ff13a56f2021ba79143039681f7eda28 100644
(file)
--- a/
cds/intrusive/impl/iterable_list.h
+++ b/
cds/intrusive/impl/iterable_list.h
@@
-5,7
+5,7
@@
Source code repo: http://github.com/khizmax/libcds/
Download: http://sourceforge.net/projects/libcds/files/
Source code repo: http://github.com/khizmax/libcds/
Download: http://sourceforge.net/projects/libcds/files/
-
+
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
@@
-160,6
+160,7
@@
namespace cds { namespace intrusive {
//@endcond
protected:
//@endcond
protected:
+ //@cond
typedef atomics::atomic< node_type* > atomic_node_ptr; ///< Atomic node pointer
typedef atomic_node_ptr auxiliary_head; ///< Auxiliary head type (for split-list support)
typedef atomics::atomic< node_type* > atomic_node_ptr; ///< Atomic node pointer
typedef atomic_node_ptr auxiliary_head; ///< Auxiliary head type (for split-list support)
@@
-167,7
+168,6
@@
namespace cds { namespace intrusive {
item_counter m_ItemCounter; ///< Item counter
mutable stat m_Stat; ///< Internal statistics
item_counter m_ItemCounter; ///< Item counter
mutable stat m_Stat; ///< Internal statistics
- //@cond
typedef cds::details::Allocator< node_type, node_allocator > cxx_node_allocator;
/// Position pointer for item search
typedef cds::details::Allocator< node_type, node_allocator > cxx_node_allocator;
/// Position pointer for item search
@@
-190,35
+190,32
@@
namespace cds { namespace intrusive {
protected:
node_type* m_pNode;
protected:
node_type* m_pNode;
- value_type* m_pVal;
- typename gc::Guard m_Guard; // for m_pVal
+ typename gc::Guard m_Guard; // data guard
void next()
{
while ( m_pNode ) {
void next()
{
while ( m_pNode ) {
- m_pNode = m_pNode->next.load( memory_model::memory_order_relaxed );
- if ( !m_pNode )
+ m_pNode = m_pNode->next.load( memory_model::memory_order_acquire );
+ if ( !m_pNode ) {
+ m_Guard.clear();
break;
break;
- m_pVal = m_Guard.protect( m_pNode->data );
- if ( m_
pVal
)
+ }
+ if ( m_
Guard.protect( m_pNode->data )
)
break;
}
}
explicit iterator_type( atomic_node_ptr const& pNode )
break;
}
}
explicit iterator_type( atomic_node_ptr const& pNode )
- : m_pNode( pNode.load( memory_model::memory_order_relaxed ))
- , m_pVal( nullptr )
+ : m_pNode( pNode.load( memory_model::memory_order_acquire ))
{
if ( m_pNode ) {
{
if ( m_pNode ) {
- m_pVal = m_Guard.protect( m_pNode->data );
- if ( !m_pVal )
+ if ( !m_Guard.protect( m_pNode->data ))
next();
}
}
iterator_type( node_type* pNode, value_type* pVal )
: m_pNode( pNode )
next();
}
}
iterator_type( node_type* pNode, value_type* pVal )
: m_pNode( pNode )
- , m_pVal( pVal )
{
if ( m_pNode ) {
assert( pVal != nullptr );
{
if ( m_pNode ) {
assert( pVal != nullptr );
@@
-232,25
+229,23
@@
namespace cds { namespace intrusive {
iterator_type()
: m_pNode( nullptr )
iterator_type()
: m_pNode( nullptr )
- , m_pVal( nullptr )
{}
iterator_type( iterator_type const& src )
: m_pNode( src.m_pNode )
{}
iterator_type( iterator_type const& src )
: m_pNode( src.m_pNode )
- , m_pVal( src.m_pVal )
{
{
- m_Guard.
assign( m_pVal
);
+ m_Guard.
copy( src.m_Guard
);
}
value_ptr operator ->() const
{
}
value_ptr operator ->() const
{
- return m_
pVal
;
+ return m_
Guard.template get<value_type>()
;
}
value_ref operator *() const
{
}
value_ref operator *() const
{
- assert( m_
pVal
!= nullptr );
- return *m_
pVal
;
+ assert( m_
Guard.get_native()
!= nullptr );
+ return *m_
Guard.template get<value_type>()
;
}
/// Pre-increment
}
/// Pre-increment
@@
-263,8
+258,7
@@
namespace cds { namespace intrusive {
iterator_type& operator = (iterator_type const& src)
{
m_pNode = src.m_pNode;
iterator_type& operator = (iterator_type const& src)
{
m_pNode = src.m_pNode;
- m_pVal = src.m_pVal;
- m_Guard.assign( m_pVal );
+ m_Guard.copy( src.m_Guard );
return *this;
}
return *this;
}
@@
-276,7
+270,7
@@
namespace cds { namespace intrusive {
template <bool C>
bool operator !=(iterator_type<C> const& i ) const
{
template <bool C>
bool operator !=(iterator_type<C> const& i ) const
{
- return
m_pNode != i.m_pNode
;
+ return
!( *this == i )
;
}
};
//@endcond
}
};
//@endcond
@@
-591,7
+585,7
@@
namespace cds { namespace intrusive {
ord_list theList;
// ...
{
ord_list theList;
// ...
{
- ord_list::guarded_ptr gp(theList.extract( 5 ));
+ ord_list::guarded_ptr gp(
theList.extract( 5 ));
if ( gp ) {
// Deal with gp
// ...
if ( gp ) {
// Deal with gp
// ...
@@
-603,9
+597,7
@@
namespace cds { namespace intrusive {
template <typename Q>
guarded_ptr extract( Q const& key )
{
template <typename Q>
guarded_ptr extract( Q const& key )
{
- guarded_ptr gp;
- extract_at( m_pHead, gp.guard(), key, key_comparator());
- return gp;
+ return extract_at( m_pHead, key, key_comparator());
}
/// Extracts the item using compare functor \p pred
}
/// Extracts the item using compare functor \p pred
@@
-621,9
+613,7
@@
namespace cds { namespace intrusive {
guarded_ptr extract_with( Q const& key, Less pred )
{
CDS_UNUSED( pred );
guarded_ptr extract_with( Q const& key, Less pred )
{
CDS_UNUSED( pred );
- guarded_ptr gp;
- extract_at( m_pHead, gp.guard(), key, cds::opt::details::make_comparator_from_less<Less>());
- return gp;
+ return extract_at( m_pHead, key, cds::opt::details::make_comparator_from_less<Less>());
}
/// Finds \p key in the list
}
/// Finds \p key in the list
@@
-662,17
+652,10
@@
namespace cds { namespace intrusive {
If \p key is not found the function returns \p end().
*/
template <typename Q>
If \p key is not found the function returns \p end().
*/
template <typename Q>
- iterator find( Q& key ) const
- {
- return find_iterator_at( m_pHead, key, key_comparator());
- }
- //@cond
- template <typename Q>
iterator find( Q const& key ) const
{
iterator find( Q const& key ) const
{
- return find_iterator_at( m_pHead, key, key_comparator()
);
+ return find_iterator_at( m_pHead, key, key_comparator());
}
}
- //@endcond
/// Finds the \p key using \p pred predicate for searching
/**
/// Finds the \p key using \p pred predicate for searching
/**
@@
-705,19
+688,11
@@
namespace cds { namespace intrusive {
If \p key is not found the function returns \p end().
*/
template <typename Q, typename Less>
If \p key is not found the function returns \p end().
*/
template <typename Q, typename Less>
- iterator find_with( Q& key, Less pred ) const
- {
- CDS_UNUSED( pred );
- return find_iterator_at( m_pHead, key, cds::opt::details::make_comparator_from_less<Less>());
- }
- //@cond
- template <typename Q, typename Less>
iterator find_with( Q const& key, Less pred ) const
{
CDS_UNUSED( pred );
return find_iterator_at( m_pHead, key, cds::opt::details::make_comparator_from_less<Less>());
}
iterator find_with( Q const& key, Less pred ) const
{
CDS_UNUSED( pred );
return find_iterator_at( m_pHead, key, cds::opt::details::make_comparator_from_less<Less>());
}
- //@endcond
/// Checks whether the list contains \p key
/**
/// Checks whether the list contains \p key
/**
@@
-775,9
+750,7
@@
namespace cds { namespace intrusive {
template <typename Q>
guarded_ptr get( Q const& key ) const
{
template <typename Q>
guarded_ptr get( Q const& key ) const
{
- guarded_ptr gp;
- get_at( m_pHead, gp.guard(), key, key_comparator());
- return gp;
+ return get_at( m_pHead, key, key_comparator());
}
/// Finds the \p key and return the item found
}
/// Finds the \p key and return the item found
@@
-793,9
+766,7
@@
namespace cds { namespace intrusive {
guarded_ptr get_with( Q const& key, Less pred ) const
{
CDS_UNUSED( pred );
guarded_ptr get_with( Q const& key, Less pred ) const
{
CDS_UNUSED( pred );
- guarded_ptr gp;
- get_at( m_pHead, gp.guard(), key, cds::opt::details::make_comparator_from_less<Less>());
- return gp;
+ return get_at( m_pHead, key, cds::opt::details::make_comparator_from_less<Less>());
}
/// Clears the list (thread safe, not atomic)
}
/// Clears the list (thread safe, not atomic)
@@
-1010,16
+981,16
@@
namespace cds { namespace intrusive {
}
template <typename Q, typename Compare>
}
template <typename Q, typename Compare>
-
bool extract_at( atomic_node_ptr& refHead, typename guarded_ptr::native_guard& dest
, Q const& val, Compare cmp )
+
guarded_ptr extract_at( atomic_node_ptr& refHead
, Q const& val, Compare cmp )
{
position pos;
back_off bkoff;
while ( search( refHead, val, pos, cmp )) {
if ( unlink_node( pos )) {
{
position pos;
back_off bkoff;
while ( search( refHead, val, pos, cmp )) {
if ( unlink_node( pos )) {
- dest.set( pos.pFound );
--m_ItemCounter;
m_Stat.onEraseSuccess();
--m_ItemCounter;
m_Stat.onEraseSuccess();
- return true;
+ assert( pos.pFound != nullptr );
+ return guarded_ptr( std::move( pos.guard ));
}
else
bkoff();
}
else
bkoff();
@@
-1028,7
+999,7
@@
namespace cds { namespace intrusive {
}
m_Stat.onEraseFailed();
}
m_Stat.onEraseFailed();
- return
false
;
+ return
guarded_ptr()
;
}
template <typename Q, typename Compare>
}
template <typename Q, typename Compare>
@@
-1075,17
+1046,16
@@
namespace cds { namespace intrusive {
}
template <typename Q, typename Compare>
}
template <typename Q, typename Compare>
-
bool get_at( atomic_node_ptr const& refHead, typename guarded_ptr::native_guard& guar
d, Q const& val, Compare cmp ) const
+
guarded_ptr get_at( atomic_node_ptr const& refHea
d, Q const& val, Compare cmp ) const
{
position pos;
if ( search( refHead, val, pos, cmp )) {
{
position pos;
if ( search( refHead, val, pos, cmp )) {
- guard.set( pos.pFound );
m_Stat.onFindSuccess();
m_Stat.onFindSuccess();
- return
true
;
+ return
guarded_ptr( std::move( pos.guard ))
;
}
m_Stat.onFindFailed();
}
m_Stat.onFindFailed();
- return
false
;
+ return
guarded_ptr()
;
}
//@endcond
}
//@endcond