Skip to content

Commit

Permalink
Improve try_put_and_wait coverage (#1501)
Browse files Browse the repository at this point in the history
  • Loading branch information
kboyarinov authored Sep 2, 2024
1 parent d666d34 commit fe3c895
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
4 changes: 0 additions & 4 deletions include/oneapi/tbb/detail/_flow_graph_join_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,6 @@
__TBB_FLOW_GRAPH_METAINFO_ARG(metainfo(&info))
{}
#if __TBB_PREVIEW_FLOW_GRAPH_TRY_PUT_AND_WAIT
queueing_port_operation(const T& e, op_type t)
: type(char(t)), my_val(e), my_arg(nullptr), bypass_t(nullptr), metainfo(nullptr)
{}

queueing_port_operation(const T* p, op_type t)
: type(char(t)), my_arg(const_cast<T*>(p)), bypass_t(nullptr), metainfo(nullptr)
{}
Expand Down
10 changes: 4 additions & 6 deletions include/oneapi/tbb/flow_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -1931,13 +1931,11 @@ class priority_queue_node : public buffer_node<T> {

bool internal_push(prio_operation *op) override {
#if __TBB_PREVIEW_FLOW_GRAPH_TRY_PUT_AND_WAIT
if (op->metainfo) {
prio_push(*(op->elem), *(op->metainfo));
} else
__TBB_ASSERT(op->metainfo, nullptr);
prio_push(*(op->elem), *(op->metainfo));
#else
prio_push(*(op->elem));
#endif
{
prio_push(*(op->elem));
}
op->status.store(SUCCEEDED, std::memory_order_release);
return true;
}
Expand Down
39 changes: 38 additions & 1 deletion test/tbb/test_join_node.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2005-2022 Intel Corporation
Copyright (c) 2005-2024 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -154,3 +154,40 @@ TEST_CASE("Test removal of the predecessor while having none") {

test(connect_join_via_make_edge);
}

//! \brief \ref error_guessing
TEST_CASE("Test reservation on the port") {
tbb::flow::graph g;

tbb::flow::buffer_node<int> buffer1(g), buffer2(g);
tbb::flow::join_node<std::tuple<int, int>, tbb::flow::reserving> join(g);
tbb::flow::buffer_node<std::tuple<int, int>> buffer3(g);

auto& port0 = tbb::flow::input_port<0>(join);
auto& port1 = tbb::flow::input_port<1>(join);

tbb::flow::make_edge(buffer1, port0);
tbb::flow::make_edge(buffer2, port1);
tbb::flow::make_edge(join, buffer3);

int value = -42;
bool result = port0.reserve(value);
CHECK_MESSAGE(!result, "Incorrect reserve return value");

result = port1.reserve(value);
CHECK_MESSAGE(!result, "Incorrect reserve return value");

buffer1.try_put(1);
g.wait_for_all();

result = port0.reserve(value);
CHECK_MESSAGE(result, "Incorrect reserve return value");
CHECK_MESSAGE(value == 1, "Incorrect reserved value");
port0.release();

buffer2.try_put(2);
g.wait_for_all();

result = port1.reserve(value);
CHECK_MESSAGE(result, "incorrect reserve return value");
}

0 comments on commit fe3c895

Please sign in to comment.