proxygen
folly::RequestToken Class Reference

#include <Request.h>

Public Member Functions

 RequestToken (const std::string &str)
 
bool operator== (const RequestToken &other) const
 
std::string getDebugString () const
 

Static Private Member Functions

static Synchronized< F14FastMap< std::string, uint32_t > > & getCache ()
 

Private Attributes

uint32_t token_
 

Friends

struct std::hash< folly::RequestToken >
 

Detailed Description

Definition at line 33 of file Request.h.

Constructor & Destructor Documentation

folly::RequestToken::RequestToken ( const std::string str)
explicit

Definition at line 27 of file Request.cpp.

References c, getCache(), token_, and uint32_t.

Referenced by folly::RequestContext::clearContextData(), folly::RequestContext::doSetContextData(), folly::RequestContext::getContextData(), folly::RequestContext::hasContextData(), folly::RequestContext::overwriteContextData(), folly::RequestContext::setContextData(), and folly::RequestContext::setContextDataIfAbsent().

27  {
28  auto& cache = getCache();
29  {
30  auto c = cache.rlock();
31  auto res = c->find(str);
32  if (res != c->end()) {
33  token_ = res->second;
34  return;
35  }
36  }
37  auto c = cache.wlock();
38  auto res = c->find(str);
39  if (res != c->end()) {
40  token_ = res->second;
41  return;
42  }
43  static uint32_t nextToken{1};
44 
45  token_ = nextToken++;
46  (*c)[str] = token_;
47 }
uint32_t token_
Definition: Request.h:49
static Synchronized< F14FastMap< std::string, uint32_t > > & getCache()
Definition: Request.cpp:60
char c

Member Function Documentation

Synchronized< F14FastMap< std::string, uint32_t > > & folly::RequestToken::getCache ( )
staticprivate

Definition at line 60 of file Request.cpp.

Referenced by getDebugString(), and RequestToken().

60  {
61  static Indestructible<Synchronized<F14FastMap<std::string, uint32_t>>> cache;
62  return *cache;
63 }
std::string folly::RequestToken::getDebugString ( ) const

Definition at line 49 of file Request.cpp.

References c, getCache(), and token_.

Referenced by folly::RequestContext::doSetContextData(), and operator==().

49  {
50  auto& cache = getCache();
51  auto c = cache.rlock();
52  for (auto& v : *c) {
53  if (v.second == token_) {
54  return v.first;
55  }
56  }
57  throw std::logic_error("Could not find debug string in RequestToken");
58 }
uint32_t token_
Definition: Request.h:49
static Synchronized< F14FastMap< std::string, uint32_t > > & getCache()
Definition: Request.cpp:60
char c
bool folly::RequestToken::operator== ( const RequestToken other) const
inline

Definition at line 37 of file Request.h.

References getDebugString(), string, and token_.

37  {
38  return token_ == other.token_;
39  }
uint32_t token_
Definition: Request.h:49

Friends And Related Function Documentation

friend struct std::hash< folly::RequestToken >
friend

Definition at line 44 of file Request.h.

Member Data Documentation

uint32_t folly::RequestToken::token_
private

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