ATLAS Offline Software
ArenaHeader.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // $Id: ArenaHeader.icc 470529 2011-11-24 23:54:22Z ssnyder $
6 /**
7  * @file AthAllocators/ArenaHeader.icc
8  * @author scott snyder
9  * @date May 2007
10  * @brief Proxy for a group of Arenas.
11  * Inline implementations.
12  */
13 
14 
15 namespace SG {
16 
17 
18 /**
19  * @brief Translate an integer index to an Allocator pointer.
20  * @param i The index to look up.
21  *
22  * If the index isn't valid, an assertion will be tripped.
23  */
24 inline
25 LockedAllocator ArenaHeader::allocator (size_t i)
26 {
27  if (m_arena.get()) {
28  return m_arena->allocator (i);
29  }
30  return m_defaultArena.allocator (i);
31 }
32 
33 
34 /**
35  * @brief Translate an integer index to an Allocator pointer.
36  * @param ctx Use the Arena associated with this event context.
37  * @param i The index to look up.
38  *
39  * If the index isn't valid, an assertion will be tripped.
40  */
41 inline
42 LockedAllocator ArenaHeader::allocator (const EventContext& ctx, size_t i)
43 {
44  ArenaBase* a = nullptr;
45  size_t slot = ctx.slot();
46  {
47  std::lock_guard<std::mutex> lock (m_mutex);
48  if (slot < m_slots.size()) {
49  a = m_slots[slot];
50  }
51  }
52  // Need to release the header lock before creating the allocator;
53  // otherwise we can deadlock (ATR-28749).
54  if (a) {
55  return a->allocator (i);
56  }
57  return allocator (i);
58 }
59 
60 
61 } // namespace SG