2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
|
2021-04-24 15:17:02 -07:00
|
|
|
#include <AK/SourceLocation.h>
|
2021-01-25 16:07:10 +01:00
|
|
|
#include <Kernel/Debug.h>
|
2020-02-16 01:27:42 +01:00
|
|
|
#include <Kernel/KSyms.h>
|
2019-07-29 12:00:14 +02:00
|
|
|
#include <Kernel/Lock.h>
|
2021-07-10 10:23:16 -06:00
|
|
|
#include <Kernel/SpinLock.h>
|
2020-12-14 16:36:22 -07:00
|
|
|
#include <Kernel/Thread.h>
|
|
|
|
|
|
2020-02-16 01:27:42 +01:00
|
|
|
namespace Kernel {
|
|
|
|
|
|
2021-01-23 23:29:11 +01:00
|
|
|
#if LOCK_DEBUG
|
2021-04-24 15:17:02 -07:00
|
|
|
void Lock::lock(Mode mode, const SourceLocation& location)
|
2020-11-30 19:04:36 -07:00
|
|
|
#else
|
2020-04-18 12:21:00 +03:00
|
|
|
void Lock::lock(Mode mode)
|
2020-11-30 19:04:36 -07:00
|
|
|
#endif
|
2020-04-18 12:21:00 +03:00
|
|
|
{
|
2020-11-30 19:04:36 -07:00
|
|
|
// NOTE: This may be called from an interrupt handler (not an IRQ handler)
|
|
|
|
|
// and also from within critical sections!
|
2021-02-23 20:42:32 +01:00
|
|
|
VERIFY(!Processor::current().in_irq());
|
|
|
|
|
VERIFY(mode != Mode::Unlocked);
|
2020-06-28 15:34:31 -06:00
|
|
|
auto current_thread = Thread::current();
|
2021-01-23 10:43:52 -07:00
|
|
|
|
2021-07-10 10:23:16 -06:00
|
|
|
ScopedSpinLock lock(m_lock);
|
|
|
|
|
bool did_block = false;
|
|
|
|
|
Mode current_mode = m_mode;
|
|
|
|
|
switch (current_mode) {
|
|
|
|
|
case Mode::Unlocked: {
|
|
|
|
|
dbgln_if(LOCK_TRACE_DEBUG, "Lock::lock @ ({}) {}: acquire {}, currently unlocked", this, m_name, mode_to_string(mode));
|
|
|
|
|
m_mode = mode;
|
|
|
|
|
VERIFY(!m_holder);
|
|
|
|
|
VERIFY(m_shared_holders.is_empty());
|
|
|
|
|
if (mode == Mode::Exclusive) {
|
|
|
|
|
m_holder = current_thread;
|
|
|
|
|
} else {
|
|
|
|
|
VERIFY(mode == Mode::Shared);
|
|
|
|
|
m_shared_holders.set(current_thread, 1);
|
|
|
|
|
}
|
|
|
|
|
VERIFY(m_times_locked == 0);
|
|
|
|
|
m_times_locked++;
|
2021-04-24 15:17:02 -07:00
|
|
|
|
2021-01-23 23:29:11 +01:00
|
|
|
#if LOCK_DEBUG
|
2021-07-10 10:23:16 -06:00
|
|
|
if (current_thread) {
|
|
|
|
|
current_thread->holding_lock(*this, 1, location);
|
|
|
|
|
}
|
2020-12-14 16:36:22 -07:00
|
|
|
#endif
|
2021-07-10 10:23:16 -06:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
case Mode::Exclusive: {
|
|
|
|
|
VERIFY(m_holder);
|
|
|
|
|
if (m_holder != current_thread) {
|
|
|
|
|
block(*current_thread, mode, lock, 1);
|
|
|
|
|
did_block = true;
|
2021-01-23 10:43:52 -07:00
|
|
|
}
|
2021-01-18 17:25:44 +01:00
|
|
|
|
2021-07-10 10:23:16 -06:00
|
|
|
VERIFY(m_shared_holders.is_empty());
|
|
|
|
|
|
|
|
|
|
if constexpr (LOCK_TRACE_DEBUG) {
|
|
|
|
|
if (mode == Mode::Exclusive)
|
|
|
|
|
dbgln("Lock::lock @ {} ({}): acquire {}, currently exclusive, holding: {}", this, m_name, mode_to_string(mode), m_times_locked);
|
|
|
|
|
else
|
|
|
|
|
dbgln("Lock::lock @ {} ({}): acquire exclusive (requested {}), currently exclusive, holding: {}", this, m_name, mode_to_string(mode), m_times_locked);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VERIFY(mode == Mode::Exclusive || mode == Mode::Shared);
|
|
|
|
|
VERIFY(m_times_locked > 0);
|
|
|
|
|
if (!did_block)
|
2021-01-23 10:43:52 -07:00
|
|
|
m_times_locked++;
|
2021-04-24 15:17:02 -07:00
|
|
|
|
2021-01-23 23:29:11 +01:00
|
|
|
#if LOCK_DEBUG
|
2021-07-10 10:23:16 -06:00
|
|
|
current_thread->holding_lock(*this, 1, location);
|
2020-12-14 16:36:22 -07:00
|
|
|
#endif
|
2021-07-10 10:23:16 -06:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
case Mode::Shared: {
|
|
|
|
|
VERIFY(!m_holder);
|
|
|
|
|
if (mode == Mode::Exclusive && m_shared_holders.size() == 1) {
|
|
|
|
|
auto it = m_shared_holders.begin();
|
|
|
|
|
if (it->key == current_thread) {
|
|
|
|
|
it->value++;
|
|
|
|
|
m_times_locked++;
|
|
|
|
|
m_mode = Mode::Exclusive;
|
|
|
|
|
m_holder = current_thread;
|
|
|
|
|
m_shared_holders.clear();
|
|
|
|
|
dbgln_if(LOCK_TRACE_DEBUG, "Lock::lock @ {} ({}): acquire {}, converted shared to exclusive lock, locks held {}", this, m_name, mode_to_string(mode), m_times_locked);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (mode != Mode::Shared) {
|
|
|
|
|
block(*current_thread, mode, lock, 1);
|
|
|
|
|
did_block = true;
|
2021-01-23 10:43:52 -07:00
|
|
|
}
|
2021-01-18 17:25:44 +01:00
|
|
|
|
2021-07-10 10:23:16 -06:00
|
|
|
dbgln_if(LOCK_TRACE_DEBUG, "Lock::lock @ {} ({}): acquire {}, currently shared, locks held {}", this, m_name, mode_to_string(mode), m_times_locked);
|
2021-01-18 17:25:44 +01:00
|
|
|
|
2021-07-10 10:23:16 -06:00
|
|
|
VERIFY(m_times_locked > 0);
|
|
|
|
|
if (did_block) {
|
|
|
|
|
VERIFY(m_shared_holders.contains(current_thread));
|
|
|
|
|
} else {
|
2021-01-23 10:43:52 -07:00
|
|
|
m_times_locked++;
|
2021-02-23 20:42:32 +01:00
|
|
|
VERIFY(!m_shared_holders.is_empty());
|
2021-01-23 10:43:52 -07:00
|
|
|
auto it = m_shared_holders.find(current_thread);
|
|
|
|
|
if (it != m_shared_holders.end())
|
|
|
|
|
it->value++;
|
|
|
|
|
else
|
|
|
|
|
m_shared_holders.set(current_thread, 1);
|
2021-07-10 10:23:16 -06:00
|
|
|
}
|
2021-04-24 15:17:02 -07:00
|
|
|
|
2021-01-23 23:29:11 +01:00
|
|
|
#if LOCK_DEBUG
|
2021-07-10 10:23:16 -06:00
|
|
|
current_thread->holding_lock(*this, 1, location);
|
2020-12-14 16:36:22 -07:00
|
|
|
#endif
|
2021-07-10 10:23:16 -06:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
VERIFY_NOT_REACHED();
|
2019-07-29 12:00:14 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Lock::unlock()
|
|
|
|
|
{
|
2020-11-30 19:04:36 -07:00
|
|
|
// NOTE: This may be called from an interrupt handler (not an IRQ handler)
|
|
|
|
|
// and also from within critical sections!
|
2021-02-23 20:42:32 +01:00
|
|
|
VERIFY(!Processor::current().in_irq());
|
2020-06-28 15:34:31 -06:00
|
|
|
auto current_thread = Thread::current();
|
2021-07-10 10:23:16 -06:00
|
|
|
ScopedSpinLock lock(m_lock);
|
|
|
|
|
Mode current_mode = m_mode;
|
|
|
|
|
if constexpr (LOCK_TRACE_DEBUG) {
|
|
|
|
|
if (current_mode == Mode::Shared)
|
|
|
|
|
dbgln("Lock::unlock @ {} ({}): release {}, locks held: {}", this, m_name, mode_to_string(current_mode), m_times_locked);
|
|
|
|
|
else
|
|
|
|
|
dbgln("Lock::unlock @ {} ({}): release {}, holding: {}", this, m_name, mode_to_string(current_mode), m_times_locked);
|
|
|
|
|
}
|
2021-01-18 17:25:44 +01:00
|
|
|
|
2021-07-10 10:23:16 -06:00
|
|
|
VERIFY(current_mode != Mode::Unlocked);
|
2020-04-18 12:21:00 +03:00
|
|
|
|
2021-07-10 10:23:16 -06:00
|
|
|
VERIFY(m_times_locked > 0);
|
|
|
|
|
m_times_locked--;
|
2020-12-14 16:36:22 -07:00
|
|
|
|
2021-07-10 10:23:16 -06:00
|
|
|
switch (current_mode) {
|
|
|
|
|
case Mode::Exclusive:
|
|
|
|
|
VERIFY(m_holder == current_thread);
|
|
|
|
|
VERIFY(m_shared_holders.is_empty());
|
|
|
|
|
if (m_times_locked == 0)
|
|
|
|
|
m_holder = nullptr;
|
|
|
|
|
break;
|
|
|
|
|
case Mode::Shared: {
|
|
|
|
|
VERIFY(!m_holder);
|
|
|
|
|
auto it = m_shared_holders.find(current_thread);
|
|
|
|
|
VERIFY(it != m_shared_holders.end());
|
|
|
|
|
if (it->value > 1) {
|
|
|
|
|
it->value--;
|
|
|
|
|
} else {
|
|
|
|
|
VERIFY(it->value > 0);
|
|
|
|
|
m_shared_holders.remove(it);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
VERIFY_NOT_REACHED();
|
|
|
|
|
}
|
2020-12-14 16:36:22 -07:00
|
|
|
|
2021-01-23 23:29:11 +01:00
|
|
|
#if LOCK_DEBUG
|
2021-07-10 10:23:16 -06:00
|
|
|
if (current_thread) {
|
|
|
|
|
current_thread->holding_lock(*this, -1, {});
|
|
|
|
|
}
|
2020-11-30 19:04:36 -07:00
|
|
|
#endif
|
2021-07-10 10:23:16 -06:00
|
|
|
|
|
|
|
|
if (m_times_locked == 0) {
|
|
|
|
|
VERIFY(current_mode == Mode::Exclusive ? !m_holder : m_shared_holders.is_empty());
|
|
|
|
|
|
|
|
|
|
m_mode = Mode::Unlocked;
|
|
|
|
|
unblock_waiters(current_mode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Lock::block(Thread& current_thread, Mode mode, ScopedSpinLock<SpinLock<u8>>& lock, u32 requested_locks)
|
|
|
|
|
{
|
|
|
|
|
auto& blocked_thread_list = thread_list_for_mode(mode);
|
|
|
|
|
VERIFY(!blocked_thread_list.contains(current_thread));
|
|
|
|
|
blocked_thread_list.append(current_thread);
|
|
|
|
|
|
|
|
|
|
dbgln_if(LOCK_TRACE_DEBUG, "Lock::lock @ {} ({}) waiting...", this, m_name);
|
|
|
|
|
current_thread.block(*this, lock, requested_locks);
|
|
|
|
|
dbgln_if(LOCK_TRACE_DEBUG, "Lock::lock @ {} ({}) waited", this, m_name);
|
|
|
|
|
|
|
|
|
|
VERIFY(blocked_thread_list.contains(current_thread));
|
|
|
|
|
blocked_thread_list.remove(current_thread);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Lock::unblock_waiters(Mode previous_mode)
|
|
|
|
|
{
|
|
|
|
|
VERIFY(m_times_locked == 0);
|
|
|
|
|
VERIFY(m_mode == Mode::Unlocked);
|
|
|
|
|
|
|
|
|
|
if (m_blocked_threads_list_exclusive.is_empty() && m_blocked_threads_list_shared.is_empty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
auto unblock_shared = [&]() {
|
|
|
|
|
if (m_blocked_threads_list_shared.is_empty())
|
|
|
|
|
return false;
|
|
|
|
|
m_mode = Mode::Shared;
|
|
|
|
|
for (auto& thread : m_blocked_threads_list_shared) {
|
|
|
|
|
auto requested_locks = thread.unblock_from_lock(*this);
|
|
|
|
|
auto set_result = m_shared_holders.set(&thread, requested_locks);
|
|
|
|
|
VERIFY(set_result == AK::HashSetResult::InsertedNewEntry);
|
|
|
|
|
m_times_locked += requested_locks;
|
2019-07-29 12:00:14 +02:00
|
|
|
}
|
2021-07-10 10:23:16 -06:00
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
auto unblock_exclusive = [&]() {
|
|
|
|
|
if (auto* next_exclusive_thread = m_blocked_threads_list_exclusive.first()) {
|
|
|
|
|
m_mode = Mode::Exclusive;
|
|
|
|
|
m_times_locked = next_exclusive_thread->unblock_from_lock(*this);
|
|
|
|
|
m_holder = next_exclusive_thread;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (previous_mode == Mode::Exclusive) {
|
|
|
|
|
if (!unblock_shared())
|
|
|
|
|
unblock_exclusive();
|
|
|
|
|
} else {
|
|
|
|
|
if (!unblock_exclusive())
|
|
|
|
|
unblock_shared();
|
2019-07-29 12:00:14 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-14 16:36:22 -07:00
|
|
|
auto Lock::force_unlock_if_locked(u32& lock_count_to_restore) -> Mode
|
2019-07-29 12:00:14 +02:00
|
|
|
{
|
2020-11-30 19:04:36 -07:00
|
|
|
// NOTE: This may be called from an interrupt handler (not an IRQ handler)
|
|
|
|
|
// and also from within critical sections!
|
2021-02-23 20:42:32 +01:00
|
|
|
VERIFY(!Processor::current().in_irq());
|
2020-12-14 16:36:22 -07:00
|
|
|
auto current_thread = Thread::current();
|
2021-07-10 10:23:16 -06:00
|
|
|
ScopedSpinLock lock(m_lock);
|
|
|
|
|
auto current_mode = m_mode;
|
|
|
|
|
switch (current_mode) {
|
|
|
|
|
case Mode::Exclusive: {
|
|
|
|
|
if (m_holder != current_thread) {
|
|
|
|
|
lock_count_to_restore = 0;
|
|
|
|
|
return Mode::Unlocked;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbgln_if(LOCK_RESTORE_DEBUG, "Lock::force_unlock_if_locked @ {}: unlocking exclusive with lock count: {}", this, m_times_locked);
|
2021-01-23 22:30:10 -07:00
|
|
|
#if LOCK_DEBUG
|
2021-07-10 10:23:16 -06:00
|
|
|
m_holder->holding_lock(*this, -(int)m_times_locked, {});
|
2021-01-23 22:30:10 -07:00
|
|
|
#endif
|
2021-07-10 10:23:16 -06:00
|
|
|
m_holder = nullptr;
|
|
|
|
|
VERIFY(m_times_locked > 0);
|
|
|
|
|
lock_count_to_restore = m_times_locked;
|
|
|
|
|
m_times_locked = 0;
|
|
|
|
|
m_mode = Mode::Unlocked;
|
|
|
|
|
unblock_waiters(Mode::Exclusive);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case Mode::Shared: {
|
|
|
|
|
VERIFY(!m_holder);
|
|
|
|
|
auto it = m_shared_holders.find(current_thread);
|
|
|
|
|
if (it == m_shared_holders.end()) {
|
|
|
|
|
lock_count_to_restore = 0;
|
|
|
|
|
return Mode::Unlocked;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbgln_if(LOCK_RESTORE_DEBUG, "Lock::force_unlock_if_locked @ {}: unlocking exclusive with lock count: {}, total locks: {}",
|
|
|
|
|
this, it->value, m_times_locked);
|
|
|
|
|
|
|
|
|
|
VERIFY(it->value > 0);
|
|
|
|
|
lock_count_to_restore = it->value;
|
|
|
|
|
VERIFY(lock_count_to_restore > 0);
|
2021-01-23 23:29:11 +01:00
|
|
|
#if LOCK_DEBUG
|
2021-07-10 10:23:16 -06:00
|
|
|
m_holder->holding_lock(*this, -(int)lock_count_to_restore, {});
|
2020-11-30 19:04:36 -07:00
|
|
|
#endif
|
2021-07-10 10:23:16 -06:00
|
|
|
m_shared_holders.remove(it);
|
|
|
|
|
VERIFY(m_times_locked >= lock_count_to_restore);
|
|
|
|
|
m_times_locked -= lock_count_to_restore;
|
|
|
|
|
if (m_times_locked == 0) {
|
|
|
|
|
m_mode = Mode::Unlocked;
|
|
|
|
|
unblock_waiters(Mode::Shared);
|
2020-12-14 16:36:22 -07:00
|
|
|
}
|
2021-07-10 10:23:16 -06:00
|
|
|
break;
|
2020-12-14 16:36:22 -07:00
|
|
|
}
|
2021-07-10 10:23:16 -06:00
|
|
|
case Mode::Unlocked: {
|
|
|
|
|
lock_count_to_restore = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
VERIFY_NOT_REACHED();
|
|
|
|
|
}
|
|
|
|
|
return current_mode;
|
2020-12-14 16:36:22 -07:00
|
|
|
}
|
|
|
|
|
|
2021-01-23 23:29:11 +01:00
|
|
|
#if LOCK_DEBUG
|
2021-04-24 15:17:02 -07:00
|
|
|
void Lock::restore_lock(Mode mode, u32 lock_count, const SourceLocation& location)
|
2020-12-14 16:36:22 -07:00
|
|
|
#else
|
|
|
|
|
void Lock::restore_lock(Mode mode, u32 lock_count)
|
|
|
|
|
#endif
|
|
|
|
|
{
|
2021-02-23 20:42:32 +01:00
|
|
|
VERIFY(mode != Mode::Unlocked);
|
|
|
|
|
VERIFY(lock_count > 0);
|
|
|
|
|
VERIFY(!Processor::current().in_irq());
|
2020-12-14 16:36:22 -07:00
|
|
|
auto current_thread = Thread::current();
|
2021-07-10 10:23:16 -06:00
|
|
|
bool did_block = false;
|
|
|
|
|
ScopedSpinLock lock(m_lock);
|
|
|
|
|
switch (mode) {
|
|
|
|
|
case Mode::Exclusive: {
|
|
|
|
|
if (m_mode != Mode::Unlocked) {
|
|
|
|
|
block(*current_thread, Mode::Exclusive, lock, lock_count);
|
|
|
|
|
did_block = true;
|
|
|
|
|
}
|
2021-04-24 15:17:02 -07:00
|
|
|
|
2021-07-10 10:23:16 -06:00
|
|
|
dbgln_if(LOCK_RESTORE_DEBUG, "Lock::restore_lock @ {}: restoring {} with lock count {}, was unlocked", this, mode_to_string(mode), lock_count);
|
|
|
|
|
|
|
|
|
|
VERIFY(m_shared_holders.is_empty());
|
|
|
|
|
if (did_block) {
|
|
|
|
|
VERIFY(m_mode == Mode::Exclusive);
|
|
|
|
|
VERIFY(m_times_locked > 0);
|
|
|
|
|
VERIFY(m_holder == current_thread);
|
|
|
|
|
} else {
|
|
|
|
|
m_mode = Mode::Exclusive;
|
|
|
|
|
VERIFY(m_times_locked == 0);
|
|
|
|
|
m_times_locked = lock_count;
|
|
|
|
|
VERIFY(!m_holder);
|
|
|
|
|
m_holder = current_thread;
|
|
|
|
|
}
|
2021-04-24 15:17:02 -07:00
|
|
|
|
2021-01-23 23:29:11 +01:00
|
|
|
#if LOCK_DEBUG
|
2021-07-10 10:23:16 -06:00
|
|
|
m_holder->holding_lock(*this, (int)lock_count, location);
|
2020-12-14 16:36:22 -07:00
|
|
|
#endif
|
2021-07-10 10:23:16 -06:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
case Mode::Shared: {
|
|
|
|
|
auto previous_mode = m_mode;
|
|
|
|
|
if (m_mode != Mode::Unlocked && m_mode != Mode::Shared) {
|
|
|
|
|
block(*current_thread, Mode::Shared, lock, lock_count);
|
|
|
|
|
did_block = true;
|
|
|
|
|
}
|
2020-12-14 16:36:22 -07:00
|
|
|
|
2021-07-10 10:23:16 -06:00
|
|
|
dbgln_if(LOCK_RESTORE_DEBUG, "Lock::restore_lock @ {}: restoring {} with lock count {}, was {}",
|
|
|
|
|
this, mode_to_string(mode), lock_count, mode_to_string(previous_mode));
|
|
|
|
|
|
|
|
|
|
VERIFY(!m_holder);
|
|
|
|
|
if (did_block) {
|
|
|
|
|
VERIFY(m_mode == Mode::Shared);
|
|
|
|
|
VERIFY(m_times_locked > 0);
|
|
|
|
|
VERIFY(m_shared_holders.contains(current_thread));
|
|
|
|
|
} else {
|
|
|
|
|
m_mode = Mode::Shared;
|
|
|
|
|
m_times_locked += lock_count;
|
|
|
|
|
auto set_result = m_shared_holders.set(current_thread, lock_count);
|
|
|
|
|
// There may be other shared lock holders already, but we should not have an entry yet
|
|
|
|
|
VERIFY(set_result == AK::HashSetResult::InsertedNewEntry);
|
2020-11-30 19:04:36 -07:00
|
|
|
}
|
2020-02-16 01:27:42 +01:00
|
|
|
|
2021-07-10 10:23:16 -06:00
|
|
|
#if LOCK_DEBUG
|
|
|
|
|
m_holder->holding_lock(*this, (int)lock_count, location);
|
|
|
|
|
#endif
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
VERIFY_NOT_REACHED();
|
|
|
|
|
}
|
Kernel: Allow process with multiple threads to call exec and exit
This allows a process wich has more than 1 thread to call exec, even
from a thread. This kills all the other threads, but it won't wait for
them to finish, just makes sure that they are not in a running/runable
state.
In the case where a thread does exec, the new program PID will be the
thread TID, to keep the PID == TID in the new process.
This introduces a new function inside the Process class,
kill_threads_except_self which is called on exit() too (exit with
multiple threads wasn't properly working either).
Inside the Lock class, there is the need for a new function,
clear_waiters, which removes all the waiters from the
Process::big_lock. This is needed since after a exit/exec, there should
be no other threads waiting for this lock, the threads should be simply
killed. Only queued threads should wait for this lock at this point,
since blocked threads are handled in set_should_die.
2020-02-18 14:28:28 +02:00
|
|
|
}
|
|
|
|
|
|
2020-02-16 01:27:42 +01:00
|
|
|
}
|