Skip to content

Commit d3faecb

Browse files
committed
tsan: minor MetaMap tweaks
1. Add some comments. 2. Use kInvalidStackID instead of literal 0. 3. Add more LIKELY/UNLIKELY. Reviewed By: vitalybuka, melver Differential Revision: https://reviews.llvm.org/D107371
1 parent 6f8c434 commit d3faecb

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

compiler-rt/lib/tsan/rtl/tsan_sync.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void SyncVar::Init(ThreadState *thr, uptr pc, uptr addr, u64 uid,
2626
this->uid = uid;
2727
this->next = 0;
2828

29-
creation_stack_id = 0;
29+
creation_stack_id = kInvalidStackID;
3030
if (save_stack && !SANITIZER_GO) // Go does not use them
3131
creation_stack_id = CurrentStackId(thr, pc);
3232
if (common_flags()->detect_deadlocks)
@@ -35,7 +35,7 @@ void SyncVar::Init(ThreadState *thr, uptr pc, uptr addr, u64 uid,
3535

3636
void SyncVar::Reset(Processor *proc) {
3737
uid = 0;
38-
creation_stack_id = 0;
38+
creation_stack_id = kInvalidStackID;
3939
owner_tid = kInvalidTid;
4040
last_lock = 0;
4141
recursion = 0;
@@ -212,12 +212,12 @@ SyncVar *MetaMap::GetSync(ThreadState *thr, uptr pc, uptr addr, bool create,
212212
}
213213
if (!create)
214214
return nullptr;
215-
if (*meta != idx0) {
215+
if (UNLIKELY(*meta != idx0)) {
216216
idx0 = *meta;
217217
continue;
218218
}
219219

220-
if (myidx == 0) {
220+
if (LIKELY(myidx == 0)) {
221221
const u64 uid = atomic_fetch_add(&uid_gen_, 1, memory_order_relaxed);
222222
myidx = sync_alloc_.Alloc(&thr->proc()->sync_cache);
223223
mys = sync_alloc_.Map(myidx);

compiler-rt/lib/tsan/rtl/tsan_sync.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ enum MutexFlags {
4646
MutexFlagNotStatic,
4747
};
4848

49+
// SyncVar is a descriptor of a user synchronization object
50+
// (mutex or an atomic variable).
4951
struct SyncVar {
5052
SyncVar();
5153

@@ -101,10 +103,8 @@ struct SyncVar {
101103
}
102104
};
103105

104-
/* MetaMap allows to map arbitrary user pointers onto various descriptors.
105-
Currently it maps pointers to heap block descriptors and sync var descs.
106-
It uses 1/2 direct shadow, see tsan_platform.h.
107-
*/
106+
// MetaMap maps app addresses to heap block (MBlock) and sync var (SyncVar)
107+
// descriptors. It uses 1/2 direct shadow, see tsan_platform.h for the mapping.
108108
class MetaMap {
109109
public:
110110
MetaMap();

0 commit comments

Comments
 (0)