Fix recursive locks when tid is huge

It turns out Linux may assign thread ids that are much larger than
previously thought. We now have fewer bits of depth so we can have
bigger tids.
This commit is contained in:
Justine Tunney 2023-01-03 05:01:00 -08:00
parent 9c72fef086
commit a4b6803556
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
3 changed files with 4 additions and 4 deletions

View file

@ -89,7 +89,7 @@ int pthread_mutex_lock(pthread_mutex_t *mutex) {
t = gettid();
if (mutex->_owner == t) {
if (mutex->_type != PTHREAD_MUTEX_ERRORCHECK) {
if (mutex->_depth < 255) {
if (mutex->_depth < 63) {
++mutex->_depth;
return 0;
} else {

View file

@ -59,7 +59,7 @@ errno_t pthread_mutex_trylock(pthread_mutex_t *mutex) {
t = gettid();
if (mutex->_owner == t) {
if (mutex->_type != PTHREAD_MUTEX_ERRORCHECK) {
if (mutex->_depth < 255) {
if (mutex->_depth < 63) {
++mutex->_depth;
return 0;
} else {

View file

@ -67,8 +67,8 @@ typedef struct pthread_mutex_s {
_Atomic(int32_t) _lock;
unsigned _type : 2;
unsigned _pshared : 1;
unsigned _depth : 8;
unsigned _owner : 21;
unsigned _depth : 6;
unsigned _owner : 23;
long _pid;
} pthread_mutex_t;