Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
ThreadPrivate.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 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/* ThreadPrivate.h (C) 2000-2018 */
9/* */
10/* Classe permettant de conserver une valeur spécifique par thread. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_CONCURRENCY_THREADPRIVATE_H
13#define ARCCORE_CONCURRENCY_THREADPRIVATE_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arccore/base/ArccoreGlobal.h"
18
19#include "arccore/concurrency/GlibAdapter.h"
20
21#include <vector>
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26namespace Arccore
27{
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
39class ARCCORE_CONCURRENCY_EXPORT ThreadPrivateStorage
40{
41 public:
42
43 ARCCORE_DEPRECATED_REASON("Y2022; This class is deprecated. Use 'thread_local' specifier.")
46
47 public:
48
57 void initialize();
58 void* getValue();
59 void setValue(void* v);
60 private:
61 GlibPrivate* m_storage;
62};
63
64/*---------------------------------------------------------------------------*/
65/*---------------------------------------------------------------------------*/
71class ARCCORE_CONCURRENCY_EXPORT ThreadPrivateBase
72{
73 public:
75 {
76 public:
77 virtual ~ICreateFunctor(){}
78 virtual void* createInstance() =0;
79 };
80
81 public:
82
83 ARCCORE_DEPRECATED_REASON("Y2022; This class is deprecated. Use 'thread_local' specifier.")
85 : m_key(key), m_create_functor(create_functor)
86 {
87 }
88
90 {
91 }
92
93 public:
94
105 void* item();
106
107 private:
108
109 ThreadPrivateStorage* m_key;
110 GlibMutex m_mutex;
111 ICreateFunctor* m_create_functor;
112};
113
114/*---------------------------------------------------------------------------*/
115/*---------------------------------------------------------------------------*/
133template<typename T>
136{
137 public:
138
139 ARCCORE_DEPRECATED_REASON("Y2022; This class is deprecated. Use 'thread_local' specifier.")
141 : m_storage(key,this)
142 {
143 }
144
146 {
147 for( T* item : m_allocated_items )
148 delete item;
149 }
150
151 public:
153 T* item()
154 {
155 return (T*)(m_storage.item());
156 }
157
158 private:
159
160 void* createInstance() override
161 {
162 T* new_ptr = new T();
163 new_ptr->build();
164 m_allocated_items.push_back(new_ptr);
165 return new_ptr;
166 }
167
168 private:
169 std::vector<T*> m_allocated_items;
170 ThreadPrivateBase m_storage;
171};
172
173/*---------------------------------------------------------------------------*/
174/*---------------------------------------------------------------------------*/
175
176} // End namespace Arccore
177
178/*---------------------------------------------------------------------------*/
179/*---------------------------------------------------------------------------*/
180
181#endif
Encapsule un GPrivate de la glib.
Definition GlibAdapter.h:67
Classe de base permettant de conserveur une instance d'un objet par thread.
void * item()
Récupère l'instance spécifique au thread courant.
Conteneur pour les valeurs privées par thread.
Classe permettant une instance d'un type par thread.
T * item()
Instance spécifique au thread courant.
Espace de nom de Arccore.
Definition ArcaneTypes.h:24