Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
ThreadPrivate.cc
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/* ThreadPrivate.cc (C) 2000-2025 */
9/* */
10/* Class allowing the storage of a specific value per thread. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arccore/concurrency/ThreadPrivate.h"
15
16/*---------------------------------------------------------------------------*/
17/*---------------------------------------------------------------------------*/
18
19namespace Arcane
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
51void ThreadPrivateStorage::
52setValue(void* v)
53{
54 m_storage->setValue(v);
55}
56
57/*---------------------------------------------------------------------------*/
58/*---------------------------------------------------------------------------*/
59
60void* ThreadPrivateBase::
61item()
62{
63 void* ptr = m_key->getValue();
64 if (ptr) {
65 return ptr;
66 }
67 void* new_ptr = nullptr;
68 {
69 GlibMutex::Lock x(m_mutex);
70 new_ptr = m_create_functor->createInstance();
71 }
72 m_key->setValue(new_ptr);
73 return new_ptr;
74}
75
76/*---------------------------------------------------------------------------*/
77/*---------------------------------------------------------------------------*/
78
79} // namespace Arcane
80
81/*---------------------------------------------------------------------------*/
82/*---------------------------------------------------------------------------*/
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --