Arcane  v3.14.10.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
ConcurrencyGlobal.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2024 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/* ConcurrencyGlobal.h (C) 2000-2024 */
9/* */
10/* Définitions globales de la composante 'Concurrency' de 'Arccore'. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
15#include "arccore/base/ReferenceCounter.h"
16#include "arccore/base/Ref.h"
17#include "arccore/base/NotSupportedException.h"
18
19#include "arccore/concurrency/ConcurrencyGlobal.h"
20
21#include "arccore/concurrency/NullThreadImplementation.h"
22#include "arccore/concurrency/SpinLock.h"
23
24#ifdef ARCCORE_HAS_GLIB
25#include "arccore/concurrency/GlibThreadImplementation.h"
26#endif
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31namespace Arccore
32{
33
34namespace
35{
36 NullThreadImplementation global_null_thread_implementation;
37 ReferenceCounter<IThreadImplementation> global_thread_implementation{ &global_null_thread_implementation };
38} // namespace
39
40/*---------------------------------------------------------------------------*/
41/*---------------------------------------------------------------------------*/
42
43IThreadImplementation* Concurrency::
44getThreadImplementation()
45{
46 return global_thread_implementation.get();
47}
48
49/*---------------------------------------------------------------------------*/
50/*---------------------------------------------------------------------------*/
51
52IThreadImplementation* Concurrency::
53setThreadImplementation(IThreadImplementation* service)
54{
55 IThreadImplementation* old_service = global_thread_implementation.get();
56 global_thread_implementation = service;
57 if (!service)
58 global_thread_implementation = &global_null_thread_implementation;
59 return old_service;
60}
61
62/*---------------------------------------------------------------------------*/
63/*---------------------------------------------------------------------------*/
64
65Ref<IThreadImplementation> Concurrency::
66createGlibThreadImplementation()
67{
68#ifdef ARCCORE_HAS_GLIB
69 return makeRef<IThreadImplementation>(new GlibThreadImplementation());
70#else
71 throw NotSupportedException(A_FUNCINFO,"GLib is not available Recompile Arccore with ARCCORE_ENABLE_GLIB=TRUE");
72#endif
73}
74
75/*---------------------------------------------------------------------------*/
76/*---------------------------------------------------------------------------*/
77
79{
80 public:
81 static Ref<IThreadImplementation> create()
82 {
83 return makeRef<>(new NullThreadImplementation());
84 }
85};
86
87Ref<IThreadImplementation> Concurrency::
88createNullThreadImplementation()
89{
90 return NullThreadImplementationFactory::create();
91}
92
93/*---------------------------------------------------------------------------*/
94/*---------------------------------------------------------------------------*/
95
96void IThreadImplementation::
97_deprecatedCreateSpinLock(Int64* spin_lock_addr)
98{
99 createSpinLock(spin_lock_addr);
100}
101
102/*---------------------------------------------------------------------------*/
103/*---------------------------------------------------------------------------*/
104
105void IThreadImplementation::
106_deprecatedLockSpinLock(Int64* spin_lock_addr, Int64* scoped_spin_lock_addr)
107{
108 lockSpinLock(spin_lock_addr, scoped_spin_lock_addr);
109}
110
111/*---------------------------------------------------------------------------*/
112/*---------------------------------------------------------------------------*/
113
114void IThreadImplementation::
115_deprecatedUnlockSpinLock(Int64* spin_lock_addr, Int64* scoped_spin_lock_addr)
116{
117 unlockSpinLock(spin_lock_addr, scoped_spin_lock_addr);
118}
119
120/*---------------------------------------------------------------------------*/
121/*---------------------------------------------------------------------------*/
122
123ARCCORE_DEFINE_REFERENCE_COUNTED_CLASS(IThreadImplementation);
124
125/*---------------------------------------------------------------------------*/
126/*---------------------------------------------------------------------------*/
127
128} // End namespace Arccore
129
130/*---------------------------------------------------------------------------*/
131/*---------------------------------------------------------------------------*/
#define ARCCORE_DEFINE_REFERENCE_COUNTED_CLASS(class_name)
Macro pour définir les méthodes et types une classe qui utilise un compteur de référence.
Gestion des références à une classe C++.
Implémentation des threads en mode mono-thread.
Espace de nom de Arccore.
Definition ArcaneTypes.h:24