Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Suyu
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
many-archive
Suyu
Commits
7322c99e
There was an error fetching the commit references. Please try again later.
Commit
7322c99e
authored
2 years ago
by
Liam
Browse files
Options
Downloads
Patches
Plain Diff
kernel: convert KAbstractSchedulerLock
parent
467adc1a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/core/hle/kernel/k_scheduler_lock.h
+24
-31
24 additions, 31 deletions
src/core/hle/kernel/k_scheduler_lock.h
with
24 additions
and
31 deletions
src/core/hle/kernel/k_scheduler_lock.h
+
24
−
31
View file @
7322c99e
...
@@ -14,74 +14,67 @@
...
@@ -14,74 +14,67 @@
namespace
Kernel
{
namespace
Kernel
{
class
KernelCore
;
class
KernelCore
;
class
GlobalSchedulerContext
;
template
<
typename
SchedulerType
>
template
<
typename
SchedulerType
>
class
KAbstractSchedulerLock
{
class
KAbstractSchedulerLock
{
public:
public:
explicit
KAbstractSchedulerLock
(
KernelCore
&
kernel
_
)
:
kernel
{
kernel
_
}
{}
explicit
KAbstractSchedulerLock
(
KernelCore
&
kernel
)
:
m_
kernel
{
kernel
}
{}
bool
IsLockedByCurrentThread
()
const
{
bool
IsLockedByCurrentThread
()
const
{
return
owner_thread
==
GetCurrentThreadPointer
(
kernel
);
return
m_
owner_thread
==
GetCurrentThreadPointer
(
m_
kernel
);
}
}
void
Lock
()
{
void
Lock
()
{
// If we are shutting down the kernel, none of this is relevant anymore.
if
(
this
->
IsLockedByCurrentThread
())
{
if
(
kernel
.
IsShuttingDown
())
{
return
;
}
if
(
IsLockedByCurrentThread
())
{
// If we already own the lock, the lock count should be > 0.
// If we already own the lock, the lock count should be > 0.
// For debug, ensure this is true.
// For debug, ensure this is true.
ASSERT
(
lock_count
>
0
);
ASSERT
(
m_
lock_count
>
0
);
}
else
{
}
else
{
// Otherwise, we want to disable scheduling and acquire the spinlock.
// Otherwise, we want to disable scheduling and acquire the spinlock.
SchedulerType
::
DisableScheduling
(
kernel
);
SchedulerType
::
DisableScheduling
(
m_
kernel
);
spin_lock
.
Lock
();
m_
spin_lock
.
Lock
();
ASSERT
(
lock_count
==
0
);
ASSERT
(
m_
lock_count
==
0
);
ASSERT
(
owner_thread
==
nullptr
);
ASSERT
(
m_
owner_thread
==
nullptr
);
// Take ownership of the lock.
// Take ownership of the lock.
owner_thread
=
GetCurrentThreadPointer
(
kernel
);
m_
owner_thread
=
GetCurrentThreadPointer
(
m_
kernel
);
}
}
// Increment the lock count.
// Increment the lock count.
lock_count
++
;
m_
lock_count
++
;
}
}
void
Unlock
()
{
void
Unlock
()
{
// If we are shutting down the kernel, none of this is relevant anymore.
ASSERT
(
this
->
IsLockedByCurrentThread
());
if
(
kernel
.
IsShuttingDown
())
{
ASSERT
(
m_lock_count
>
0
);
return
;
}
ASSERT
(
IsLockedByCurrentThread
());
ASSERT
(
lock_count
>
0
);
// Release an instance of the lock.
// Release an instance of the lock.
if
((
--
lock_count
)
==
0
)
{
if
((
--
m_
lock_count
)
==
0
)
{
// Perform a memory barrier here.
// Perform a memory barrier here.
std
::
atomic_thread_fence
(
std
::
memory_order_seq_cst
);
std
::
atomic_thread_fence
(
std
::
memory_order_seq_cst
);
// We're no longer going to hold the lock. Take note of what cores need scheduling.
// We're no longer going to hold the lock. Take note of what cores need scheduling.
const
u64
cores_needing_scheduling
=
const
u64
cores_needing_scheduling
=
SchedulerType
::
UpdateHighestPriorityThreads
(
kernel
);
SchedulerType
::
UpdateHighestPriorityThreads
(
m_
kernel
);
// Note that we no longer hold the lock, and unlock the spinlock.
// Note that we no longer hold the lock, and unlock the spinlock.
owner_thread
=
nullptr
;
m_
owner_thread
=
nullptr
;
spin_lock
.
Unlock
();
m_
spin_lock
.
Unlock
();
// Enable scheduling, and perform a rescheduling operation.
// Enable scheduling, and perform a rescheduling operation.
SchedulerType
::
EnableScheduling
(
kernel
,
cores_needing_scheduling
);
SchedulerType
::
EnableScheduling
(
m_
kernel
,
cores_needing_scheduling
);
}
}
}
}
private
:
private
:
KernelCore
&
kernel
;
friend
class
GlobalSchedulerContext
;
KAlignedSpinLock
spin_lock
{};
s32
lock_count
{};
KernelCore
&
m_kernel
;
std
::
atomic
<
KThread
*>
owner_thread
{};
KAlignedSpinLock
m_spin_lock
{};
s32
m_lock_count
{};
std
::
atomic
<
KThread
*>
m_owner_thread
{};
};
};
}
// namespace Kernel
}
// namespace Kernel
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment