Update rw_lock.h for #143

This commit is contained in:
木头云 2025-04-20 13:58:42 +08:00 committed by GitHub
parent f3bf137668
commit fdcc9340be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,6 +6,7 @@
#include <limits> #include <limits>
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
#include <cstdint>
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
/// Gives hint to processor that improves performance of spin-wait loops. /// Gives hint to processor that improves performance of spin-wait loops.
@ -98,7 +99,7 @@ inline void sleep(K& k) {
namespace ipc { namespace ipc {
class spin_lock { class spin_lock {
std::atomic<unsigned> lc_ { 0 }; std::atomic<std::uint32_t> lc_ { 0 };
public: public:
void lock(void) noexcept { void lock(void) noexcept {
@ -113,13 +114,13 @@ public:
}; };
class rw_lock { class rw_lock {
using lc_ui_t = unsigned; using lc_ui_t = std::uint32_t;
std::atomic<lc_ui_t> lc_ { 0 }; std::atomic<lc_ui_t> lc_ { 0 };
enum : lc_ui_t { enum : lc_ui_t {
w_mask = (std::numeric_limits<std::make_signed_t<lc_ui_t>>::max)(), // b 0111 1111 w_mask = (std::numeric_limits<std::make_signed_t<lc_ui_t>>::max)(), // b 0111 1111 ...
w_flag = w_mask + 1 // b 1000 0000 w_flag = w_mask + 1 // b 1000 0000 ...
}; };
public: public: