proxygen
folly::symbolizer::SignalSafeElfCache Class Reference

#include <ElfCache.h>

Inheritance diagram for folly::symbolizer::SignalSafeElfCache:
folly::symbolizer::ElfCacheBase

Classes

class  Path
 

Public Member Functions

 SignalSafeElfCache (size_t capacity)
 
std::shared_ptr< ElfFilegetFile (StringPiece path) override
 
- Public Member Functions inherited from folly::symbolizer::ElfCacheBase
virtual ~ElfCacheBase ()
 

Private Attributes

Path scratchpad_
 
boost::container::flat_map< Path, int > map_
 
std::vector< std::shared_ptr< ElfFile > > slots_
 

Detailed Description

Cache ELF files. Async-signal-safe: does memory allocation upfront.

Will not grow; once the capacity is reached, lookups for files that aren't already in the cache will fail (return nullptr).

Not MT-safe. May not be used concurrently from multiple threads.

NOTE that async-signal-safety is preserved only as long as the SignalSafeElfCache object exists; after the SignalSafeElfCache object is destroyed, destroying returned shared_ptr<ElfFile> objects may cause ElfFile objects to be destroyed, and that's not async-signal-safe.

Definition at line 63 of file ElfCache.h.

Constructor & Destructor Documentation

folly::symbolizer::SignalSafeElfCache::SignalSafeElfCache ( size_t  capacity)
explicit

Definition at line 53 of file ElfCache.cpp.

References i, map_, and slots_.

53  {
54  map_.reserve(capacity);
55  slots_.reserve(capacity);
56 
57  // Preallocate
58  for (size_t i = 0; i < capacity; ++i) {
59  slots_.push_back(std::make_shared<ElfFile>());
60  }
61 }
boost::container::flat_map< Path, int > map_
Definition: ElfCache.h:109
std::vector< std::shared_ptr< ElfFile > > slots_
Definition: ElfCache.h:110

Member Function Documentation

std::shared_ptr< ElfFile > folly::symbolizer::SignalSafeElfCache::getFile ( StringPiece  path)
overridevirtual

Implements folly::symbolizer::ElfCacheBase.

Definition at line 63 of file ElfCache.cpp.

References folly::symbolizer::SignalSafeElfCache::Path::assign(), folly::symbolizer::SignalSafeElfCache::Path::data(), f, folly::symbolizer::SignalSafeElfCache::Path::kMaxSize, folly::symbolizer::ElfFile::kSuccess, map_, scratchpad_, folly::Range< Iter >::size(), and slots_.

63  {
64  if (p.size() > Path::kMaxSize) {
65  return nullptr;
66  }
67 
69  auto pos = map_.find(scratchpad_);
70  if (pos != map_.end()) {
71  return slots_[pos->second];
72  }
73 
74  size_t n = map_.size();
75  if (n >= slots_.size()) {
76  DCHECK_EQ(map_.size(), slots_.size());
77  return nullptr;
78  }
79 
80  auto& f = slots_[n];
81 
82  const char* msg = "";
83  int r = f->openAndFollow(scratchpad_.data(), true, &msg);
84  if (r != ElfFile::kSuccess) {
85  return nullptr;
86  }
87 
88  map_[scratchpad_] = n;
89  return f;
90 }
auto f
boost::container::flat_map< Path, int > map_
Definition: ElfCache.h:109
std::vector< std::shared_ptr< ElfFile > > slots_
Definition: ElfCache.h:110

Member Data Documentation

boost::container::flat_map<Path, int> folly::symbolizer::SignalSafeElfCache::map_
private

Definition at line 109 of file ElfCache.h.

Referenced by getFile(), and SignalSafeElfCache().

Path folly::symbolizer::SignalSafeElfCache::scratchpad_
private

Definition at line 108 of file ElfCache.h.

Referenced by getFile().

std::vector<std::shared_ptr<ElfFile> > folly::symbolizer::SignalSafeElfCache::slots_
private

Definition at line 110 of file ElfCache.h.

Referenced by getFile(), and SignalSafeElfCache().


The documentation for this class was generated from the following files: