Skip to content

Commit f447332

Browse files
author
jparisu
committed
Implementation of new Thread Pool
Signed-off-by: jparisu <[email protected]>
1 parent 60fe631 commit f447332

36 files changed

+2577
-75
lines changed

Diff for: cmake_utils/cmake/test/test_target.cmake

+18-9
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 <cpp_utils/threading/task/ITask.hpp>
26+
#include <cpp_utils/threading/manager/IManager.hpp>
27+
28+
namespace eprosima {
29+
namespace utils {
30+
namespace threading {
31+
32+
template <typename ... Args>
33+
class OneShotConnector
34+
{
35+
public:
36+
37+
static void execute(IManager* tp, const std::function<void(Args...)>& callback, Args... args);
38+
39+
static void execute(IManager* tp, std::function<void(Args...)>&& callback, Args... args);
40+
41+
};
42+
using SimpleOneShotConnector = OneShotConnector<>;
43+
44+
} /* namespace threading */
45+
} /* namespace utils */
46+
} /* namespace eprosima */
47+
48+
// Include implementation template file
49+
#include <cpp_utils/threading/connector/impl/OneShotConnector.ipp>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 <cpp_utils/threading/task/ITask.hpp>
26+
#include <cpp_utils/threading/manager/IManager.hpp>
27+
28+
namespace eprosima {
29+
namespace utils {
30+
namespace threading {
31+
32+
template <typename ... Args>
33+
class SlotConnector
34+
{
35+
public:
36+
37+
SlotConnector(
38+
IManager* manager,
39+
const std::function<void(Args...)>& callback);
40+
41+
SlotConnector(
42+
IManager* manager,
43+
std::function<void(Args...)>&& callback);
44+
45+
~SlotConnector() = default;
46+
47+
void execute(Args...);
48+
49+
protected:
50+
51+
IManager* manager_;
52+
53+
std::function<void (Args...)> callback_;
54+
55+
};
56+
using SimpleSlotConnector = SlotConnector<>;
57+
58+
} /* namespace threading */
59+
} /* namespace utils */
60+
} /* namespace eprosima */
61+
62+
// Include implementation template file
63+
#include <cpp_utils/threading/connector/impl/SlotConnector.ipp>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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 <cpp_utils/threading/task/ArgsOwnedTask.hpp>
24+
25+
namespace eprosima {
26+
namespace utils {
27+
namespace threading {
28+
29+
template <typename ... Args>
30+
void OneShotConnector<Args...>::execute(
31+
IManager* manager,
32+
const std::function<void(Args...)>& callback,
33+
Args... args)
34+
{
35+
manager->execute(
36+
std::make_unique<ArgsOwnedTask<Args...>>(
37+
callback,
38+
args...
39+
)
40+
);
41+
}
42+
43+
template <typename ... Args>
44+
void OneShotConnector<Args...>::execute(
45+
IManager* manager,
46+
std::function<void(Args...)>&& callback,
47+
Args... args)
48+
{
49+
manager->execute(
50+
std::make_unique<ArgsOwnedTask<Args...>>(
51+
std::move(callback),
52+
args...
53+
)
54+
);
55+
}
56+
57+
// template <typename ... Args>
58+
// void OneShotConnector<Args...>::execute(
59+
// IManager* manager,
60+
// std::function<void(Args...)> callback,
61+
// Args... args)
62+
// {
63+
// manager->execute(
64+
// std::make_unique<ArgsOwnedTask<Args...>>(
65+
// callback,
66+
// args...
67+
// )
68+
// );
69+
// }
70+
71+
} /* namespace thread */
72+
} /* namespace event */
73+
} /* namespace eprosima */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 <cpp_utils/threading/task/ArgsOwnedTask.hpp>
24+
25+
namespace eprosima {
26+
namespace utils {
27+
namespace threading {
28+
29+
template <typename ... Args>
30+
SlotConnector<Args...>::SlotConnector(
31+
IManager* manager,
32+
const std::function<void(Args...)>& callback)
33+
: manager_(manager)
34+
, callback_(callback)
35+
{
36+
}
37+
38+
template <typename ... Args>
39+
SlotConnector<Args...>::SlotConnector(
40+
IManager* manager,
41+
std::function<void(Args...)>&& callback)
42+
: manager_(manager)
43+
, callback_(std::move(callback))
44+
{
45+
}
46+
47+
template <typename ... Args>
48+
void SlotConnector<Args...>::execute(Args... args)
49+
{
50+
manager_->execute(
51+
std::make_unique<ArgsOwnedTask<Args...>>(
52+
callback_,
53+
args...
54+
)
55+
);
56+
}
57+
58+
} /* namespace thread */
59+
} /* namespace event */
60+
} /* namespace eprosima */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 <cpp_utils/library/library_dll.h>
29+
#include <cpp_utils/threading/manager/IManager.hpp>
30+
#include <cpp_utils/threading/thread/CustomThread.hpp>
31+
#include <cpp_utils/types/Atomicable.hpp>
32+
33+
namespace eprosima {
34+
namespace utils {
35+
namespace threading {
36+
37+
using TasksCollectionType =
38+
Atomicable<
39+
std::vector<
40+
std::pair<
41+
std::unique_ptr<CustomThread>,
42+
std::unique_ptr<ITask>>>>;
43+
44+
/**
45+
* TODO
46+
*/
47+
class AsyncManager : public IManager
48+
{
49+
public:
50+
51+
AsyncManager() = default;
52+
53+
~AsyncManager();
54+
55+
virtual void execute(std::unique_ptr<ITask>&& task) override;
56+
57+
void clean_threads();
58+
59+
protected:
60+
61+
TasksCollectionType tasks_running_;
62+
};
63+
64+
} /* namespace threading */
65+
} /* namespace utils */
66+
} /* namespace eprosima */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 IManager.hpp
17+
*
18+
* This file contains class SlotThreadPool definition.
19+
*/
20+
21+
#pragma once
22+
23+
#include <cpp_utils/threading/task/ITask.hpp>
24+
25+
namespace eprosima {
26+
namespace utils {
27+
namespace threading {
28+
29+
class IManager
30+
{
31+
public:
32+
virtual ~IManager() {};
33+
virtual void execute(std::unique_ptr<ITask>&& task) = 0;
34+
};
35+
36+
} /* namespace threading */
37+
} /* namespace utils */
38+
} /* namespace eprosima */

0 commit comments

Comments
 (0)