+bool RequestContext::doSetContextData(
+ const std::string& val,
+ std::unique_ptr<RequestData>& data,
+ bool strict) {
+ auto ulock = state_.ulock();
+
+ bool conflict = false;
+ auto it = ulock->requestData_.find(val);
+ if (it != ulock->requestData_.end()) {
+ if (strict) {
+ return false;
+ } else {
+ LOG_FIRST_N(WARNING, 1) << "Calling RequestContext::setContextData for "
+ << val << " but it is already set";
+ conflict = true;
+ }
+ }
+
+ auto wlock = ulock.moveFromUpgradeToWrite();
+ if (conflict) {
+ if (it->second) {
+ if (it->second->hasCallback()) {
+ wlock->callbackData_.erase(it->second.get());
+ }
+ it->second.reset(nullptr);
+ }
+ return true;
+ }
+
+ if (data && data->hasCallback()) {
+ wlock->callbackData_.insert(data.get());
+ }
+ wlock->requestData_[val] = std::move(data);
+
+ return true;
+}
+