Skip to content

Prefer to check against thread ID for musl's rwlock. NFC. #15606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion system/lib/libc/musl/src/internal/pthread_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ enum {
// XXX Emscripten: The spec allows detecting when multiple write locks would deadlock, so use an extra field
// _rw_wr_owner to record which thread owns the write lock in order to avoid hangs.
// Points to the pthread that currently has the write lock.
#define _rw_wr_owner __u.__p[3]
#define _rw_wr_owner __u.__vi[3]
#endif
#define _b_lock __u.__vi[0]
#define _b_waiters __u.__vi[1]
Expand Down
4 changes: 2 additions & 2 deletions system/lib/libc/musl/src/thread/pthread_rwlock_timedwrlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ int __pthread_rwlock_timedwrlock(pthread_rwlock_t *restrict rw, const struct tim
#ifdef __EMSCRIPTEN__
/// XXX Emscripten: The spec allows detecting when multiple write locks would deadlock, which we do here to avoid hangs.
/// If attempting to lock the write lock that we already own, error out.
if (rw->_rw_wr_owner == (void *)pthread_self()) return EDEADLK;
if (rw->_rw_wr_owner == __pthread_self()->tid) return EDEADLK;
#endif
int r, t;

Expand All @@ -27,7 +27,7 @@ int __pthread_rwlock_timedwrlock(pthread_rwlock_t *restrict rw, const struct tim
#ifdef __EMSCRIPTEN__
/// XXX Emscripten: The spec allows detecting when multiple write locks would deadlock, which we do here to avoid hangs.
/// Mark this thread as the owner of this write lock.
rw->_rw_wr_owner = (void *)pthread_self();
rw->_rw_wr_owner = __pthread_self()->tid;
#endif
return r;
}
Expand Down
2 changes: 1 addition & 1 deletion system/lib/libc/musl/src/thread/pthread_rwlock_trywrlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ int __pthread_rwlock_trywrlock(pthread_rwlock_t *rw)
#ifdef __EMSCRIPTEN__
/// XXX Emscripten: The spec allows detecting when multiple write locks would deadlock, which we do here to avoid hangs.
/// Mark this thread to own the write lock, to ignore multiple attempts to lock.
rw->_rw_wr_owner = (void *)pthread_self();
rw->_rw_wr_owner = __pthread_self()->tid;
#endif
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion system/lib/libc/musl/src/thread/pthread_rwlock_unlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int __pthread_rwlock_unlock(pthread_rwlock_t *rw)
#ifdef __EMSCRIPTEN__
/// XXX Emscripten: The spec allows detecting when multiple write locks would deadlock, which we do here to avoid hangs.
/// Mark this thread to not own the write lock anymore.
if (rw->_rw_wr_owner == (void *)pthread_self()) rw->_rw_wr_owner = 0;
if (rw->_rw_wr_owner == __pthread_self()->tid) rw->_rw_wr_owner = 0;
#endif

do {
Expand Down