Skip to content

Commit

Permalink
Kernel: Rename functions to be less confusing
Browse files Browse the repository at this point in the history
Thread::yield_and_release_relock_big_lock releases the big lock, yields
and then relocks the big lock.

Thread::yield_assuming_not_holding_big_lock yields assuming the big
lock is not being held.
  • Loading branch information
tomuta authored and awesomekling committed Jul 16, 2021
1 parent 0536a4f commit 704e1c2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Kernel/Syscalls/sched.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Kernel {
KResultOr<FlatPtr> Process::sys$yield()
{
REQUIRE_PROMISE(stdio);
Thread::current()->yield_without_holding_big_lock();
Thread::current()->yield_and_release_relock_big_lock();
return 0;
}

Expand Down
13 changes: 7 additions & 6 deletions Kernel/Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ void Thread::block(Kernel::Lock& lock, ScopedSpinLock<SpinLock<u8>>& lock_lock,
if (&lock != &big_lock && big_lock.own_lock()) {
// We're locking another lock and already hold the big lock...
// We need to release the big lock
yield_without_holding_big_lock();
yield_and_release_relock_big_lock();
} else {
yield_while_not_holding_big_lock();
yield_assuming_not_holding_big_lock();
}
VERIFY(Processor::current().in_critical());

Expand Down Expand Up @@ -414,9 +414,10 @@ void Thread::exit(void* exit_value)
die_if_needed();
}

void Thread::yield_while_not_holding_big_lock()
void Thread::yield_assuming_not_holding_big_lock()
{
VERIFY(!g_scheduler_lock.own_lock());
VERIFY(!process().big_lock().own_lock());
// Disable interrupts here. This ensures we don't accidentally switch contexts twice
InterruptDisabler disable;
Scheduler::yield(); // flag a switch
Expand All @@ -426,7 +427,7 @@ void Thread::yield_while_not_holding_big_lock()
Processor::current().restore_critical(prev_crit, prev_flags);
}

void Thread::yield_without_holding_big_lock()
void Thread::yield_and_release_relock_big_lock()
{
VERIFY(!g_scheduler_lock.own_lock());
// Disable interrupts here. This ensures we don't accidentally switch contexts twice
Expand Down Expand Up @@ -594,7 +595,7 @@ void Thread::check_dispatch_pending_signal()

switch (result) {
case DispatchSignalResult::Yield:
yield_while_not_holding_big_lock();
yield_assuming_not_holding_big_lock();
break;
default:
break;
Expand Down Expand Up @@ -701,7 +702,7 @@ void Thread::send_urgent_signal_to_self(u8 signal)
result = dispatch_signal(signal);
}
if (result == DispatchSignalResult::Yield)
yield_without_holding_big_lock();
yield_and_release_relock_big_lock();
}

DispatchSignalResult Thread::dispatch_one_pending_signal()
Expand Down
8 changes: 4 additions & 4 deletions Kernel/Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ class Thread
while (state() == Thread::Stopped) {
lock.unlock();
// We shouldn't be holding the big lock here
yield_while_not_holding_big_lock();
yield_assuming_not_holding_big_lock();
lock.lock();
}
}
Expand Down Expand Up @@ -905,7 +905,7 @@ class Thread
// Yield to the scheduler, and wait for us to resume unblocked.
VERIFY(!g_scheduler_lock.own_lock());
VERIFY(Processor::current().in_critical());
yield_while_not_holding_big_lock();
yield_assuming_not_holding_big_lock();
VERIFY(Processor::current().in_critical());

ScopedSpinLock block_lock2(m_block_lock);
Expand Down Expand Up @@ -1341,8 +1341,8 @@ class Thread

bool m_is_profiling_suppressed { false };

void yield_without_holding_big_lock();
void yield_while_not_holding_big_lock();
void yield_and_release_relock_big_lock();
void yield_assuming_not_holding_big_lock();
void drop_thread_count(bool);
};

Expand Down

0 comments on commit 704e1c2

Please sign in to comment.