ATLAS Offline Software
ArenaBase.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // $Id$
6 /**
7  * @file AthAllocators/ArenaBase.icc
8  * @author scott snyder
9  * @date Mar 2017
10  * @brief Part of @c Arena dealing with the list of allocators.
11  * Broken out from @c Arena to avoid a dependency loop
12  * with @c ArenaHeader.
13  * Inline implementations.
14  */
15 
16 
17 namespace SG {
18 
19 
20 /**
21  * @brief Translate an integer index to an Allocator pointer.
22  * @param i The index to look up.
23  *
24  * If the index isn't valid, an assertion will be tripped.
25  */
26 inline
27 LockedAllocator ArenaBase::allocator (size_t i)
28 {
29  ArenaAllocatorBase* allocbase = nullptr;
30  std::mutex* m = nullptr;
31  {
32  lock_t l (m_mutex);
33  if (i >= m_allocs.size() || (allocbase = m_allocs[i].m_alloc.get()) == nullptr) {
34  allocbase = makeAllocator(i);
35  }
36 
37  m = m_allocs[i].m_mutex.get();
38 
39  // Need to give up m_mutex before waiting on m; otherwise we can deadlock.
40  }
41 
42  return LockedAllocator (allocbase, *m);
43 }
44 
45 
46 } // namespace SG
47 
48 
49 
50