summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Burchell <robin+git@viroteck.net>2019-07-19 09:34:11 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-07-19 11:03:22 +0200
commitd2ca91c024e0dca3742715392ad5b2cd6125563f (patch)
tree0ee7d8339db8f9dee45e27fb0ca1bc15ce8914d1
parent750dbe986de0b80772c1bd32627850b1105c0e60 (diff)
downloadserenity-d2ca91c024e0dca3742715392ad5b2cd6125563f.zip
Kernel: Convert BlockedSignal and BlockedLurking to the new Blocker mechanism
The last two of the old block states gone :)
-rw-r--r--Kernel/Process.cpp8
-rw-r--r--Kernel/Scheduler.cpp14
-rw-r--r--Kernel/Thread.cpp8
-rw-r--r--Kernel/Thread.h16
-rw-r--r--Kernel/init.cpp2
5 files changed, 31 insertions, 17 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index 07141a7ba3..279f4cccd2 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -869,7 +869,7 @@ ssize_t Process::sys$writev(int fd, const struct iovec* iov, int iov_count)
}
if (current->has_unmasked_pending_signals()) {
- current->block(Thread::State::BlockedSignal);
+ current->block(*new Thread::SemiPermanentBlocker(Thread::SemiPermanentBlocker::Reason::Signal));
if (nwritten == 0)
return -EINTR;
}
@@ -914,7 +914,7 @@ ssize_t Process::do_write(FileDescription& description, const u8* data, int data
if (rc == 0)
break;
if (current->has_unmasked_pending_signals()) {
- current->block(Thread::State::BlockedSignal);
+ current->block(*new Thread::SemiPermanentBlocker(Thread::SemiPermanentBlocker::Reason::Signal));
if (nwritten == 0)
return -EINTR;
}
@@ -939,7 +939,7 @@ ssize_t Process::sys$write(int fd, const u8* data, ssize_t size)
return -EBADF;
auto nwritten = do_write(*description, data, size);
if (current->has_unmasked_pending_signals()) {
- current->block(Thread::State::BlockedSignal);
+ current->block(*new Thread::SemiPermanentBlocker(Thread::SemiPermanentBlocker::Reason::Signal));
if (nwritten == 0)
return -EINTR;
}
@@ -1265,7 +1265,7 @@ int Process::sys$kill(pid_t pid, int signal)
}
if (pid == m_pid) {
current->send_signal(signal, this);
- current->block(Thread::State::BlockedSignal);
+ current->block(*new Thread::SemiPermanentBlocker(Thread::SemiPermanentBlocker::Reason::Signal));
return 0;
}
InterruptDisabler disabler;
diff --git a/Kernel/Scheduler.cpp b/Kernel/Scheduler.cpp
index 60c0819f4d..ae9e624c2a 100644
--- a/Kernel/Scheduler.cpp
+++ b/Kernel/Scheduler.cpp
@@ -201,6 +201,16 @@ bool Thread::WaitBlocker::should_unblock(Thread& thread, time_t, long)
return should_unblock;
}
+Thread::SemiPermanentBlocker::SemiPermanentBlocker(Reason reason)
+ : m_reason(reason)
+{}
+
+bool Thread::SemiPermanentBlocker::should_unblock(Thread&, time_t, long)
+{
+ // someone else has to unblock us
+ return false;
+}
+
// Called by the scheduler on threads that are blocked for some reason.
// Make a decision as to whether to unblock them or not.
void Thread::consider_unblock(time_t now_sec, long now_usec)
@@ -215,8 +225,6 @@ void Thread::consider_unblock(time_t now_sec, long now_usec)
case Thread::Running:
case Thread::Dead:
case Thread::Stopped:
- case Thread::BlockedLurking:
- case Thread::BlockedSignal:
/* don't know, don't care */
return;
case Thread::BlockedCondition:
@@ -234,7 +242,7 @@ void Thread::consider_unblock(time_t now_sec, long now_usec)
return;
case Thread::Dying:
ASSERT(g_finalizer);
- if (g_finalizer->state() == Thread::BlockedLurking)
+ if (g_finalizer->is_blocked())
g_finalizer->unblock();
return;
}
diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp
index 9aa6f45698..f0d21c12b3 100644
--- a/Kernel/Thread.cpp
+++ b/Kernel/Thread.cpp
@@ -162,10 +162,6 @@ const char* to_string(Thread::State state)
return "Skip1";
case Thread::Skip0SchedulerPasses:
return "Skip0";
- case Thread::BlockedSignal:
- return "Signal";
- case Thread::BlockedLurking:
- return "Lurking";
case Thread::BlockedCondition:
return "Condition";
case Thread::__Begin_Blocked_States__:
@@ -349,9 +345,7 @@ ShouldUnblockThread Thread::dispatch_signal(u8 signal)
m_process.terminate_due_to_signal(signal);
return ShouldUnblockThread::No;
case DefaultSignalAction::Ignore:
- if (state() == BlockedSignal)
- set_state(Runnable);
- return ShouldUnblockThread::No;
+ ASSERT_NOT_REACHED();
case DefaultSignalAction::Continue:
return ShouldUnblockThread::Yes;
}
diff --git a/Kernel/Thread.h b/Kernel/Thread.h
index 6144fb8db2..b2597002f0 100644
--- a/Kernel/Thread.h
+++ b/Kernel/Thread.h
@@ -65,8 +65,6 @@ public:
Stopped,
__Begin_Blocked_States__,
- BlockedLurking,
- BlockedSignal,
BlockedCondition,
__End_Blocked_States__
};
@@ -158,6 +156,20 @@ public:
pid_t& m_waitee_pid;
};
+ class SemiPermanentBlocker : public Blocker {
+ public:
+ enum class Reason {
+ Lurking,
+ Signal,
+ };
+
+ SemiPermanentBlocker(Reason reason);
+ virtual bool should_unblock(Thread&, time_t, long) override;
+
+ private:
+ Reason m_reason;
+ };
+
void did_schedule() { ++m_times_scheduled; }
u32 times_scheduled() const { return m_times_scheduled; }
diff --git a/Kernel/init.cpp b/Kernel/init.cpp
index c2bba580c4..70a9ca8c92 100644
--- a/Kernel/init.cpp
+++ b/Kernel/init.cpp
@@ -242,7 +242,7 @@ extern "C" [[noreturn]] void init()
current->process().set_priority(Process::LowPriority);
for (;;) {
Thread::finalize_dying_threads();
- current->block(Thread::BlockedLurking);
+ current->block(*new Thread::SemiPermanentBlocker(Thread::SemiPermanentBlocker::Reason::Lurking));
Scheduler::yield();
}
});