Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ready] Replacing Competition with Cooperation to Achieve Scalable Lock-Free … #136

Open
wants to merge 26 commits into
base: integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4384d73
Replacing Competition with Cooperation to Achieve Scalable Lock-Free …
NikitaKomp Jan 31, 2019
6553bd1
Update intrusive_push_pop.cpp
NikitaKomp Feb 5, 2019
e32fa3f
Update intrusive_push_pop.cpp
NikitaKomp Feb 5, 2019
10f07cc
Update intrusive_push_pop.cpp
NikitaKomp Feb 5, 2019
d6fc46e
Update intrusive_queue_type.h
NikitaKomp Feb 5, 2019
4beaf8e
Update pop.cpp
NikitaKomp Feb 5, 2019
4f77194
Update print_stat.h
NikitaKomp Feb 5, 2019
f4f3b89
Update push.cpp
NikitaKomp Feb 5, 2019
0d6313a
Update spsc_buffer.cpp
NikitaKomp Feb 5, 2019
efeaccf
Update random.cpp
NikitaKomp Feb 5, 2019
dfa9b96
Update queue_type.h
NikitaKomp Feb 5, 2019
e8c093b
Update push_pop.cpp
NikitaKomp Feb 5, 2019
d2a9bda
Update speculative_pairing_queue.h
NikitaKomp Feb 6, 2019
3569f3c
Update push.cpp
NikitaKomp Feb 6, 2019
74c4ffd
Update test_intrusive_speculative_pairing_queue.h
NikitaKomp Feb 6, 2019
9cded93
Update speculative_pairing_queue.h
NikitaKomp Feb 6, 2019
2308585
Update sp_queue_base.h
NikitaKomp Feb 6, 2019
55b6b48
Update speculative_pairing_queue.h
NikitaKomp Feb 6, 2019
c7be8fb
Update intrusive_speculative_pairing_queue_dhp.cpp
NikitaKomp Feb 6, 2019
d930350
Update intrusive_speculative_pairing_queue_hp.cpp
NikitaKomp Feb 6, 2019
818afe4
Update speculative_pairing_queue_dhp.cpp
NikitaKomp Feb 6, 2019
b2f3931
Update speculative_pairing_queue_hp.cpp
NikitaKomp Feb 6, 2019
1fc589e
Update test_intrusive_speculative_pairing_queue.h
NikitaKomp Feb 6, 2019
0ff5393
Update test_intrusive_speculative_pairing_queue.h
NikitaKomp Feb 6, 2019
f2075dc
Update spsc_buffer.cpp
NikitaKomp Feb 6, 2019
1d3edec
Update spsc_buffer.cpp
NikitaKomp Feb 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
403 changes: 403 additions & 0 deletions cds/container/speculative_pairing_queue.h

Large diffs are not rendered by default.

179 changes: 179 additions & 0 deletions cds/intrusive/details/sp_queue_base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
// Copyright (c) 2006-2018 Maxim Khizhinsky
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)

#ifndef CDSLIB_INTRUSIVE_DETAILS_SP_QUEUE_BASE_H
#define CDSLIB_INTRUSIVE_DETAILS_SP_QUEUE_BASE_H

#include <cds/intrusive/details/base.h>
#include <cds/gc/default_gc.h>
#include <cds/algo/atomic.h>
#include <cds/intrusive/details/single_link_struct.h>

namespace cds { namespace intrusive {

/// Definitions common for single-linked data structures
/** @ingroup cds_intrusive_helper
*/
namespace sp_queue {

/// Container's node
/**
Template parameters:
- GC - garbage collector used
- Tag - a tag used to distinguish between different implementation
*/

template <class GC, typename Tag = opt::none >
struct node {
typedef GC gc ; ///< Garbage collector
typedef Tag tag ; ///< tag

typedef typename gc::template atomic_ref<node> atomic_node_ptr; ///< atomic pointer
typedef typename gc::template atomic_type<int> atomic_int;

/// Rebind node for other template parameters
template <class GC2, typename Tag2 = tag>
struct rebind {
typedef node<GC2, Tag2> other ; ///< Rebinding result
};

atomic_node_ptr m_pNext ; ///< pointer to the next node in the container

atomic_int m_nVer;
bool m_removed = false;

node() noexcept
{
m_pNext.store( nullptr, atomics::memory_order_release );
m_nVer.store(0, atomics::memory_order_release);
}

};


//@cond
struct default_hook {
typedef cds::gc::default_gc gc;
typedef opt::none tag;
};
//@endcond

//@cond
template < typename HookType, typename... Options>
struct hook
{
typedef typename opt::make_options< default_hook, Options...>::type options;
typedef typename options::gc gc;
typedef typename options::tag tag;
typedef node<gc, tag> node_type;
typedef HookType hook_type;
};
//@endcond

/// Base hook
/**
\p Options are:
- opt::gc - garbage collector used.
- opt::tag - tag
*/
template < typename... Options >
struct base_hook: public hook< opt::base_hook_tag, Options... >
{};

/// Member hook
/**
\p MemberOffset defines offset in bytes of \ref node member into your structure.
Use \p offsetof macro to define \p MemberOffset

\p Options are:
- opt::gc - garbage collector used.
- opt::tag - tag
*/
template < size_t MemberOffset, typename... Options >
struct member_hook: public hook< opt::member_hook_tag, Options... >
{
//@cond
static const size_t c_nMemberOffset = MemberOffset;
//@endcond
};

/// Traits hook
/**
\p NodeTraits defines type traits for node.
See \ref node_traits for \p NodeTraits interface description

\p Options are:
- opt::gc - garbage collector used.
- opt::tag - tag
*/
template <typename NodeTraits, typename... Options >
struct traits_hook: public hook< opt::traits_hook_tag, Options... >
{
//@cond
typedef NodeTraits node_traits;
//@endcond
};

/// Check link
template <typename Node>
struct link_checker {
//@cond
typedef Node node_type;
//@endcond

/// Checks if the link field of node \p pNode is \p nullptr
/**
An asserting is generated if \p pNode link field is not \p nullptr
*/
static void is_empty( const node_type * pNode )
{
assert( pNode->m_pNext.load( atomics::memory_order_relaxed ) == nullptr );
CDS_UNUSED( pNode );
}
};

//@cond
template <class GC, typename Node, opt::link_check_type LinkType >
struct link_checker_selector;

template <typename GC, typename Node>
struct link_checker_selector< GC, Node, opt::never_check_link >
{
typedef intrusive::opt::v::empty_link_checker<Node> type;
};

template <typename GC, typename Node>
struct link_checker_selector< GC, Node, opt::debug_check_link >
{
# ifdef _DEBUG
typedef link_checker<Node> type;
# else
typedef intrusive::opt::v::empty_link_checker<Node> type;
# endif
};

template <typename GC, typename Node>
struct link_checker_selector< GC, Node, opt::always_check_link >
{
typedef link_checker<Node> type;
};
//@endcond

/// Metafunction for selecting appropriate link checking policy
template < typename Node, opt::link_check_type LinkType >
struct get_link_checker
{
//@cond
typedef typename link_checker_selector< typename Node::gc, Node, LinkType>::type type;
//@endcond
};

} // namespace single_link

}} // namespace cds::intrusive



#endif // #ifndef CDSLIB_INTRUSIVE_DETAILS_SINGLE_LINK_STRUCT_H
Loading