forked from gazebosim/gazebo-classic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use oneapi::tbb::task_group instead of tbb::task if available
As tbb::task has been removed in oneTBB 2021.01, we need to replace its use with oneapi::tbb::task_group. Define a wrapper so that tbb::task_group is used for newer versions of oneTBB. Fixes gazebosim#2867. Signed-off-by: Alex Dewar <alex.dewar@gmx.co.uk>
- Loading branch information
Showing
7 changed files
with
118 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright (C) 2021 Alex Dewar | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
#ifndef _TASK_GROUP_HH_ | ||
#define _TASK_GROUP_HH_ | ||
|
||
#include <utility> | ||
|
||
#if __has_include(<oneapi/tbb/task_group.h>) | ||
|
||
// Emit is both a macro in Qt and a function defined by tbb | ||
#undef emit | ||
#include <oneapi/tbb/task_group.h> | ||
#define emit | ||
|
||
namespace gazebo { | ||
namespace transport { | ||
class TaskGroup | ||
{ | ||
public: ~TaskGroup() noexcept | ||
{ | ||
// Wait for running tasks to finish | ||
this->taskGroup.wait(); | ||
} | ||
|
||
public: template<class Functor, class... Args> void run(Args&&... args) | ||
{ | ||
this->taskGroup.run(Functor(std::forward<Args>(args)...)); | ||
} | ||
|
||
private: oneapi::tbb::task_group taskGroup; | ||
}; | ||
} | ||
} | ||
#else | ||
#include <tbb/task.h> | ||
|
||
namespace gazebo { | ||
namespace transport { | ||
class TaskGroup | ||
{ | ||
/// \brief A helper class which provides the requisite execute() method | ||
/// required by tbb. | ||
private: template<class T> class TaskWrapper : public tbb::task | ||
{ | ||
public: template<class... Args> TaskWrapper<T>(Args&&... args) | ||
: functor(std::forward<Args>(args)...) | ||
{ | ||
} | ||
|
||
public: tbb::task *execute() | ||
{ | ||
this->functor(); | ||
return nullptr; | ||
} | ||
|
||
private: T functor; | ||
}; | ||
|
||
public: template<class Functor, class... Args> void run(Args&&... args) | ||
{ | ||
auto *task = new (tbb::task::allocate_root()) | ||
TaskWrapper<Functor>(std::forward<Args>(args)...); | ||
tbb::task::enqueue(*task); | ||
} | ||
}; | ||
} | ||
} | ||
|
||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters