Skip to content

Commit eb0290a

Browse files
author
jparisu
committed
New Enchanced Thread Pool Implementation
Signed-off-by: jparisu <[email protected]>
1 parent e4cd252 commit eb0290a

40 files changed

+2883
-233
lines changed

ddsrouter_cmake/cmake/test/test_target.cmake

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,24 @@ function(add_test_executable TEST_EXECUTABLE_NAME TEST_SOURCES TEST_NAME TEST_LI
5858

5959
get_win32_path_dependencies(${TEST_EXECUTABLE_NAME} TEST_FRIENDLY_PATH)
6060

61-
foreach(test_name ${TEST_LIST})
62-
add_test(NAME ${TEST_NAME}.${test_name}
63-
COMMAND ${TEST_EXECUTABLE_NAME}
64-
--gtest_filter=${TEST_NAME}.${test_name}:**/${TEST_NAME}.${test_name}/**)
65-
66-
if(TEST_FRIENDLY_PATH)
67-
set_tests_properties(${TEST_NAME}.${test_name} PROPERTIES ENVIRONMENT "PATH=${TEST_FRIENDLY_PATH}")
68-
endif(TEST_FRIENDLY_PATH)
69-
endforeach()
61+
if( TEST_LIST )
62+
# If list of tests is not empty, add each test separatly
63+
foreach(test_name ${TEST_LIST})
64+
add_test(NAME ${TEST_NAME}.${test_name}
65+
COMMAND ${TEST_EXECUTABLE_NAME}
66+
--gtest_filter=${TEST_NAME}**.${test_name}:**/${TEST_NAME}**.${test_name}/**)
67+
68+
if(TEST_FRIENDLY_PATH)
69+
set_tests_properties(${TEST_NAME}.${test_name} PROPERTIES ENVIRONMENT "PATH=${TEST_FRIENDLY_PATH}")
70+
endif(TEST_FRIENDLY_PATH)
71+
endforeach()
72+
else()
73+
# If no tests are provided, create a single test
74+
message(STATUS "Creating general test ${TEST_NAME}.")
75+
add_test(NAME ${TEST_NAME}
76+
COMMAND ${TEST_EXECUTABLE_NAME})
77+
endif( TEST_LIST )
78+
7079

7180
target_compile_definitions(${TEST_EXECUTABLE_NAME}
7281
PRIVATE FASTDDS_ENFORCE_LOG_INFO
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* @file OwnedTask.hpp
17+
*
18+
* This file contains class Task definition.
19+
*/
20+
21+
#pragma once
22+
23+
#include <functional>
24+
25+
#include <ddsrouter_utils/thread/task/ITask.hpp>
26+
#include <ddsrouter_utils/thread/manager/IManager.hpp>
27+
28+
namespace eprosima {
29+
namespace ddsrouter {
30+
namespace utils {
31+
namespace thread {
32+
33+
template <typename ... Args>
34+
class OneShotConnector
35+
{
36+
public:
37+
38+
static void execute(IManager* tp, const std::function<void(Args...)>& callback, Args... args);
39+
40+
static void execute(IManager* tp, std::function<void(Args...)>&& callback, Args... args);
41+
42+
};
43+
using SimpleOneShotConnector = OneShotConnector<>;
44+
45+
} /* namespace thread */
46+
} /* namespace utils */
47+
} /* namespace ddsrouter */
48+
} /* namespace eprosima */
49+
50+
// Include implementation template file
51+
#include <ddsrouter_utils/thread/connector/impl/OneShotConnector.ipp>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* @file SlotConnector.hpp
17+
*
18+
* This file contains class SlotConnector definition.
19+
*/
20+
21+
#pragma once
22+
23+
#include <functional>
24+
25+
#include <ddsrouter_utils/thread/task/ITask.hpp>
26+
#include <ddsrouter_utils/thread/manager/IManager.hpp>
27+
28+
namespace eprosima {
29+
namespace ddsrouter {
30+
namespace utils {
31+
namespace thread {
32+
33+
template <typename ... Args>
34+
class SlotConnector
35+
{
36+
public:
37+
38+
SlotConnector(
39+
IManager* manager,
40+
const std::function<void(Args...)>& callback);
41+
42+
SlotConnector(
43+
IManager* manager,
44+
std::function<void(Args...)>&& callback);
45+
46+
~SlotConnector() = default;
47+
48+
void execute(Args...);
49+
50+
protected:
51+
52+
IManager* manager_;
53+
54+
std::function<void (Args...)> callback_;
55+
56+
};
57+
using SimpleSlotConnector = SlotConnector<>;
58+
59+
} /* namespace thread */
60+
} /* namespace utils */
61+
} /* namespace ddsrouter */
62+
} /* namespace eprosima */
63+
64+
// Include implementation template file
65+
#include <ddsrouter_utils/thread/connector/impl/SlotConnector.ipp>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* @file OneShotConnector.hpp
17+
*
18+
* This file contains class OneShotConnector implementation.
19+
*/
20+
21+
#pragma once
22+
23+
#include <ddsrouter_utils/thread/task/ArgsOwnedTask.hpp>
24+
25+
namespace eprosima {
26+
namespace ddsrouter {
27+
namespace utils {
28+
namespace thread {
29+
30+
template <typename ... Args>
31+
void OneShotConnector<Args...>::execute(
32+
IManager* manager,
33+
const std::function<void(Args...)>& callback,
34+
Args... args)
35+
{
36+
manager->execute(
37+
std::make_unique<ArgsOwnedTask<Args...>>(
38+
callback,
39+
args...
40+
)
41+
);
42+
}
43+
44+
template <typename ... Args>
45+
void OneShotConnector<Args...>::execute(
46+
IManager* manager,
47+
std::function<void(Args...)>&& callback,
48+
Args... args)
49+
{
50+
manager->execute(
51+
std::make_unique<ArgsOwnedTask<Args...>>(
52+
std::move(callback),
53+
args...
54+
)
55+
);
56+
}
57+
58+
// template <typename ... Args>
59+
// void OneShotConnector<Args...>::execute(
60+
// IManager* manager,
61+
// std::function<void(Args...)> callback,
62+
// Args... args)
63+
// {
64+
// manager->execute(
65+
// std::make_unique<ArgsOwnedTask<Args...>>(
66+
// callback,
67+
// args...
68+
// )
69+
// );
70+
// }
71+
72+
} /* namespace thread */
73+
} /* namespace event */
74+
} /* namespace ddsrouter */
75+
} /* namespace eprosima */
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* @file SlotConnector.hpp
17+
*
18+
* This file contains class SlotConnector implementation.
19+
*/
20+
21+
#pragma once
22+
23+
#include <ddsrouter_utils/thread/task/ArgsOwnedTask.hpp>
24+
25+
namespace eprosima {
26+
namespace ddsrouter {
27+
namespace utils {
28+
namespace thread {
29+
30+
template <typename ... Args>
31+
SlotConnector<Args...>::SlotConnector(
32+
IManager* manager,
33+
const std::function<void(Args...)>& callback)
34+
: manager_(manager)
35+
, callback_(callback)
36+
{
37+
}
38+
39+
template <typename ... Args>
40+
SlotConnector<Args...>::SlotConnector(
41+
IManager* manager,
42+
std::function<void(Args...)>&& callback)
43+
: manager_(manager)
44+
, callback_(std::move(callback))
45+
{
46+
}
47+
48+
template <typename ... Args>
49+
void SlotConnector<Args...>::execute(Args... args)
50+
{
51+
manager_->execute(
52+
std::make_unique<ArgsOwnedTask<Args...>>(
53+
callback_,
54+
args...
55+
)
56+
);
57+
}
58+
59+
} /* namespace thread */
60+
} /* namespace event */
61+
} /* namespace ddsrouter */
62+
} /* namespace eprosima */
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* @file AsyncManager.hpp
17+
*
18+
* This file contains class AsyncManager definition.
19+
*/
20+
21+
#pragma once
22+
23+
#include <map>
24+
#include <mutex>
25+
#include <thread>
26+
#include <vector>
27+
28+
#include <ddsrouter_utils/library/library_dll.h>
29+
#include <ddsrouter_utils/thread/manager/IManager.hpp>
30+
#include <ddsrouter_utils/thread/thread/CustomThread.hpp>
31+
#include <ddsrouter_utils/types/Atomicable.hpp>
32+
33+
namespace eprosima {
34+
namespace ddsrouter {
35+
namespace utils {
36+
namespace thread {
37+
38+
using TasksCollectionType =
39+
Atomicable<
40+
std::vector<
41+
std::pair<
42+
std::unique_ptr<CustomThread>,
43+
std::unique_ptr<ITask>>>>;
44+
45+
/**
46+
* TODO
47+
*/
48+
class AsyncManager : public IManager
49+
{
50+
public:
51+
52+
AsyncManager() = default;
53+
54+
~AsyncManager();
55+
56+
virtual void execute(std::unique_ptr<ITask>&& task) override;
57+
58+
void clean_threads();
59+
60+
protected:
61+
62+
TasksCollectionType tasks_running_;
63+
};
64+
65+
} /* namespace thread */
66+
} /* namespace utils */
67+
} /* namespace ddsrouter */
68+
} /* namespace eprosima */

0 commit comments

Comments
 (0)