Arcane  v4.1.3.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
ConcurrencyApplication.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* ConcurrencyApplication.h (C) 2000-2026 */
9/* */
10/* Gestion des services de multi-threading d'une application Arccore. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arccore/concurrency/internal/ConcurrencyApplication.h"
15
16#include "arccore/base/CheckedConvert.h"
17#include "arccore/base/PlatformUtils.h"
18#include "arccore/base/FatalErrorException.h"
19#include "arccore/base/internal/DependencyInjection.h"
20
21#include "arccore/trace/ITraceMng.h"
22
23#include "arccore/concurrency/ITaskImplementation.h"
24#include "arccore/concurrency/IThreadImplementation.h"
25#include "arccore/concurrency/IThreadImplementationService.h"
26#include "arccore/concurrency/TaskFactory.h"
27#include "arccore/concurrency/internal/TaskFactoryInternal.h"
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32namespace Arcane
33{
34
42template <typename InterfaceType> Ref<InterfaceType> ConcurrencyApplication::
43tryCreateServiceUsingInjector(ConstArrayView<String> names, String* found_name, bool has_trace)
44{
45 DependencyInjection::Injector injector;
46 injector.fillWithGlobalFactories();
47 // Ajoute une instance de ITraceMng* pour les services qui en ont besoin
48 if (has_trace)
49 injector.bind(m_trace.get());
50
51 if (found_name)
52 (*found_name) = String();
53 for (String s : names) {
54 auto t = injector.createInstance<InterfaceType>(s, true);
55 if (t.get()) {
56 if (found_name)
57 (*found_name) = s;
58 return t;
59 }
60 }
61 return {};
62}
63
64/*---------------------------------------------------------------------------*/
65/*---------------------------------------------------------------------------*/
66
67void ConcurrencyApplication::
68setCoreServices(const ConcurrencyApplicationBuildInfo& build_info)
69{
70
71 // Recherche le service utilisé pour connaitre la pile d'appel
72 bool has_dbghelp = false;
73 {
74 String dbghelp_service_name = "DbgHelpStackTraceService";
76 String found_name;
78 const auto v = Convert::Type<Int32>::tryParseFromEnvironment("ARCANE_USE_BACKWARDCPP", true);
79 if (v && v.value() != 0) {
80 names.add("BackwardCppStackTraceService");
81 }
82 names.add("LibUnwind");
83 names.add("DbgHelpStackTraceService");
84 sv = tryCreateServiceUsingInjector<IStackTraceService>(names.constView(), &found_name, true);
85 if (found_name == dbghelp_service_name)
86 has_dbghelp = true;
87 if (sv.get()) {
88 m_stack_trace_service = sv;
90 }
91 }
92
93 // Recherche le service utilisé pour connaitre les infos sur les symboles
94 // du code source. Pour l'instant, on ne supporte que LLVM et on n'active ce service
95 // que si la variable d'environnement ARCANE_LLVMSYMBOLIZER_PATH est définie.
96 {
97 Impl::CoreArray<String> names;
98 String found_name;
99 Ref<ISymbolizerService> sv;
100
101 if (!platform::getEnvironmentVariable("ARCANE_LLVMSYMBOLIZER_PATH").null())
102 names.add("LLVMSymbolizer");
103 if (has_dbghelp)
104 names.add("DbgHelpSymbolizerService");
105 sv = tryCreateServiceUsingInjector<ISymbolizerService>(names.constView(), &found_name, true);
106 if (sv.get()) {
107 m_symbolizer_service = sv;
109 }
110 }
111
112 // Recherche le service implémentant le support du multi-threading.
113 {
114 ConstArrayView<String> names = build_info.threadImplementationServices();
115 String found_name;
116 auto sv = tryCreateServiceUsingInjector<IThreadImplementationService>(names, &found_name, false);
117 if (!sv.get())
118 ARCCORE_FATAL("Can not find implementation for 'IThreadImplementation' (names='{0}').", names);
119 m_thread_implementation_service = sv;
120 m_thread_implementation = sv->createImplementation();
121 Arccore::Concurrency::setThreadImplementation(m_thread_implementation.get());
122 m_thread_implementation->initialize();
123 m_used_thread_service_name = found_name;
124 }
125
126 // Le gestionnaire de thread a pu changer et il faut donc
127 // reinitialiser le gestionnaire de trace.
128 m_trace->resetThreadStatus();
129
130 // Recherche le service utilisé pour gérer les tâches
131 {
132 Integer nb_task_thread = build_info.nbTaskThread();
133 if (nb_task_thread >= 0) {
134
135 ConstArrayView<String> names = build_info.taskImplementationServices();
136 String found_name;
137 auto sv = tryCreateServiceUsingInjector<ITaskImplementation>(names, &found_name, false);
138 if (sv.get()) {
139 TaskFactoryInternal::setImplementation(sv.get());
140 sv->initialize(nb_task_thread);
141 m_used_task_service_name = found_name;
142 m_task_implementation = sv;
143 }
144 else
145 ARCCORE_FATAL("Can not find task implementation service (names='{0}')."
146 " Please check if Arcane is configured with Intel TBB library",
147 names);
148 }
149
150 if (auto v = Convert::Type<Int32>::tryParseFromEnvironment("ARCANE_TASK_VERBOSE_LEVEL", true))
152 }
153}
154
155/*---------------------------------------------------------------------------*/
156/*---------------------------------------------------------------------------*/
157
158} // namespace Arcane
159
160/*---------------------------------------------------------------------------*/
161/*---------------------------------------------------------------------------*/
#define ARCCORE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Ref< InterfaceType > tryCreateServiceUsingInjector(ConstArrayView< String > names, String *found_name, bool has_trace)
String m_used_task_service_name
Nom du service utilisé pour gérer les tâches.
ReferenceCounter< ITraceMng > m_trace
Gestionnaire de traces.
String m_used_thread_service_name
Nom du service utilisé pour gérer les threads.
Vue constante d'un tableau de type T.
static ARCCORE_BASE_EXPORT std::optional< Int32 > tryParseFromEnvironment(StringView s, bool throw_if_invalid)
Classe template pour convertir un type.
ConstArrayView< DataType > constView() const
Vue constante.
Référence à une instance.
InstanceType * get() const
Instance associée ou nullptr si aucune.
Chaîne de caractères unicode.
static void setVerboseLevel(Integer v)
Positionne le niveau de verbosité (0 pour pas d'affichage qui est le défaut)
ARCCORE_BASE_EXPORT ISymbolizerService * setSymbolizerService(ISymbolizerService *service)
Positionne le service pour obtenir des informations sur les symboles du code source.
ARCCORE_BASE_EXPORT IStackTraceService * setStackTraceService(IStackTraceService *service)
Positionne le service utilisé pour obtenir la pile d'appel.
ARCCORE_BASE_EXPORT String getEnvironmentVariable(const String &name)
Variable d'environnement du nom name.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Int32 Integer
Type représentant un entier.