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]Williams lock-free queue (impl by @FatherOctber). (3303: Ваулина, Крень, Левшин, Переверзев) #126

Open
wants to merge 3 commits into
base: integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
538 changes: 538 additions & 0 deletions cds/container/williams_queue.h

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion projects/Win/vc141/cds.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,7 @@
<ClInclude Include="..\..\..\cds\container\striped_set\std_list.h" />
<ClInclude Include="..\..\..\cds\container\striped_set\std_set.h" />
<ClInclude Include="..\..\..\cds\container\striped_set\std_vector.h" />
<ClInclude Include="..\..\..\cds\container\williams_queue.h" />
<ClInclude Include="..\..\..\cds\container\weak_ringbuffer.h" />
<ClInclude Include="..\..\..\cds\details\binary_functor_wrapper.h" />
<ClInclude Include="..\..\..\cds\details\bit_reverse_counter.h" />
Expand Down Expand Up @@ -1374,4 +1375,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
5 changes: 4 additions & 1 deletion projects/Win/vc141/cds.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1258,5 +1258,8 @@
<ClInclude Include="..\..\..\cds\details\tls_holder.h">
<Filter>Header Files\cds\details</Filter>
</ClInclude>
<ClInclude Include="..\..\..\cds\container\williams_queue.h">
<Filter>Header Files\cds\container</Filter>
</ClInclude>
</ItemGroup>
</Project>
</Project>
3 changes: 2 additions & 1 deletion projects/Win/vc141/gtest-queue.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
</ClCompile>
<ClCompile Include="..\..\..\test\unit\queue\segmented_queue_hp.cpp" />
<ClCompile Include="..\..\..\test\unit\queue\vyukov_mpmc_queue.cpp" />
<ClCompile Include="..\..\..\test\unit\queue\williams_queue.cpp" />
<ClCompile Include="..\..\..\test\unit\queue\weak_ringbuffer.cpp" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -726,4 +727,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
5 changes: 4 additions & 1 deletion projects/Win/vc141/gtest-queue.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
<ClCompile Include="..\..\..\test\unit\queue\intrusive_vyukov_queue.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\test\unit\queue\williams_queue.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\test\unit\queue\weak_ringbuffer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
Expand All @@ -113,4 +116,4 @@
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
</Project>
1 change: 1 addition & 0 deletions test/stress/queue/pop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ namespace {
CDSSTRESS_FCDeque( queue_pop )
CDSSTRESS_RWQueue( queue_pop )
CDSSTRESS_StdQueue( queue_pop )
CDSSTRESS_WilliamsQueue( queue_pop )

#undef CDSSTRESS_Queue_F
#define CDSSTRESS_Queue_F( test_fixture, type_name ) \
Expand Down
1 change: 1 addition & 0 deletions test/stress/queue/push.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ namespace {
CDSSTRESS_FCDeque( queue_push )
CDSSTRESS_RWQueue( queue_push )
CDSSTRESS_StdQueue( queue_push )
CDSSTRESS_WilliamsQueue( queue_push )

#undef CDSSTRESS_Queue_F
#define CDSSTRESS_Queue_F( test_fixture, type_name ) \
Expand Down
1 change: 1 addition & 0 deletions test/stress/queue/push_pop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ namespace {
CDSSTRESS_FCDeque_HeavyValue( fc_with_heavy_value )
CDSSTRESS_RWQueue( simple_queue_push_pop )
CDSSTRESS_StdQueue( simple_queue_push_pop )
CDSSTRESS_WilliamsQueue( simple_queue_push_pop )

#undef CDSSTRESS_Queue_F
#define CDSSTRESS_Queue_F( test_fixture, type_name ) \
Expand Down
15 changes: 15 additions & 0 deletions test/stress/queue/queue_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <cds/container/fcdeque.h>
#include <cds/container/segmented_queue.h>
#include <cds/container/weak_ringbuffer.h>
#include <cds/container/williams_queue.h>

#include <cds/gc/hp.h>
#include <cds/gc/dhp.h>
Expand Down Expand Up @@ -398,6 +399,16 @@ namespace fc_details{
{};
typedef cds::container::RWQueue< Value, traits_RWQueue_mutex > RWQueue_mutex;

// WilliamsQueue
typedef cds::container::WilliamsQueue< Value > WilliamsQueue_default;

struct traits_WilliamsQueue_ic : public cds::container::williams_queue::traits
{
typedef cds::atomicity::item_counter item_counter;
};
typedef cds::container::WilliamsQueue< Value, traits_WilliamsQueue_ic > WilliamsQueue_ic;


// FCQueue
struct traits_FCQueue_stat:
public cds::container::fcqueue::make_traits<
Expand Down Expand Up @@ -836,6 +847,10 @@ namespace cds_test {
CDSSTRESS_Queue_F( test_fixture, RWQueue_mutex ) \
CDSSTRESS_RWQueue_1( test_fixture )

#define CDSSTRESS_WilliamsQueue( test_fixture ) \
CDSSTRESS_Queue_F( test_fixture, WilliamsQueue_default) \
CDSSTRESS_Queue_F( test_fixture, WilliamsQueue_ic)

#define CDSSTRESS_SegmentedQueue( test_fixture ) \
CDSSTRESS_Queue_F( test_fixture, SegmentedQueue_HP_spin ) \
CDSSTRESS_Queue_F( test_fixture, SegmentedQueue_HP_spin_padding ) \
Expand Down
1 change: 1 addition & 0 deletions test/stress/queue/random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ namespace {
CDSSTRESS_FCDeque( queue_random )
CDSSTRESS_RWQueue( queue_random )
CDSSTRESS_StdQueue( queue_random )
CDSSTRESS_WilliamsQueue( queue_random )

#undef CDSSTRESS_Queue_F
#define CDSSTRESS_Queue_F( test_fixture, type_name ) \
Expand Down
3 changes: 2 additions & 1 deletion test/unit/queue/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ set(CDSGTEST_QUEUE_SOURCES
intrusive_segmented_queue_hp.cpp
intrusive_segmented_queue_dhp.cpp
intrusive_vyukov_queue.cpp
williams_queue.cpp
)

include_directories(
Expand All @@ -37,4 +38,4 @@ include_directories(
add_executable(${PACKAGE_NAME} ${CDSGTEST_QUEUE_SOURCES})
target_link_libraries(${PACKAGE_NAME} ${CDS_TEST_LIBRARIES})

add_test(NAME ${PACKAGE_NAME} COMMAND ${PACKAGE_NAME} WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH})
add_test(NAME ${PACKAGE_NAME} COMMAND ${PACKAGE_NAME} WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH})
51 changes: 51 additions & 0 deletions test/unit/queue/williams_queue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "test_generic_queue.h"

#include <cds/container/williams_queue.h>

namespace {
namespace cc = cds::container;

class WilliamsQueue : public cds_test::generic_queue
{};

TEST_F(WilliamsQueue, defaulted)
{
typedef cds::container::WilliamsQueue< int > test_queue;

test_queue q;
test(q);
}

TEST_F(WilliamsQueue, item_counting)
{
typedef cds::container::WilliamsQueue< int,
typename cds::container::williams_queue::make_traits <
cds::opt::item_counter< cds::atomicity::item_counter >
> ::type
> test_queue;

test_queue q;
test(q);
}

TEST_F(WilliamsQueue, move)
{
typedef cds::container::WilliamsQueue< std::string > test_queue;

test_queue q;
test_string(q);
}

TEST_F(WilliamsQueue, move_item_counting)
{
struct traits : public cc::williams_queue::traits
{
typedef cds::atomicity::item_counter item_counter;
};
typedef cds::container::WilliamsQueue< std::string, traits > test_queue;

test_queue q;
test_string(q);
}

} // namespace