Arcane  v3.14.10.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
NullThreadImplementation.h
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/* NullThreadImplementation.h (C) 2000-2024 */
9/* */
10/* Gestionnaire de thread en mode mono-thread. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_CONCURRENCY_NULLTHREADIMPLEMENTATION_H
13#define ARCCORE_CONCURRENCY_NULLTHREADIMPLEMENTATION_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arccore/concurrency/IThreadBarrier.h"
18#include "arccore/concurrency/IThreadImplementation.h"
19
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arccore
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30/*!
31 * \brief Implémentation d'une barrière en mono-thread.
32 */
33class ARCCORE_CONCURRENCY_EXPORT NullThreadBarrier
34: public IThreadBarrier
35{
36 void init(Integer nb_thread) override { ARCCORE_UNUSED(nb_thread); }
37 void destroy() override { delete this; }
38 bool wait() override { return true; }
39};
40
41/*---------------------------------------------------------------------------*/
42/*---------------------------------------------------------------------------*/
43/*!
44 * \brief Implémentation des threads en mode mono-thread.
45 */
46class ARCCORE_CONCURRENCY_EXPORT NullThreadImplementation
49{
50 // Pour créer dynamiquement les instances
52
53 private:
54
55 // TODO Utiliser ARCCORE_DEFINE_REFERENCE_COUNTED_INCLASS_METHODS()
56 // quand il n'y a aura plus d'instances statiques de cette classe.
57 ReferenceCounterImpl* _internalReferenceCounter() override { return this; }
58 void _internalAddReference() override
59 {
60 if (m_do_destroy)
61 Arccore::ReferenceCounterImpl::_internalAddReference();
62 }
63 bool _internalRemoveReference() override
64 {
65 if (m_do_destroy)
66 return Arccore::ReferenceCounterImpl::_internalRemoveReference();
67 return false;
68 }
69
70 public:
71
72 void addReference() override { _internalAddReference(); }
73 void removeReference() override { _internalRemoveReference(); }
74
75 public:
76
77 ARCCORE_DEPRECATED_REASON("Y2023: This constructor is internal to Arcane. Use Concurrency::createNullThreadImplementation() instead")
79 : m_do_destroy(false)
80 {}
81
82 public:
83
84 void initialize() override {}
85 ThreadImpl* createThread(IFunctor*) override { return nullptr; }
86 void joinThread(ThreadImpl*) override {}
87 void destroyThread(ThreadImpl*) override {}
88
89 void createSpinLock(Int64* spin_lock_addr) override
90 {
91 ARCCORE_UNUSED(spin_lock_addr);
92 }
93 void lockSpinLock(Int64* spin_lock_addr, Int64* scoped_spin_lock_addr) override
94 {
95 ARCCORE_UNUSED(spin_lock_addr);
96 ARCCORE_UNUSED(scoped_spin_lock_addr);
97 }
98 void unlockSpinLock(Int64* spin_lock_addr, Int64* scoped_spin_lock_addr) override
99 {
100 ARCCORE_UNUSED(spin_lock_addr);
101 ARCCORE_UNUSED(scoped_spin_lock_addr);
102 }
103
104 MutexImpl* createMutex() override { return nullptr; }
105 void destroyMutex(MutexImpl*) override {}
106 void lockMutex(MutexImpl*) override {}
107 void unlockMutex(MutexImpl*) override {}
108
109 Int64 currentThread() override { return 0; }
110
111 IThreadBarrier* createBarrier() override { return new NullThreadBarrier(); }
112
113 bool isMultiThread() const override { return false; }
114
115 private:
116
117 // Constructeur utilisé par NullThreadImplementationFactory qui oblige à créer via 'new'
119 : m_do_destroy(true)
120 {}
121
122 private:
123
124 bool m_do_destroy = true;
125};
126
127/*---------------------------------------------------------------------------*/
128/*---------------------------------------------------------------------------*/
129
130} // End namespace Arccore
131
132/*---------------------------------------------------------------------------*/
133/*---------------------------------------------------------------------------*/
134
135#endif
Interface d'un service implémentant le support des threads.
Implémentation d'une barrière en mono-thread.
Implémentation des threads en mode mono-thread.
bool isMultiThread() const override
Vrai si l'implémentation supporte plusieurs threads.
Implémentation thread-safe d'un compteur de référence.
Espace de nom de Arccore.
Definition ArcaneTypes.h:24
Int32 Integer
Type représentant un entier.
std::int64_t Int64
Type entier signé sur 64 bits.