BAN: Add more APIs for Atomic and make compare_exchage take a reference
This commit is contained in:
@@ -24,8 +24,12 @@ namespace Kernel
|
||||
ASSERT(m_lock_depth > 0);
|
||||
else
|
||||
{
|
||||
while (!m_locker.compare_exchange(-1, tid))
|
||||
pid_t expected = -1;
|
||||
while (!m_locker.compare_exchange(expected, tid))
|
||||
{
|
||||
Scheduler::get().yield();
|
||||
expected = -1;
|
||||
}
|
||||
ASSERT(m_lock_depth == 0);
|
||||
if (Scheduler::current_tid())
|
||||
Thread::current().add_mutex();
|
||||
@@ -40,7 +44,8 @@ namespace Kernel
|
||||
ASSERT(m_lock_depth > 0);
|
||||
else
|
||||
{
|
||||
if (!m_locker.compare_exchange(-1, tid))
|
||||
pid_t expected = -1;
|
||||
if (!m_locker.compare_exchange(expected, tid))
|
||||
return false;
|
||||
ASSERT(m_lock_depth == 0);
|
||||
if (Scheduler::current_tid())
|
||||
@@ -89,8 +94,12 @@ namespace Kernel
|
||||
bool has_priority = tid ? !Thread::current().is_userspace() : true;
|
||||
if (has_priority)
|
||||
m_queue_length++;
|
||||
while (!(has_priority || m_queue_length == 0) || !m_locker.compare_exchange(-1, tid))
|
||||
pid_t expected = -1;
|
||||
while (!(has_priority || m_queue_length == 0) || !m_locker.compare_exchange(expected, tid))
|
||||
{
|
||||
Scheduler::get().yield();
|
||||
expected = -1;
|
||||
}
|
||||
ASSERT(m_lock_depth == 0);
|
||||
if (Scheduler::current_tid())
|
||||
Thread::current().add_mutex();
|
||||
@@ -106,7 +115,8 @@ namespace Kernel
|
||||
else
|
||||
{
|
||||
bool has_priority = tid ? !Thread::current().is_userspace() : true;
|
||||
if (!(has_priority || m_queue_length == 0) || !m_locker.compare_exchange(-1, tid))
|
||||
pid_t expected = -1;
|
||||
if (!(has_priority || m_queue_length == 0) || !m_locker.compare_exchange(expected, tid))
|
||||
return false;
|
||||
if (has_priority)
|
||||
m_queue_length++;
|
||||
|
||||
@@ -26,8 +26,12 @@ namespace Kernel
|
||||
auto id = Processor::current_id();
|
||||
ASSERT(m_locker != id);
|
||||
|
||||
while (!m_locker.compare_exchange(PROCESSOR_NONE, id, BAN::MemoryOrder::memory_order_acquire))
|
||||
ProcessorID expected = PROCESSOR_NONE;
|
||||
while (!m_locker.compare_exchange(expected, id, BAN::MemoryOrder::memory_order_acquire))
|
||||
{
|
||||
__builtin_ia32_pause();
|
||||
expected = PROCESSOR_NONE;
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
@@ -67,8 +71,12 @@ namespace Kernel
|
||||
ASSERT(m_lock_depth > 0);
|
||||
else
|
||||
{
|
||||
while (!m_locker.compare_exchange(PROCESSOR_NONE, id, BAN::MemoryOrder::memory_order_acquire))
|
||||
ProcessorID expected = PROCESSOR_NONE;
|
||||
while (!m_locker.compare_exchange(expected, id, BAN::MemoryOrder::memory_order_acquire))
|
||||
{
|
||||
__builtin_ia32_pause();
|
||||
expected = PROCESSOR_NONE;
|
||||
}
|
||||
ASSERT(m_lock_depth == 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -346,7 +346,8 @@ namespace Kernel
|
||||
if (m_info.has<ConnectionInfo>())
|
||||
{
|
||||
auto& connection_info = m_info.get<ConnectionInfo>();
|
||||
if (connection_info.target_closed.compare_exchange(true, false))
|
||||
bool expected = true;
|
||||
if (connection_info.target_closed.compare_exchange(expected, false))
|
||||
return 0;
|
||||
if (!connection_info.connection)
|
||||
return BAN::Error::from_errno(ENOTCONN);
|
||||
|
||||
Reference in New Issue
Block a user