Skip to content

Commit

Permalink
remove dependency on tbb interfaces from RTaskArena
Browse files Browse the repository at this point in the history
Introduce yet another layer of abstraction in ROpaqueTaskArena,
a class inheriting from tbb::task_arena that will allow us to keep
tbb hidden from ROOT interfaces while solving the issue of having to
forward-declare tbb::task_arena in an interface-dependent way
  • Loading branch information
xvallspl committed Jan 20, 2021
1 parent eba6696 commit 2af0cc3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
11 changes: 5 additions & 6 deletions core/imt/inc/ROOT/RTaskArena.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@

/// tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow
/// to forward declare tbb::task_arena without forward declaring tbb::interface7
namespace tbb{
namespace interface7{class task_arena;}
using task_arena = interface7::task_arena;
}

namespace ROOT {

class ROpaqueTaskArena;

namespace Internal {

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -65,11 +64,11 @@ class RTaskArenaWrapper {
public:
~RTaskArenaWrapper(); // necessary to set size back to zero
static unsigned TaskArenaSize(); // A static getter lets us check for RTaskArenaWrapper's existence
tbb::task_arena &Access();
ROOT::ROpaqueTaskArena &Access();
private:
RTaskArenaWrapper(unsigned maxConcurrency = 0);
friend std::shared_ptr<ROOT::Internal::RTaskArenaWrapper> GetGlobalTaskArena(unsigned maxConcurrency);
std::unique_ptr<tbb::task_arena> fTBBArena;
std::unique_ptr<ROOT::ROpaqueTaskArena> fTBBArena;
static unsigned fNWorkers;
};

Expand Down
5 changes: 5 additions & 0 deletions core/imt/src/ROpaqueTaskArena.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "tbb/task_arena.h"

namespace ROOT {
class ROpaqueTaskArena: public tbb::task_arena {};
}
5 changes: 3 additions & 2 deletions core/imt/src/RTaskArena.cxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "ROOT/RTaskArena.hxx"
#include "ROpaqueTaskArena.hxx"
#include "TError.h"
#include "TROOT.h"
#include "TThread.h"
Expand Down Expand Up @@ -68,7 +69,7 @@ int LogicalCPUBandwithControl()
/// * If no BC in place and maxConcurrency<1, defaults to the default tbb number of threads,
/// which is CPU affinity aware
////////////////////////////////////////////////////////////////////////////////
RTaskArenaWrapper::RTaskArenaWrapper(unsigned maxConcurrency) : fTBBArena(new tbb::task_arena{})
RTaskArenaWrapper::RTaskArenaWrapper(unsigned maxConcurrency) : fTBBArena(new ROpaqueTaskArena{})
{
const unsigned tbbDefaultNumberThreads = fTBBArena->max_concurrency(); // not initialized, automatic state
maxConcurrency = maxConcurrency > 0 ? std::min(maxConcurrency, tbbDefaultNumberThreads) : tbbDefaultNumberThreads;
Expand Down Expand Up @@ -100,7 +101,7 @@ unsigned RTaskArenaWrapper::TaskArenaSize()
////////////////////////////////////////////////////////////////////////////////
/// Provides access to the wrapped tbb::task_arena.
////////////////////////////////////////////////////////////////////////////////
tbb::task_arena &RTaskArenaWrapper::Access()
ROOT::ROpaqueTaskArena &RTaskArenaWrapper::Access()
{
return *fTBBArena;
}
Expand Down
1 change: 1 addition & 0 deletions core/imt/src/TThreadExecutor.cxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "ROOT/TThreadExecutor.hxx"
#include "ROpaqueTaskArena.hxx"
#if !defined(_MSC_VER)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
Expand Down
2 changes: 1 addition & 1 deletion core/imt/test/testRTaskArena.cxx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "TROOT.h"
#include "ROOT/RTaskArena.hxx"
#include "ROOT/TThreadExecutor.hxx"
#include "../src/ROpaqueTaskArena.hxx"
#include <fstream>
#include <random>
#include <thread>
#include "gtest/gtest.h"
#include "tbb/task_arena.h"

#ifdef R__USE_IMT

Expand Down

0 comments on commit 2af0cc3

Please sign in to comment.