Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
ThreadPrivate.cc
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.cc (C) 2000-2018 */
9/* */
10/* Classe permettant de conserver une valeur spécifique par thread. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arccore/concurrency/ThreadPrivate.h"
15
16/*---------------------------------------------------------------------------*/
17/*---------------------------------------------------------------------------*/
18
19namespace Arccore
20{
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25ThreadPrivateStorage::
26ThreadPrivateStorage()
27: m_storage(nullptr)
28{
29}
30
31ThreadPrivateStorage::
32~ThreadPrivateStorage()
33{
34}
35
36void ThreadPrivateStorage::
37initialize()
38{
39 if (!m_storage){
40 m_storage = new GlibPrivate();
41 m_storage->create();
42 }
43}
44
45void* ThreadPrivateStorage::
46getValue()
47{
48 return m_storage->getValue();
49}
50
51
52void ThreadPrivateStorage::
53setValue(void* v)
54{
55 m_storage->setValue(v);
56}
57
58/*---------------------------------------------------------------------------*/
59/*---------------------------------------------------------------------------*/
60
61void* ThreadPrivateBase::
62item()
63{
64 void* ptr = m_key->getValue();
65 if (ptr){
66 return ptr;
67 }
68 void* new_ptr = nullptr;
69 {
70 GlibMutex::Lock x(m_mutex);
71 new_ptr = m_create_functor->createInstance();
72 }
73 m_key->setValue(new_ptr);
74 return new_ptr;
75}
76
77/*---------------------------------------------------------------------------*/
78/*---------------------------------------------------------------------------*/
79
80} // End namespace Arccore
81
82/*---------------------------------------------------------------------------*/
83/*---------------------------------------------------------------------------*/
Encapsule un GPrivate de la glib.
Definition GlibAdapter.h:67
Espace de nom de Arccore.
Definition ArcaneTypes.h:24