Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
NullThreadImplementation.h
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/* NullThreadImplementation.h (C) 2000-2026 */
9/* */
10/* Single-threaded thread manager. */
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 Arcane
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
34class ARCCORE_CONCURRENCY_EXPORT NullThreadBarrier
35: public IThreadBarrier
36{
37 void init(Integer nb_thread) override { ARCCORE_UNUSED(nb_thread); }
38 void destroy() override { delete this; }
39 void wait() override { /* Nothing to do */ }
40};
41
42/*---------------------------------------------------------------------------*/
43/*---------------------------------------------------------------------------*/
44
48class ARCCORE_CONCURRENCY_EXPORT NullThreadImplementation
51{
52 // To dynamically create instances
53 friend class NullThreadImplementationFactory;
54
55 private:
56
57 // TODO Use ARCCORE_DEFINE_REFERENCE_COUNTED_INCLASS_METHODS()
58 // when there are no more static instances of this class.
59 ReferenceCounterImpl* _internalReferenceCounter() override { return this; }
60 void _internalAddReference() override
61 {
62 if (m_do_destroy)
63 Arccore::ReferenceCounterImpl::_internalAddReference();
64 }
65 bool _internalRemoveReference() override
66 {
67 if (m_do_destroy)
68 return Arccore::ReferenceCounterImpl::_internalRemoveReference();
69 return false;
70 }
71
72 public:
73
74 void addReference() override { _internalAddReference(); }
75 void removeReference() override { _internalRemoveReference(); }
76
77 public:
78
79 ARCCORE_DEPRECATED_REASON("Y2023: This constructor is internal to Arcane. Use Concurrency::createNullThreadImplementation() instead")
80 NullThreadImplementation()
81 : m_do_destroy(false)
82 {}
83
84 public:
85
86 void initialize() override {}
87 ThreadImpl* createThread(IFunctor*) override { return nullptr; }
88 void joinThread(ThreadImpl*) override {}
89 void destroyThread(ThreadImpl*) override {}
90
91 void createSpinLock(Int64* spin_lock_addr) override
92 {
93 ARCCORE_UNUSED(spin_lock_addr);
94 }
95 void lockSpinLock(Int64* spin_lock_addr, Int64* scoped_spin_lock_addr) override
96 {
97 ARCCORE_UNUSED(spin_lock_addr);
98 ARCCORE_UNUSED(scoped_spin_lock_addr);
99 }
100 void unlockSpinLock(Int64* spin_lock_addr, Int64* scoped_spin_lock_addr) override
101 {
102 ARCCORE_UNUSED(spin_lock_addr);
103 ARCCORE_UNUSED(scoped_spin_lock_addr);
104 }
105
106 MutexImpl* createMutex() override { return nullptr; }
107 void destroyMutex(MutexImpl*) override {}
108 void lockMutex(MutexImpl*) override {}
109 void unlockMutex(MutexImpl*) override {}
110
111 Int64 currentThread() override { return 0; }
112
113 IThreadBarrier* createBarrier() override { return new NullThreadBarrier(); }
114
115 bool isMultiThread() const override { return false; }
116
117 private:
118
119 // Constructor used by NullThreadImplementationFactory which forces creation via 'new'
120 explicit NullThreadImplementation(bool)
121 {}
122
123 private:
124
125 bool m_do_destroy = true;
126};
127
128/*---------------------------------------------------------------------------*/
129/*---------------------------------------------------------------------------*/
130
131} // namespace Arcane
132
133/*---------------------------------------------------------------------------*/
134/*---------------------------------------------------------------------------*/
135
136#endif
Implementation of a single-threaded barrier.
void init(Integer nb_thread) override
Initializes the barrier for nb_thread.
void destroy() override
Destroys the barrier.
void wait() override
Blocks and waits until all threads call this method.
Implementation of threads in single-threaded mode.
bool isMultiThread() const override
True if the implementation supports multiple threads.
Thread-safe implementation of a reference counter.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.