mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
Kernel: Restore state strings for block states
"Blocking" is not terribly informative, but now that everything is ported over, we can force the blocker to provide us with a reason. This does mean that to_string(State) needed to become a member, but that's OK.
This commit is contained in:
parent
b13f1699fc
commit
762333ba95
Notes:
sideshowbarker
2024-07-19 13:09:26 +09:00
Author: https://github.com/rburchell Commit: https://github.com/SerenityOS/serenity/commit/762333ba95a Pull-request: https://github.com/SerenityOS/serenity/pull/340
7 changed files with 37 additions and 18 deletions
|
@ -139,7 +139,7 @@ void SB16::handle_irq()
|
|||
|
||||
void SB16::wait_for_irq()
|
||||
{
|
||||
current->block_until([this] {
|
||||
current->block_until("Interrupting", [this] {
|
||||
return m_interrupted;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -572,7 +572,7 @@ ByteBuffer procfs$all(InodeIdentifier)
|
|||
process_object.set("sid", process.sid());
|
||||
process_object.set("uid", process.uid());
|
||||
process_object.set("gid", process.gid());
|
||||
process_object.set("state", to_string(process.state()));
|
||||
process_object.set("state", process.main_thread().state_string());
|
||||
process_object.set("ppid", process.ppid());
|
||||
process_object.set("nfds", process.number_of_open_file_descriptors());
|
||||
process_object.set("name", process.name());
|
||||
|
|
|
@ -59,7 +59,7 @@ void NetworkTask_main()
|
|||
for (;;) {
|
||||
auto packet = dequeue_packet();
|
||||
if (packet.is_null()) {
|
||||
current->block_until([] {
|
||||
current->block_until("Networking", [] {
|
||||
if (LoopbackAdapter::the().has_queued_packets())
|
||||
return true;
|
||||
if (auto* e1000 = E1000NetworkAdapter::the()) {
|
||||
|
|
|
@ -1384,7 +1384,7 @@ int Process::reap(Process& process)
|
|||
}
|
||||
}
|
||||
|
||||
dbgprintf("reap: %s(%u) {%s}\n", process.name().characters(), process.pid(), to_string(process.state()));
|
||||
dbgprintf("reap: %s(%u) {%s}\n", process.name().characters(), process.pid(), process.main_thread().state_string());
|
||||
ASSERT(process.is_dead());
|
||||
g_processes->remove(&process);
|
||||
}
|
||||
|
|
|
@ -122,8 +122,9 @@ bool Thread::ReadBlocker::should_unblock(Thread&, time_t, long)
|
|||
return blocked_description()->can_read();
|
||||
}
|
||||
|
||||
Thread::ConditionBlocker::ConditionBlocker(Function<bool()> &condition)
|
||||
Thread::ConditionBlocker::ConditionBlocker(const char* state_string, Function<bool()> &condition)
|
||||
: m_block_until_condition(move(condition))
|
||||
, m_state_string(state_string)
|
||||
{
|
||||
ASSERT(m_block_until_condition);
|
||||
}
|
||||
|
|
|
@ -108,9 +108,9 @@ void Thread::unblock()
|
|||
set_state(Thread::Runnable);
|
||||
}
|
||||
|
||||
void Thread::block_until(Function<bool()>&& condition)
|
||||
void Thread::block_until(const char* state_string, Function<bool()>&& condition)
|
||||
{
|
||||
m_blocker = make<ConditionBlocker>(condition);
|
||||
m_blocker = make<ConditionBlocker>(state_string, condition);
|
||||
block(Thread::Blocked);
|
||||
Scheduler::yield();
|
||||
}
|
||||
|
@ -118,9 +118,6 @@ void Thread::block_until(Function<bool()>&& condition)
|
|||
void Thread::block(Thread::State new_state)
|
||||
{
|
||||
bool did_unlock = process().big_lock().unlock_if_locked();
|
||||
if (state() != Thread::Running) {
|
||||
dbgprintf("Thread::block: %s(%u) block(%u/%s) with state=%u/%s\n", process().name().characters(), process().pid(), new_state, to_string(new_state), state(), to_string(state()));
|
||||
}
|
||||
ASSERT(state() == Thread::Running);
|
||||
m_was_interrupted_while_blocked = false;
|
||||
set_state(new_state);
|
||||
|
@ -143,9 +140,9 @@ u64 Thread::sleep(u32 ticks)
|
|||
return wakeup_time;
|
||||
}
|
||||
|
||||
const char* to_string(Thread::State state)
|
||||
const char* Thread::state_string() const
|
||||
{
|
||||
switch (state) {
|
||||
switch (state()) {
|
||||
case Thread::Invalid:
|
||||
return "Invalid";
|
||||
case Thread::Runnable:
|
||||
|
@ -163,9 +160,10 @@ const char* to_string(Thread::State state)
|
|||
case Thread::Skip0SchedulerPasses:
|
||||
return "Skip0";
|
||||
case Thread::Blocked:
|
||||
return "Blocked";
|
||||
ASSERT(m_blocker);
|
||||
return m_blocker->state_string();
|
||||
}
|
||||
kprintf("to_string(Thread::State): Invalid state: %u\n", state);
|
||||
kprintf("to_string(Thread::State): Invalid state: %u\n", state());
|
||||
ASSERT_NOT_REACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -70,6 +70,7 @@ public:
|
|||
public:
|
||||
virtual ~Blocker() {}
|
||||
virtual bool should_unblock(Thread&, time_t now_s, long us) = 0;
|
||||
virtual const char* state_string() const = 0;
|
||||
};
|
||||
|
||||
class FileDescriptionBlocker : public Blocker {
|
||||
|
@ -85,45 +86,53 @@ public:
|
|||
public:
|
||||
AcceptBlocker(const RefPtr<FileDescription>& description);
|
||||
virtual bool should_unblock(Thread&, time_t, long) override;
|
||||
virtual const char* state_string() const override { return "Accepting"; }
|
||||
};
|
||||
|
||||
class ReceiveBlocker : public FileDescriptionBlocker {
|
||||
public:
|
||||
ReceiveBlocker(const RefPtr<FileDescription>& description);
|
||||
virtual bool should_unblock(Thread&, time_t, long) override;
|
||||
virtual const char* state_string() const override { return "Receiving"; }
|
||||
};
|
||||
|
||||
class ConnectBlocker : public FileDescriptionBlocker {
|
||||
public:
|
||||
ConnectBlocker(const RefPtr<FileDescription>& description);
|
||||
virtual bool should_unblock(Thread&, time_t, long) override;
|
||||
virtual const char* state_string() const override { return "Connecting"; }
|
||||
};
|
||||
|
||||
class WriteBlocker : public FileDescriptionBlocker {
|
||||
public:
|
||||
WriteBlocker(const RefPtr<FileDescription>& description);
|
||||
virtual bool should_unblock(Thread&, time_t, long) override;
|
||||
virtual const char* state_string() const override { return "Writing"; }
|
||||
};
|
||||
|
||||
class ReadBlocker : public FileDescriptionBlocker {
|
||||
public:
|
||||
ReadBlocker(const RefPtr<FileDescription>& description);
|
||||
virtual bool should_unblock(Thread&, time_t, long) override;
|
||||
virtual const char* state_string() const override { return "Reading"; }
|
||||
};
|
||||
|
||||
class ConditionBlocker : public Blocker {
|
||||
public:
|
||||
ConditionBlocker(Function<bool()> &condition);
|
||||
ConditionBlocker(const char* state_string, Function<bool()> &condition);
|
||||
virtual bool should_unblock(Thread&, time_t, long) override;
|
||||
virtual const char* state_string() const override { return m_state_string; }
|
||||
|
||||
private:
|
||||
Function<bool()> m_block_until_condition;
|
||||
const char* m_state_string;
|
||||
};
|
||||
|
||||
class SleepBlocker : public Blocker {
|
||||
public:
|
||||
SleepBlocker(u64 wakeup_time);
|
||||
virtual bool should_unblock(Thread&, time_t, long) override;
|
||||
virtual const char* state_string() const override { return "Sleeping"; }
|
||||
|
||||
private:
|
||||
u64 m_wakeup_time { 0 };
|
||||
|
@ -134,6 +143,7 @@ public:
|
|||
typedef Vector<int, FD_SETSIZE> FDVector;
|
||||
SelectBlocker(const timeval& tv, bool select_has_timeout, const FDVector& read_fds, const FDVector& write_fds, const FDVector& except_fds);
|
||||
virtual bool should_unblock(Thread&, time_t, long) override;
|
||||
virtual const char* state_string() const override { return "Selecting"; }
|
||||
|
||||
private:
|
||||
timeval m_select_timeout;
|
||||
|
@ -147,6 +157,7 @@ public:
|
|||
public:
|
||||
WaitBlocker(int wait_options, pid_t& waitee_pid);
|
||||
virtual bool should_unblock(Thread&, time_t, long) override;
|
||||
virtual const char* state_string() const override { return "Waiting"; }
|
||||
|
||||
private:
|
||||
int m_wait_options { 0 };
|
||||
|
@ -162,6 +173,16 @@ public:
|
|||
|
||||
SemiPermanentBlocker(Reason reason);
|
||||
virtual bool should_unblock(Thread&, time_t, long) override;
|
||||
virtual const char* state_string() const override
|
||||
{
|
||||
switch (m_reason) {
|
||||
case Reason::Lurking:
|
||||
return "Lurking";
|
||||
case Reason::Signal:
|
||||
return "Signal";
|
||||
}
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
private:
|
||||
Reason m_reason;
|
||||
|
@ -183,6 +204,7 @@ public:
|
|||
u16 selector() const { return m_far_ptr.selector; }
|
||||
TSS32& tss() { return m_tss; }
|
||||
State state() const { return m_state; }
|
||||
const char* state_string() const;
|
||||
u32 ticks() const { return m_ticks; }
|
||||
|
||||
u64 sleep(u32 ticks);
|
||||
|
@ -190,7 +212,7 @@ public:
|
|||
void block(Blocker& blocker);
|
||||
void unblock();
|
||||
|
||||
void block_until(Function<bool()>&&);
|
||||
void block_until(const char* state_string, Function<bool()>&&);
|
||||
KResult wait_for_connect(FileDescription&);
|
||||
|
||||
const FarPtr& far_ptr() const { return m_far_ptr; }
|
||||
|
@ -281,8 +303,6 @@ private:
|
|||
|
||||
HashTable<Thread*>& thread_table();
|
||||
|
||||
const char* to_string(Thread::State);
|
||||
|
||||
template<typename Callback>
|
||||
inline void Thread::for_each_in_state(State state, Callback callback)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue