Skip to content

Commit dfc7ebd

Browse files
fix cross process logging
1 parent c713f7f commit dfc7ebd

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

libc/test/integration/src/pthread/pthread_rwlock_test.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ enum class Operation : int {
273273
COUNT = 6
274274
};
275275

276-
LIBC_NAMESPACE::RawMutex io_mutex{};
276+
LIBC_NAMESPACE::RawMutex *io_mutex;
277277
struct ThreadGuard {
278278
Operation record[64]{};
279279
size_t cursor = 0;
@@ -283,12 +283,12 @@ struct ThreadGuard {
283283
return;
284284
pid_t pid = LIBC_NAMESPACE::syscall_impl(SYS_getpid);
285285
pid_t tid = LIBC_NAMESPACE::syscall_impl(SYS_gettid);
286-
io_mutex.lock(LIBC_NAMESPACE::cpp::nullopt, true);
286+
io_mutex->lock(LIBC_NAMESPACE::cpp::nullopt, true);
287287
LIBC_NAMESPACE::printf("process %d thread %d: ", pid, tid);
288288
for (size_t i = 0; i < cursor; ++i)
289289
LIBC_NAMESPACE::printf("%d ", static_cast<int>(record[i]));
290290
LIBC_NAMESPACE::printf("\n");
291-
io_mutex.unlock(true);
291+
io_mutex->unlock(true);
292292
}
293293
};
294294

@@ -459,6 +459,9 @@ static void multiple_process_test(int preference) {
459459
}
460460

461461
TEST_MAIN() {
462+
io_mutex = new (LIBC_NAMESPACE::mmap(
463+
nullptr, sizeof(LIBC_NAMESPACE::RawMutex), PROT_READ | PROT_WRITE,
464+
MAP_ANONYMOUS | MAP_SHARED, -1, 0)) LIBC_NAMESPACE::RawMutex();
462465
smoke_test();
463466
deadlock_detection_test();
464467
try_lock_test();
@@ -472,5 +475,7 @@ TEST_MAIN() {
472475
single_process_test(PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
473476
multiple_process_test(PTHREAD_RWLOCK_PREFER_READER_NP);
474477
multiple_process_test(PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
478+
io_mutex->~RawMutex();
479+
LIBC_NAMESPACE::munmap(io_mutex, sizeof(LIBC_NAMESPACE::RawMutex));
475480
return 0;
476481
}

0 commit comments

Comments
 (0)