This is an automated email from the ASF dual-hosted git repository.
wkaras pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new f738aea0ed Allow DbgCtl tag to be set after instance construction.
(#10375)
f738aea0ed is described below
commit f738aea0ed00b48c5a1e9f59604e3f47eb3cef2f
Author: Walt Karas <[email protected]>
AuthorDate: Wed Sep 6 10:01:10 2023 -0400
Allow DbgCtl tag to be set after instance construction. (#10375)
---
include/ts/DbgCtl.h | 34 ++++++++++++++++++++++++++++------
src/tscore/DbgCtl.cc | 20 ++++++++++++++++++++
2 files changed, 48 insertions(+), 6 deletions(-)
diff --git a/include/ts/DbgCtl.h b/include/ts/DbgCtl.h
index 1bd08988e9..1aac864461 100644
--- a/include/ts/DbgCtl.h
+++ b/include/ts/DbgCtl.h
@@ -38,7 +38,31 @@ public:
//
DbgCtl(char const *tag) : _ptr{_new_reference(tag)} {}
- ~DbgCtl() { _rm_reference(); }
+ // As instance with no tag will always be off.
+ //
+ DbgCtl() : _ptr{&_No_tag_dummy} {}
+
+ ~DbgCtl()
+ {
+ if (_ptr != &_No_tag_dummy) {
+ _rm_reference();
+ }
+ }
+
+ // No copying. Only moving from a tagged to a tagless instance allowed.
+ //
+ DbgCtl(DbgCtl const &) = delete;
+ DbgCtl &operator=(DbgCtl const &) = delete;
+ DbgCtl(DbgCtl &&);
+ DbgCtl &operator=(DbgCtl &&);
+
+ // A shorthand.
+ //
+ void
+ set(char const *tag)
+ {
+ *this = DbgCtl{tag};
+ }
bool
tag_on() const
@@ -90,14 +114,12 @@ public:
static void print(char const *tag, char const *file, char const *function,
int line, char const *fmt_str, ...)
TS_PRINTFLIKE(5, 6);
- // No copying/moving.
- DbgCtl(DbgCtl const &) = delete;
- DbgCtl &operator=(DbgCtl const &) = delete;
-
private:
using _TagData = std::pair<char const *const, bool>;
- _TagData const *const _ptr;
+ _TagData const *_ptr;
+
+ static const _TagData _No_tag_dummy;
static const _TagData *_new_reference(char const *tag);
diff --git a/src/tscore/DbgCtl.cc b/src/tscore/DbgCtl.cc
index 8ae652eb20..0c5cad85fd 100644
--- a/src/tscore/DbgCtl.cc
+++ b/src/tscore/DbgCtl.cc
@@ -30,6 +30,24 @@
#include <tscore/ink_assert.h>
#include <tscore/Diags.h>
+DbgCtl::DbgCtl(DbgCtl &&src)
+{
+ ink_release_assert(src._ptr != &_No_tag_dummy);
+
+ _ptr = src._ptr;
+ src._ptr = &_No_tag_dummy;
+}
+
+DbgCtl &
+DbgCtl::operator=(DbgCtl &&src)
+{
+ ink_release_assert(&_No_tag_dummy == _ptr);
+
+ new (this) DbgCtl{std::move(src)};
+
+ return *this;
+}
+
// The resistry of fast debug controllers has a ugly implementation to handle
the whole-program initialization
// and destruction order problem with C++.
//
@@ -205,3 +223,5 @@ DbgCtl::_override_global_on()
{
return diags()->get_override();
}
+
+DbgCtl::_TagData const DbgCtl::_No_tag_dummy{nullptr, false};