mirror of
https://github.com/RGBCube/serenity
synced 2025-05-22 15:55:07 +00:00
LibPthread: Okay I'm dumb, let's convert mutex locks into Atomic<u32>&
This commit is contained in:
parent
2e280417e2
commit
a12c2df43f
1 changed files with 4 additions and 4 deletions
|
@ -114,11 +114,11 @@ int pthread_mutex_destroy(pthread_mutex_t*)
|
||||||
|
|
||||||
int pthread_mutex_lock(pthread_mutex_t* mutex)
|
int pthread_mutex_lock(pthread_mutex_t* mutex)
|
||||||
{
|
{
|
||||||
auto* atomic = reinterpret_cast<Atomic<u32>*>(mutex->lock);
|
auto& atomic = reinterpret_cast<Atomic<u32>&>(mutex->lock);
|
||||||
pthread_t this_thread = pthread_self();
|
pthread_t this_thread = pthread_self();
|
||||||
for (;;) {
|
for (;;) {
|
||||||
u32 expected = false;
|
u32 expected = false;
|
||||||
if (!atomic->compare_exchange_strong(expected, true, AK::memory_order_acq_rel)) {
|
if (!atomic.compare_exchange_strong(expected, true, AK::memory_order_acq_rel)) {
|
||||||
if (mutex->type == PTHREAD_MUTEX_RECURSIVE && mutex->owner == this_thread) {
|
if (mutex->type == PTHREAD_MUTEX_RECURSIVE && mutex->owner == this_thread) {
|
||||||
mutex->level++;
|
mutex->level++;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -134,9 +134,9 @@ int pthread_mutex_lock(pthread_mutex_t* mutex)
|
||||||
|
|
||||||
int pthread_mutex_trylock(pthread_mutex_t* mutex)
|
int pthread_mutex_trylock(pthread_mutex_t* mutex)
|
||||||
{
|
{
|
||||||
auto* atomic = reinterpret_cast<Atomic<u32>*>(mutex->lock);
|
auto& atomic = reinterpret_cast<Atomic<u32>&>(mutex->lock);
|
||||||
u32 expected = false;
|
u32 expected = false;
|
||||||
if (!atomic->compare_exchange_strong(expected, true, AK::memory_order_acq_rel)) {
|
if (!atomic.compare_exchange_strong(expected, true, AK::memory_order_acq_rel)) {
|
||||||
if (mutex->type == PTHREAD_MUTEX_RECURSIVE && mutex->owner == pthread_self()) {
|
if (mutex->type == PTHREAD_MUTEX_RECURSIVE && mutex->owner == pthread_self()) {
|
||||||
mutex->level++;
|
mutex->level++;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue