Skip to content

Commit 806ab86

Browse files
committed
Change TSDbgCtl from a struct to a class.
TSDbgCtlCreate() and TSDbgCtlDestroy() are eliminated. tsapi::c_support::TSDbgCtlUniqPtr is eliminated.
1 parent 0d0fe87 commit 806ab86

File tree

11 files changed

+44
-108
lines changed

11 files changed

+44
-108
lines changed

example/plugins/c-api/cache_scan/cache_scan.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
#define PLUGIN_NAME "cache_scan"
3838

39-
static const TSDbgCtl *const dbg_ctl = TSDbgCtlCreate(PLUGIN_NAME);
39+
static TSDbgCtl dbg_ctl{PLUGIN_NAME};
4040

4141
static TSCont global_contp;
4242

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323

2424
#pragma once
2525

26-
#include <ts/ts.h>
26+
class DiagsConfigState;
2727

28-
// For use with TSDbg().
28+
// For use with TSDbg() or Dbg().
2929
//
3030
class DbgCtl
3131
{
@@ -37,26 +37,45 @@ class DbgCtl
3737

3838
~DbgCtl() { _rm_reference(); }
3939

40-
TSDbgCtl const *
41-
ptr() const
40+
bool
41+
on() const
4242
{
43-
return _ptr;
43+
return _ptr->on != 0;
4444
}
4545

46-
// Call this when the compiled regex to enable tags may have changed.
46+
char const *
47+
tag() const
48+
{
49+
return _ptr->tag;
50+
}
51+
52+
static bool
53+
global_on()
54+
{
55+
return _global_on;
56+
}
57+
58+
// Call this when the compiled regex to enable tags may have changed. Should not be called in plugins.
4759
//
4860
static void update();
4961

62+
// For use in Dbg() macro only.
63+
//
64+
static void print(const char *tag, const char *format_str, ...);
65+
5066
private:
51-
TSDbgCtl const *const _ptr;
67+
struct _Data {
68+
char volatile on; // Flag
69+
char const *tag;
70+
};
5271

53-
static const TSDbgCtl *_new_reference(char const *tag);
72+
Data const *const _ptr;
5473

55-
static void _rm_reference();
74+
static const Data *_new_reference(char const *tag);
5675

57-
class _RegistryAccessor;
76+
static void _rm_reference();
5877

59-
friend TSDbgCtl const *tsapi::c::TSDbgCtlCreate(char const *tag);
78+
static bool _global_on;
6079

61-
friend void tsapi::c::TSDbgCtlDestroy(TSDbgCtl const *dbg_ctl);
80+
class _RegistryAccessor;
6281
};

include/ts/apidefs.h.in

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,11 +1114,6 @@ char const TS_VERSION_STRING[] = "@TS_VERSION_STRING@";
11141114
TSIOBufferWaterMark buffer_water_mark;
11151115
};
11161116

1117-
struct TSDbgCtl {
1118-
char volatile on; // Flag
1119-
char const *tag;
1120-
};
1121-
11221117
/* --------------------------------------------------------------------------
11231118
URL schemes */
11241119
extern const char *TS_URL_SCHEME_FILE;

include/ts/ts.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"License"); you may not use this file except in compliance
1313
with the License. You may obtain a copy of the License at
1414
15-
http://www.apache.org/licenses/LICENSE-2.0
15+
http://www.apache.org/licenses/LICENSE-2.0
1616
1717
Unless required by applicable law or agreed to in writing, software
1818
distributed under the License is distributed on an "AS IS" BASIS,
@@ -25,7 +25,7 @@
2525
Developers, when adding a new element to an enum, append it. DO NOT
2626
insert it. Otherwise, binary compatibility of plugins will be broken!
2727
28-
*/
28+
*/
2929

3030
#pragma once
3131

include/tscpp/api/Cleanup.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,6 @@ struct TSIOBufferReaderDeleter {
100100
};
101101
using TSIOBufferReaderUniqPtr = std::unique_ptr<std::remove_pointer_t<TSIOBufferReader>, TSIOBufferReaderDeleter>;
102102

103-
// Deleter and unique pointer for TSDbgCtl const.
104-
//
105-
struct TSDbgCtlDeleter {
106-
void
107-
operator()(TSDbgCtl const *ptr)
108-
{
109-
TSDbgCtlDestroy(ptr);
110-
}
111-
};
112-
using TSDbgCtlUniqPtr = std::unique_ptr<TSDbgCtl const, TSDbgCtlDeleter>;
113-
114103
class TxnAuxDataMgrBase
115104
{
116105
protected:

plugins/experimental/webp_transform/ImageTransform.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ namespace
4949
{
5050
GlobalPlugin *plugin;
5151

52-
auto webp_dbg_ctl = TSDbgCtlCreate(TAG);
52+
TSDbgCtl webp_dbg_ctl{TAG};
5353

5454
enum class ImageEncoding { webp, jpeg, png, unknown };
5555

src/traffic_server/InkAPI.cc

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -7435,50 +7435,6 @@ tsapi::c::TSStatFindName(const char *name, int *idp)
74357435
}
74367436
}
74377437

7438-
/************************** Tracing API ****************************/
7439-
// returns 1 or 0 to indicate whether TS is being run with a debug tag.
7440-
int
7441-
tsapi::c::TSIsDebugTagSet(const char *t)
7442-
{
7443-
return diags()->on_for_TSDebug(t);
7444-
}
7445-
7446-
void
7447-
tsapi::c::TSDebugSpecific(int debug_flag, const char *tag, const char *format_str, ...)
7448-
{
7449-
if ((debug_flag && diags()->on_for_TSDebug()) || diags()->on_for_TSDebug(tag)) {
7450-
va_list ap;
7451-
7452-
va_start(ap, format_str);
7453-
diags()->print_va(tag, DL_Diag, nullptr, format_str, ap);
7454-
va_end(ap);
7455-
}
7456-
}
7457-
7458-
// Plugins would use TSDebug just as the TS internal uses Debug
7459-
// e.g. TSDebug("plugin-cool", "Snoopy is a cool guy even after %d requests.", num_reqs);
7460-
void
7461-
tsapi::c::TSDebug(const char *tag, const char *format_str, ...)
7462-
{
7463-
if (diags()->on_for_TSDebug() && diags()->tag_activated(tag)) {
7464-
va_list ap;
7465-
7466-
va_start(ap, format_str);
7467-
diags()->print_va(tag, DL_Diag, nullptr, format_str, ap);
7468-
va_end(ap);
7469-
}
7470-
}
7471-
7472-
void
7473-
tsapi::c::_TSDbg(const char *tag, const char *format_str, ...)
7474-
{
7475-
va_list ap;
7476-
7477-
va_start(ap, format_str);
7478-
diags()->print_va(tag, DL_Diag, nullptr, format_str, ap);
7479-
va_end(ap);
7480-
}
7481-
74827438
/************************** Logging API ****************************/
74837439

74847440
TSReturnCode
@@ -10023,23 +9979,6 @@ tsapi::c::TSHttpTxnPostBufferReaderGet(TSHttpTxn txnp)
100239979
return (TSIOBufferReader)sm->get_postbuf_clone_reader();
100249980
}
100259981

10026-
tsapi::c::TSDbgCtl const *
10027-
tsapi::c::TSDbgCtlCreate(char const *tag)
10028-
{
10029-
sdk_assert(tag != nullptr);
10030-
sdk_assert(*tag != '\0');
10031-
10032-
return DbgCtl::_new_reference(tag);
10033-
}
10034-
10035-
void
10036-
tsapi::c::TSDbgCtlDestroy(TSDbgCtl const *dbg_ctl)
10037-
{
10038-
sdk_assert(dbg_ctl != nullptr);
10039-
10040-
DbgCtl::_rm_reference();
10041-
}
10042-
100439982
namespace rpc
100449983
{
100459984
extern std::mutex g_rpcHandlingMutex;

src/tscore/DbgCtl.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ class DbgCtl::_RegistryAccessor
3939
private:
4040
struct TagCmp {
4141
bool
42-
operator()(TSDbgCtl const &a, TSDbgCtl const &b) const
42+
operator()(Data const &a, Data const &b) const
4343
{
4444
return std::strcmp(a.tag, b.tag) < 0;
4545
}
4646
};
4747

4848
public:
49-
using Set = std::set<TSDbgCtl, TagCmp>;
49+
using Set = std::set<Data, TagCmp>;
5050

5151
class Registry
5252
{
@@ -121,12 +121,12 @@ class DbgCtl::_RegistryAccessor
121121
inline static std::atomic<Registry *> _registry_instance{nullptr};
122122
};
123123

124-
TSDbgCtl const *
124+
Data const *
125125
DbgCtl::_new_reference(char const *tag)
126126
{
127127
ink_assert(tag != nullptr);
128128

129-
TSDbgCtl ctl;
129+
Data ctl;
130130

131131
ctl.tag = tag;
132132

@@ -192,6 +192,6 @@ DbgCtl::update()
192192
auto &d{ra.data()};
193193

194194
for (auto &i : d.set) {
195-
const_cast<char volatile &>(i.on) = diags()->tag_activated(i.tag, DiagsTagType_Debug);
195+
const_cast<bool volatile &>(i.on) = diags()->tag_activated(i.tag, DiagsTagType_Debug);
196196
}
197197
}

tests/gold_tests/pluginTest/TSVConnFd/TSVConnFd.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include <tscpp/api/Cleanup.h>
3333

3434
using atscppapi::TSContUniqPtr;
35-
using atscppapi::TSDbgCtlUniqPtr;
3635

3736
/*
3837
Plugin for testing TSVConnFdCreate().
@@ -446,8 +445,7 @@ Send_to_vconn::_cont_func(TSCont cont, TSEvent event, void *edata)
446445
return 0;
447446
}
448447

449-
TSDbgCtlUniqPtr dbg_ctl_guard{TSDbgCtlCreate(PIName)};
450-
TSDbgCtl const *const dbg_ctl{dbg_ctl_guard.get()};
448+
TSDbgCtl dbg_ctl{PIName};
451449

452450
// Delete file whose path is specified in the constructor when the instance is destroyed.
453451
//

tests/gold_tests/pluginTest/polite_hook_wait/polite_hook_wait.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ namespace
4040
{
4141
char PIName[] = PINAME;
4242

43-
atscppapi::TSDbgCtlUniqPtr dbg_ctl_guard{TSDbgCtlCreate(PIName)};
44-
TSDbgCtl const *const dbg_ctl{dbg_ctl_guard.get()};
43+
TSDbgCtl dbg_ctl{PIName};
4544

4645
enum Test_step { BEGIN, GLOBAL_CONT_READ_HDRS, THREAD, TXN_CONT_READ_HDRS, END };
4746

0 commit comments

Comments
 (0)