Skip to content

Commit

Permalink
[NFC][asan] Cleanup AsanThreadIdAndName ctor/init (#111923)
Browse files Browse the repository at this point in the history
Co-authored-by: YunQiang Su <yunqiang@isrc.iscas.ac.cn>
  • Loading branch information
vitalybuka and wzssyqa authored Oct 11, 2024
1 parent 36639af commit e556f07
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
26 changes: 11 additions & 15 deletions compiler-rt/lib/asan/asan_descriptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,20 @@
namespace __asan {

AsanThreadIdAndName::AsanThreadIdAndName(AsanThreadContext *t) {
Init(t->tid, t->name);
}

AsanThreadIdAndName::AsanThreadIdAndName(u32 tid) {
if (tid == kInvalidTid) {
Init(tid, "");
} else {
asanThreadRegistry().CheckLocked();
AsanThreadContext *t = GetThreadContextByTidLocked(tid);
Init(tid, t->name);
if (!t) {
internal_snprintf(name, sizeof(name), "T-1");
return;
}
int len = internal_snprintf(name, sizeof(name), "T%d", t->tid);
CHECK(((unsigned int)len) < sizeof(name));
if (internal_strlen(t->name))
internal_snprintf(&name[len], sizeof(name) - len, " (%s)", t->name);
}

void AsanThreadIdAndName::Init(u32 tid, const char *tname) {
int len = internal_snprintf(name, sizeof(name), "T%d", tid);
CHECK(((unsigned int)len) < sizeof(name));
if (tname[0] != '\0')
internal_snprintf(&name[len], sizeof(name) - len, " (%s)", tname);
AsanThreadIdAndName::AsanThreadIdAndName(u32 tid)
: AsanThreadIdAndName(
tid == kInvalidTid ? nullptr : GetThreadContextByTidLocked(tid)) {
asanThreadRegistry().CheckLocked();
}

void DescribeThread(AsanThreadContext *context) {
Expand Down
2 changes: 0 additions & 2 deletions compiler-rt/lib/asan/asan_descriptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ class AsanThreadIdAndName {
const char *c_str() const { return &name[0]; }

private:
void Init(u32 tid, const char *tname);

char name[128];
};

Expand Down

0 comments on commit e556f07

Please sign in to comment.