Skip to content

Commit

Permalink
mutex,once: Revert a previous commit, and rectify more
Browse files Browse the repository at this point in the history
This reverts commit 373fe71.
  • Loading branch information
lhmouse committed May 5, 2022
1 parent a1f9f31 commit 651fba1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 36 deletions.
11 changes: 6 additions & 5 deletions src/mutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ _MCF_mutex_lock_slow(_MCF_mutex* mutex, const int64_t* timeout_opt)
}
}

size_t
_MCF_mutex_unlock_slow(_MCF_mutex* mutex, size_t reserved)
void
_MCF_mutex_unlock_slow(_MCF_mutex* mutex)
{
/* Clear the `__locked` field and release at most one thread, if any.
* The right most bit one of the spinning mask is also cleared to enable
Expand All @@ -193,10 +193,11 @@ _MCF_mutex_unlock_slow(_MCF_mutex* mutex, size_t reserved)
}
while(!__MCF_ATOMIC_CMPXCHG_WEAK_PTR_REL(mutex, &old, &new));

/* Notify a spinning thread, if any. */
/* Notify a spinning thread, if any. If `__sp_mask` was non-zero, only its
* rightmost bit should have been cleared, so we need not calculate the
* bit difference, unlike `_MCF_mutex_lock_slow()`. */
if(old.__sp_mask != 0)
__MCF_ATOMIC_STORE_RLX(do_spin_byte_ptr(mutex, old.__sp_mask), 1);

(void) reserved;
return __MCF_batch_release_common(mutex, wake_one);
__MCF_batch_release_common(mutex, wake_one);
}
6 changes: 3 additions & 3 deletions src/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ _MCF_mutex_lock(_MCF_mutex* __mutex, const int64_t* __timeout_opt) __MCF_NOEXCEP
void
_MCF_mutex_unlock(_MCF_mutex* __mutex) __MCF_NOEXCEPT;

size_t
_MCF_mutex_unlock_slow(_MCF_mutex* __mutex, size_t __reserved) __MCF_NOEXCEPT;
void
_MCF_mutex_unlock_slow(_MCF_mutex* __mutex) __MCF_NOEXCEPT;

__MCF_MUTEX_EXTERN_INLINE
void
Expand All @@ -115,7 +115,7 @@ _MCF_mutex_unlock(_MCF_mutex* __mutex) __MCF_NOEXCEPT
if(__MCF_ATOMIC_CMPXCHG_WEAK_PTR_REL(__mutex, &__old, &__new))
return;

_MCF_mutex_unlock_slow(__mutex, 0);
_MCF_mutex_unlock_slow(__mutex);
}

#ifdef __cplusplus
Expand Down
14 changes: 6 additions & 8 deletions src/once.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ _MCF_once_wait_slow(_MCF_once* once, const int64_t* timeout_opt)
}
}

size_t
_MCF_once_abort_slow(_MCF_once* once, size_t reserved)
void
_MCF_once_abort(_MCF_once* once)
{
/* Clear the `__locked` field and release at most one thread, if any. */
size_t wake_one;
Expand All @@ -102,19 +102,17 @@ _MCF_once_abort_slow(_MCF_once* once, size_t reserved)
}
while(!__MCF_ATOMIC_CMPXCHG_WEAK_PTR_RLX(once, &old, &new));

(void) reserved;
return __MCF_batch_release_common(once, wake_one);
__MCF_batch_release_common(once, wake_one);
}

size_t
_MCF_once_release_slow(_MCF_once* once, size_t reserved)
void
_MCF_once_release(_MCF_once* once)
{
/* Set the `__ready` field and release all threads. */
_MCF_once old;
_MCF_once new = __MCF_0_INIT;
new.__ready = 1;
__MCF_ATOMIC_XCHG_PTR_ARL(&old, once, &new);

(void) reserved;
return __MCF_batch_release_common(once, old.__nsleep);
__MCF_batch_release_common(once, old.__nsleep);
}
20 changes: 0 additions & 20 deletions src/once.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,6 @@ _MCF_once_wait(_MCF_once* __once, const int64_t* __timeout_opt) __MCF_NOEXCEPT
void
_MCF_once_abort(_MCF_once* __once) __MCF_NOEXCEPT;

size_t
_MCF_once_abort_slow(_MCF_once* __once, size_t __reserved) __MCF_NOEXCEPT;

__MCF_ONCE_EXTERN_INLINE
void
_MCF_once_abort(_MCF_once* __once) __MCF_NOEXCEPT
{
_MCF_once_abort_slow(__once, 0);
}

/* Releases a once-initialization flag which shall be in the LOCKED state. If
* the flag has not been locked already, the behavior is undefined.
*
Expand All @@ -111,16 +101,6 @@ _MCF_once_abort(_MCF_once* __once) __MCF_NOEXCEPT
void
_MCF_once_release(_MCF_once* __once) __MCF_NOEXCEPT;

size_t
_MCF_once_release_slow(_MCF_once* __once, size_t __reserved) __MCF_NOEXCEPT;

__MCF_ONCE_EXTERN_INLINE
void
_MCF_once_release(_MCF_once* __once) __MCF_NOEXCEPT
{
_MCF_once_release_slow(__once, 0);
}

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit 651fba1

Please sign in to comment.