1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:07:44 +00:00

Kernel: Use StringView instead of C strings in Mutex

This commit is contained in:
Andreas Kling 2021-08-29 02:07:57 +02:00
parent a28cd921a1
commit 6ae60137d7

View file

@ -26,7 +26,7 @@ class Mutex {
public: public:
using Mode = LockMode; using Mode = LockMode;
Mutex(const char* name = nullptr) Mutex(StringView name = {})
: m_name(name) : m_name(name)
{ {
} }
@ -52,19 +52,19 @@ public:
return false; return false;
} }
[[nodiscard]] const char* name() const { return m_name; } [[nodiscard]] StringView name() const { return m_name; }
static const char* mode_to_string(Mode mode) static StringView mode_to_string(Mode mode)
{ {
switch (mode) { switch (mode) {
case Mode::Unlocked: case Mode::Unlocked:
return "unlocked"; return "unlocked"sv;
case Mode::Exclusive: case Mode::Exclusive:
return "exclusive"; return "exclusive"sv;
case Mode::Shared: case Mode::Shared:
return "shared"; return "shared"sv;
default: default:
return "invalid"; return "invalid"sv;
} }
} }
@ -80,7 +80,7 @@ private:
void block(Thread&, Mode, SpinlockLocker<Spinlock<u8>>&, u32); void block(Thread&, Mode, SpinlockLocker<Spinlock<u8>>&, u32);
void unblock_waiters(Mode); void unblock_waiters(Mode);
const char* m_name { nullptr }; StringView m_name;
Mode m_mode { Mode::Unlocked }; Mode m_mode { Mode::Unlocked };
// When locked exclusively, only the thread already holding the lock can // When locked exclusively, only the thread already holding the lock can