20 #include <glog/logging.h> 30 auto c = cache.rlock();
31 auto res =
c->find(str);
32 if (res !=
c->end()) {
37 auto c = cache.wlock();
38 auto res =
c->find(str);
39 if (res !=
c->end()) {
51 auto c = cache.rlock();
57 throw std::logic_error(
"Could not find debug string in RequestToken");
67 auto keepAliveCounter =
70 DCHECK(keepAliveCounter > 0);
71 if (keepAliveCounter == 1) {
80 auto keepAliveCounter =
82 DCHECK(keepAliveCounter >= 0);
89 std::unique_ptr<RequestData>&
data,
91 auto ulock = state_.ulock();
93 bool conflict =
false;
94 auto it =
ulock->requestData_.find(val);
95 if (it !=
ulock->requestData_.end()) {
96 if (behaviour == DoSetBehaviour::SET_IF_ABSENT) {
98 }
else if (behaviour == DoSetBehaviour::SET) {
100 <<
"Calling RequestContext::setContextData for " 109 if (it->second->hasCallback()) {
110 it->second->onUnset();
111 wlock->callbackData_.erase(it->second.get());
113 it->second.reset(
nullptr);
115 if (behaviour == DoSetBehaviour::SET) {
120 if (data && data->hasCallback()) {
121 wlock->callbackData_.insert(data.get());
131 std::unique_ptr<RequestData>
data) {
132 doSetContextData(val, data, DoSetBehaviour::SET);
137 std::unique_ptr<RequestData>
data) {
138 return doSetContextData(val, data, DoSetBehaviour::SET_IF_ABSENT);
143 std::unique_ptr<RequestData>
data) {
144 doSetContextData(val, data, DoSetBehaviour::OVERWRITE);
148 return state_.rlock()->requestData_.count(val);
163 auto rlock = state_.rlock();
164 for (
const auto&
data :
rlock->callbackData_) {
170 auto rlock = state_.rlock();
171 for (
const auto&
data :
rlock->callbackData_) {
181 auto ulock = state_.ulock();
182 auto it =
ulock->requestData_.find(val);
183 if (it ==
ulock->requestData_.end()) {
188 if (it->second && it->second->hasCallback()) {
189 it->second->onUnset();
190 wlock->callbackData_.erase(it->second.get());
194 wlock->requestData_.erase(it);
201 template <
typename TData,
typename TExec>
202 void exec_set_difference(
const TData&
data,
const TData& other, TExec&& exec) {
203 auto diter = data.begin();
204 auto dend = data.end();
205 auto oiter = other.begin();
206 auto oend = other.end();
207 while (diter != dend) {
214 }
else if (*diter == *oiter) {
217 }
else if (*diter < *oiter) {
228 std::shared_ptr<RequestContext> newCtx) {
229 auto& staticCtx = getStaticContext();
230 if (newCtx == staticCtx) {
235 folly, request_context_switch_before, staticCtx.get(), newCtx.get());
237 auto curCtx = staticCtx;
238 if (newCtx && curCtx) {
242 auto& newLock = std::get<0>(ret);
243 auto& curLock = std::get<1>(ret);
244 auto& newData = newLock->callbackData_;
245 auto& curData = curLock->callbackData_;
268 std::shared_ptr<RequestContext>
270 auto&
parent = getStaticContext();
271 auto child = std::make_shared<RequestContext>();
275 auto& parentLock = std::get<0>(ret);
276 auto& childLock = std::get<1>(ret);
277 childLock->callbackData_ = parentLock->callbackData_;
278 childLock->requestData_.reserve(parentLock->requestData_.size());
279 for (
const auto& entry : parentLock->requestData_) {
280 childLock->requestData_.insert(std::make_pair(
291 auto&
context = getStaticContext();
294 return std::addressof(defaultContext);
static std::shared_ptr< RequestContext > setContext(std::shared_ptr< RequestContext > ctx)
#define FOLLY_SDT(provider, name,...)
auto wlock(Synchronized< D, M > &synchronized, Args &&...args)
std::atomic< int > keepAliveCounter_
void setContextData(const RequestToken &val, std::unique_ptr< RequestData > data)
std::string getDebugString() const
const Map::mapped_type & get_ref_default(const Map &map, const Key &key, const typename Map::mapped_type &dflt)
static std::shared_ptr< RequestContext > & getStaticContext()
bool doSetContextData(const RequestToken &val, std::unique_ptr< RequestData > &data, DoSetBehaviour behaviour)
constexpr detail::Map< Move > move
void operator()(RequestData *ptr)
—— Concurrent Priority Queue Implementation ——
RequestToken(const std::string &str)
void overwriteContextData(const RequestToken &val, std::unique_ptr< RequestData > data)
constexpr T const & as_const(T &t) noexcept
auto rlock(const Synchronized< Data, Mutex > &synchronized, Args &&...args)
std::tuple< detail::LockedPtrType< Sync1 >, detail::LockedPtrType< Sync2 > > acquireLocked(Sync1 &l1, Sync2 &l2)
static SharedPtr constructPtr(RequestData *ptr)
constexpr auto data(C &c) -> decltype(c.data())
void clearContextData(const RequestToken &val)
static std::shared_ptr< RequestContext > setShallowCopyContext()
std::unique_ptr< RequestData, DestructPtr > SharedPtr
bool setContextDataIfAbsent(const RequestToken &val, std::unique_ptr< RequestData > data)
static Synchronized< F14FastMap< std::string, uint32_t > > & getCache()
auto ulock(Synchronized< D, M > &synchronized, Args &&...args)
folly::Function< void()> child
void swap(SwapTrackingAlloc< T > &, SwapTrackingAlloc< T > &)
bool hasContextData(const RequestToken &val) const
RequestData * getContextData(const RequestToken &val)
PUSHMI_INLINE_VAR constexpr detail::get_fn< T > get
static RequestContext * get()
folly::Function< void()> parent