File indexing completed on 2024-11-15 09:01:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef ABSL_STRINGS_INTERNAL_CORDZ_UPDATE_SCOPE_H_
0016 #define ABSL_STRINGS_INTERNAL_CORDZ_UPDATE_SCOPE_H_
0017
0018 #include "absl/base/config.h"
0019 #include "absl/base/optimization.h"
0020 #include "absl/base/thread_annotations.h"
0021 #include "absl/strings/internal/cord_internal.h"
0022 #include "absl/strings/internal/cordz_info.h"
0023 #include "absl/strings/internal/cordz_update_tracker.h"
0024
0025 namespace absl {
0026 ABSL_NAMESPACE_BEGIN
0027 namespace cord_internal {
0028
0029
0030
0031
0032
0033 class ABSL_SCOPED_LOCKABLE CordzUpdateScope {
0034 public:
0035 CordzUpdateScope(CordzInfo* info, CordzUpdateTracker::MethodIdentifier method)
0036 ABSL_EXCLUSIVE_LOCK_FUNCTION(info)
0037 : info_(info) {
0038 if (ABSL_PREDICT_FALSE(info_)) {
0039 info->Lock(method);
0040 }
0041 }
0042
0043
0044 CordzUpdateScope(CordzUpdateScope&& rhs) = delete;
0045 CordzUpdateScope(const CordzUpdateScope&) = delete;
0046 CordzUpdateScope& operator=(CordzUpdateScope&& rhs) = delete;
0047 CordzUpdateScope& operator=(const CordzUpdateScope&) = delete;
0048
0049 ~CordzUpdateScope() ABSL_UNLOCK_FUNCTION() {
0050 if (ABSL_PREDICT_FALSE(info_)) {
0051 info_->Unlock();
0052 }
0053 }
0054
0055 void SetCordRep(CordRep* rep) const {
0056 if (ABSL_PREDICT_FALSE(info_)) {
0057 info_->SetCordRep(rep);
0058 }
0059 }
0060
0061 CordzInfo* info() const { return info_; }
0062
0063 private:
0064 CordzInfo* info_;
0065 };
0066
0067 }
0068 ABSL_NAMESPACE_END
0069 }
0070
0071 #endif