Skip to content

Commit efd08b4

Browse files
committed
Fix some bugs
1 parent dddcc93 commit efd08b4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/threading.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,8 +875,7 @@ JL_DLLEXPORT void _jl_sleep_mutex_init(jl_sleep_mutex_t *lock, const char *name)
875875
// bit 31 indicates spin lock
876876
// bits 30:1 indicate number of waiter threads
877877
// bit 0 indicates lock held
878-
lock->count = (uint32_t)(1ull << 31);
879-
jl_atomic_store_relaxed(&lock->count, 0);
878+
lock->count = 0;
880879
jl_atomic_store_relaxed(&lock->owner, (jl_task_t*)NULL);
881880
jl_atomic_store_release(&lock->waiters, 0);
882881
jl_profile_lock_init(lock, name);
@@ -946,6 +945,11 @@ JL_DLLEXPORT int _jl_sleep_mutex_trylock_nogc(jl_task_t *self, jl_sleep_mutex_t
946945
lock->count = 1;
947946
return 1;
948947
}
948+
if (jl_atomic_load_relaxed(&lock->owner) == self) {
949+
// we already own the lock, just increment the count
950+
lock->count++;
951+
return;
952+
}
949953
return 0;
950954
}
951955

0 commit comments

Comments
 (0)