Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
07b8d00
Valois list (unfinished)
MagisterDemens Dec 27, 2017
1b0be18
Cleaned
MagisterDemens Jan 4, 2018
2a3e725
Implemented insert, erase, empty, iterator.
MagisterDemens Jan 5, 2018
a084900
add small test
w3prog Jan 6, 2018
e56579c
fix small bug
w3prog Jan 6, 2018
0edb606
error fixes
MagisterDemens Jan 6, 2018
1b9695a
Have implemented contains(), iterator begin()
MagisterDemens Jan 6, 2018
9fc144a
Add stat in base file
w3prog Jan 7, 2018
86aabad
add methods with comments
w3prog Jan 8, 2018
84f361f
add some unit test
w3prog Jan 8, 2018
ff0e387
Fixed compare
MagisterDemens Jan 8, 2018
6e6de8e
Fix insert, find
MagisterDemens Jan 8, 2018
c09df90
Almoust finished. Small test working
MagisterDemens Jan 8, 2018
5c1e8da
variables type fix
MagisterDemens Jan 8, 2018
745eb12
add new debug functions
w3prog Jan 9, 2018
4b50360
fix with test
w3prog Jan 9, 2018
f72fa65
update test
w3prog Jan 9, 2018
a4c5ca7
update test
w3prog Jan 9, 2018
c212802
add random test, fix bugs, comment update iterator
w3prog Jan 9, 2018
57e205a
add revert unit test
w3prog Jan 9, 2018
829ef8f
update insert
w3prog Jan 10, 2018
ae18493
fix verstion with append
w3prog Jan 10, 2018
d3de087
add debug functions
w3prog Jan 10, 2018
fe3313b
test complite correctly but not free
w3prog Jan 10, 2018
253489f
update iterator work correctly
w3prog Jan 10, 2018
c5e5f82
format code
w3prog Jan 10, 2018
e1f0109
update erase
w3prog Jan 10, 2018
a29ec78
update test
w3prog Jan 10, 2018
08a22ee
update licency
w3prog Jan 10, 2018
4aae499
clear code and fix destroy
w3prog Jan 10, 2018
67655b9
Guarded added
MagisterDemens Jan 10, 2018
d67d86d
format code
w3prog Jan 10, 2018
0718da4
local Guard
MagisterDemens Jan 12, 2018
ce2b340
local Guard
MagisterDemens Jan 13, 2018
8c1f6d4
add base for stress tests
w3prog Jan 14, 2018
8bf69b8
update test
w3prog Jan 15, 2018
59f93d1
stress test pass with memory leap
w3prog Jan 17, 2018
cc152a6
change iterator to local iterator scheme
w3prog Jan 18, 2018
538e93c
moving to atomik ptr need help with CAS
w3prog Jan 18, 2018
8afc1ae
merge
w3prog Jan 18, 2018
c0338a3
moving to atomik ptr need help with CAS
w3prog Jan 18, 2018
0254032
fix with marked pointers
w3prog Jan 18, 2018
4793090
fix with memory leaks
w3prog Jan 18, 2018
effc834
optimize methods
w3prog Jan 18, 2018
fe4f90b
fix with CAS result in search insert
w3prog Jan 18, 2018
3d62447
fix a bug
w3prog Jan 18, 2018
2214b93
fix for request
w3prog Jan 27, 2018
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
216 changes: 216 additions & 0 deletions cds/intrusive/details/valois_list_base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
/*
This file is a part of libcds - Concurrent Data Structures library

(C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017

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:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <type_traits>
#include <cds/intrusive/details/base.h>
#include <cds/opt/compare.h>
#include <cds/algo/atomic.h>
#include <cds/details/marked_ptr.h>
#include <cds/urcu/options.h>

#ifndef CDSLIB_INTRUSIVE_DETAILS_VALOIS_LIST_BASE_H
#define CDSLIB_INTRUSIVE_DETAILS_VALOIS_LIST_BASE_H

namespace cds { namespace intrusive {

namespace valois_list{

template <typename T>
struct node
{
typedef T value_type; ///< Value type
typedef cds::details::marked_ptr<T, 1> marked_data_ptr; ///< marked pointer to the value

atomics::atomic< node* > next; ///< pointer to next node in the list
atomics::atomic< marked_data_ptr > data; ///< pointer to user data, \p nullptr if the node is free

node()
{
next.store( nullptr, atomics::memory_order_relaxed );
data.store( marked_data_ptr( NULL ), atomics::memory_order_release );
}

node( value_type * pVal )
{
next.store( nullptr, atomics::memory_order_relaxed );
data.store( marked_data_ptr( pVal ), atomics::memory_order_release );
}

};


template <typename EventCounter = cds::atomicity::event_counter>
struct stat {
typedef EventCounter event_counter; ///< Event counter type

event_counter m_nInsertSuccess; ///< Number of success \p insert() operations
event_counter m_nInsertFailed; ///< Number of failed \p insert() operations
event_counter m_nInsertRetry; ///< Number of attempts to insert new item
event_counter m_nUpdateNew; ///< Number of new item inserted for \p update()
event_counter m_nUpdateExisting; ///< Number of existing item updates
event_counter m_nUpdateFailed; ///< Number of failed \p update() call
event_counter m_nUpdateRetry; ///< Number of attempts to \p update() the item
event_counter m_nUpdateMarked; ///< Number of attempts to \p update() logically deleted (marked) items
event_counter m_nEraseSuccess; ///< Number of successful \p erase(), \p unlink(), \p extract() operations
event_counter m_nEraseFailed; ///< Number of failed \p erase(), \p unlink(), \p extract() operations
event_counter m_nEraseRetry; ///< Number of attempts to \p erase() an item
event_counter m_nFindSuccess; ///< Number of successful \p find() and \p get() operations
event_counter m_nFindFailed; ///< Number of failed \p find() and \p get() operations

event_counter m_nHelpingSuccess; ///< Number of successful help attempts to remove marked item during searching
event_counter m_nHelpingFailed; ///< Number if failed help attempts to remove marked item during searching

//@cond
void onInsertSuccess() { ++m_nInsertSuccess; }
void onInsertFailed() { ++m_nInsertFailed; }
void onInsertRetry() { ++m_nInsertRetry; }
void onUpdateNew() { ++m_nUpdateNew; }
void onUpdateExisting() { ++m_nUpdateExisting; }
void onUpdateFailed() { ++m_nUpdateFailed; }
void onUpdateRetry() { ++m_nUpdateRetry; }
void onUpdateMarked() { ++m_nUpdateMarked; }
void onEraseSuccess() { ++m_nEraseSuccess; }
void onEraseFailed() { ++m_nEraseFailed; }
void onEraseRetry() { ++m_nEraseRetry; }
void onFindSuccess() { ++m_nFindSuccess; }
void onFindFailed() { ++m_nFindFailed; }

void onHelpingSuccess() { ++m_nHelpingSuccess; }
void onHelpingFailed() { ++m_nHelpingFailed; }
//@endcond
};

/// \p MichaelList empty internal statistics
struct empty_stat {
//@cond
void onInsertSuccess() const {}
void onInsertFailed() const {}
void onInsertRetry() const {}
void onUpdateNew() const {}
void onUpdateExisting() const {}
void onUpdateFailed() const {}
void onUpdateRetry() const {}
void onUpdateMarked() const {}
void onEraseSuccess() const {}
void onEraseFailed() const {}
void onEraseRetry() const {}
void onFindSuccess() const {}
void onFindFailed() const {}

void onHelpingSuccess() const {}
void onHelpingFailed() const {}
//@endcond
};

//@cond
template <typename Stat = valois_list::stat<>>
struct wrapped_stat {
typedef Stat stat_type;

wrapped_stat( stat_type& st )
: m_stat( st )
{}

void onInsertSuccess() { m_stat.onInsertSuccess(); }
void onInsertFailed() { m_stat.onInsertFailed(); }
void onInsertRetry() { m_stat.onInsertRetry(); }
void onUpdateNew() { m_stat.onUpdateNew(); }
void onUpdateExisting() { m_stat.onUpdateExisting(); }
void onUpdateFailed() { m_stat.onUpdateFailed(); }
void onUpdateRetry() { m_stat.onUpdateRetry(); }
void onUpdateMarked() { m_stat.onUpdateMarked(); }
void onEraseSuccess() { m_stat.onEraseSuccess(); }
void onEraseFailed() { m_stat.onEraseFailed(); }
void onEraseRetry() { m_stat.onEraseRetry(); }
void onFindSuccess() { m_stat.onFindSuccess(); }
void onFindFailed() { m_stat.onFindFailed(); }

void onHelpingSuccess() { m_stat.onHelpingSuccess(); }
void onHelpingFailed() { m_stat.onHelpingFailed(); }

stat_type& m_stat;
};

struct traits
{
/// Key comparison functor
/**
No default functor is provided. If the option is not specified, the \p less is used.
*/
typedef opt::none compare;

/// Specifies binary predicate used for key compare.
/**
Default is \p std::less<T>
*/
typedef opt::none less;

/// Node allocator
typedef CDS_DEFAULT_ALLOCATOR node_allocator;

/// Back-off strategy
typedef cds::backoff::Default back_off;

/// Disposer for removing items
typedef opt::v::empty_disposer disposer;

/// Internal statistics
/**
It's disabled
*/
typedef empty_stat stat;

/// Item counting feature; by default, disabled. Use \p cds::atomicity::item_counter or \p atomicity::cache_friendly_item_counter to enable item counting
typedef atomicity::empty_item_counter item_counter;

/// C++ memory ordering model
/**
Can be \p opt::v::relaxed_ordering (relaxed memory model, the default)
or \p opt::v::sequential_consistent (sequentially consisnent memory model).
*/
typedef opt::v::relaxed_ordering memory_model;
};

template <typename... Options>
struct make_traits {
# ifdef CDS_DOXYGEN_INVOKED
typedef implementation_defined type ; ///< Metafunction result
# else
typedef typename cds::opt::make_options<
typename cds::opt::find_type_traits< traits, Options... >::type
,Options...
>::type type;
# endif
};

}
}}

#endif // #ifndef CDSLIB_INTRUSIVE_DETAILS_VALOIS_LIST_BASE_H
Loading