Skip to content

Commit 061f22d

Browse files
committed
[NFC][lsan] Refactor LockThreadRegistry/LockAllocator calls
1 parent aa407c1 commit 061f22d

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

compiler-rt/lib/lsan/lsan_common.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,22 @@ bool WordIsPoisoned(uptr addr);
224224
// Wrappers for ThreadRegistry access.
225225
void LockThreadRegistry() NO_THREAD_SAFETY_ANALYSIS;
226226
void UnlockThreadRegistry() NO_THREAD_SAFETY_ANALYSIS;
227+
228+
struct ScopedStopTheWorldLock {
229+
ScopedStopTheWorldLock() {
230+
LockThreadRegistry();
231+
LockAllocator();
232+
}
233+
234+
~ScopedStopTheWorldLock() {
235+
UnlockAllocator();
236+
UnlockThreadRegistry();
237+
}
238+
239+
ScopedStopTheWorldLock &operator=(const ScopedStopTheWorldLock &) = delete;
240+
ScopedStopTheWorldLock(const ScopedStopTheWorldLock &) = delete;
241+
};
242+
227243
ThreadRegistry *GetThreadRegistryLocked();
228244
bool GetThreadRangesLocked(tid_t os_id, uptr *stack_begin, uptr *stack_end,
229245
uptr *tls_begin, uptr *tls_end, uptr *cache_begin,

compiler-rt/lib/lsan/lsan_common_fuchsia.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ int ExitHook(int status) {
5858

5959
void LockStuffAndStopTheWorld(StopTheWorldCallback callback,
6060
CheckForLeaksParam *argument) {
61-
LockThreadRegistry();
62-
LockAllocator();
61+
ScopedStopTheWorldLock lock;
6362

6463
struct Params {
6564
InternalMmapVector<uptr> allocator_caches;
@@ -149,9 +148,6 @@ void LockStuffAndStopTheWorld(StopTheWorldCallback callback,
149148
params->callback(SuspendedThreadsListFuchsia(), params->argument);
150149
},
151150
&params);
152-
153-
UnlockAllocator();
154-
UnlockThreadRegistry();
155151
}
156152

157153
} // namespace __lsan

compiler-rt/lib/lsan/lsan_common_linux.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,9 @@ void HandleLeaks() {
122122

123123
static int LockStuffAndStopTheWorldCallback(struct dl_phdr_info *info,
124124
size_t size, void *data) {
125-
LockThreadRegistry();
126-
LockAllocator();
125+
ScopedStopTheWorldLock lock;
127126
DoStopTheWorldParam *param = reinterpret_cast<DoStopTheWorldParam *>(data);
128127
StopTheWorld(param->callback, param->argument);
129-
UnlockAllocator();
130-
UnlockThreadRegistry();
131128
return 1;
132129
}
133130

compiler-rt/lib/lsan/lsan_common_mac.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,8 @@ void HandleLeaks() {}
195195

196196
void LockStuffAndStopTheWorld(StopTheWorldCallback callback,
197197
CheckForLeaksParam *argument) {
198-
LockThreadRegistry();
199-
LockAllocator();
198+
ScopedStopTheWorldLock lock;
200199
StopTheWorld(callback, argument);
201-
UnlockAllocator();
202-
UnlockThreadRegistry();
203200
}
204201

205202
} // namespace __lsan

0 commit comments

Comments
 (0)