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
1b0bf00c
There was an error fetching the commit references. Please try again later.
Commit
1b0bf00c
authored
10 years ago
by
bunnei
Browse files
Options
Downloads
Patches
Plain Diff
Mutex: Locks should be recursive.
parent
caa58acc
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/core/hle/kernel/mutex.cpp
+19
-14
19 additions, 14 deletions
src/core/hle/kernel/mutex.cpp
src/core/hle/kernel/mutex.h
+1
-2
1 addition, 2 deletions
src/core/hle/kernel/mutex.h
with
20 additions
and
16 deletions
src/core/hle/kernel/mutex.cpp
+
19
−
14
View file @
1b0bf00c
...
...
@@ -21,7 +21,7 @@ namespace Kernel {
*/
static
void
ResumeWaitingThread
(
Mutex
*
mutex
)
{
// Reset mutex lock thread handle, nothing is waiting
mutex
->
lock
ed
=
false
;
mutex
->
lock
_count
=
0
;
mutex
->
holding_thread
=
nullptr
;
// Find the next waiting thread for the mutex...
...
...
@@ -44,8 +44,7 @@ Mutex::~Mutex() {}
SharedPtr
<
Mutex
>
Mutex
::
Create
(
bool
initial_locked
,
std
::
string
name
)
{
SharedPtr
<
Mutex
>
mutex
(
new
Mutex
);
mutex
->
initial_locked
=
initial_locked
;
mutex
->
locked
=
false
;
mutex
->
lock_count
=
0
;
mutex
->
name
=
std
::
move
(
name
);
mutex
->
holding_thread
=
nullptr
;
...
...
@@ -57,7 +56,7 @@ SharedPtr<Mutex> Mutex::Create(bool initial_locked, std::string name) {
}
bool
Mutex
::
ShouldWait
()
{
return
lock
ed
&&
holding_thread
!=
GetCurrentThread
();
return
lock
_count
>
0
&&
holding_thread
!=
GetCurrentThread
();
;
}
void
Mutex
::
Acquire
()
{
...
...
@@ -66,21 +65,27 @@ void Mutex::Acquire() {
void
Mutex
::
Acquire
(
SharedPtr
<
Thread
>
thread
)
{
_assert_msg_
(
Kernel
,
!
ShouldWait
(),
"object unavailable!"
);
if
(
locked
)
return
;
locked
=
true
;
// Actually "acquire" the mutex only if we don't already have it...
if
(
lock_count
==
0
)
{
thread
->
held_mutexes
.
insert
(
this
);
holding_thread
=
std
::
move
(
thread
);
}
thread
->
held_mutexes
.
insert
(
this
);
holding_thread
=
std
::
move
(
thread
);
lock_count
++
;
}
void
Mutex
::
Release
()
{
if
(
!
locked
)
return
;
holding_thread
->
held_mutexes
.
erase
(
this
);
ResumeWaitingThread
(
this
);
// Only release if the mutex is held...
if
(
lock_count
>
0
)
{
lock_count
--
;
// Yield to the next thread only if we've fully released the mutex...
if
(
lock_count
==
0
)
{
holding_thread
->
held_mutexes
.
erase
(
this
);
ResumeWaitingThread
(
this
);
}
}
}
}
// namespace
This diff is collapsed.
Click to expand it.
src/core/hle/kernel/mutex.h
+
1
−
2
View file @
1b0bf00c
...
...
@@ -30,8 +30,7 @@ public:
static
const
HandleType
HANDLE_TYPE
=
HandleType
::
Mutex
;
HandleType
GetHandleType
()
const
override
{
return
HANDLE_TYPE
;
}
bool
initial_locked
;
///< Initial lock state when mutex was created
bool
locked
;
///< Current locked state
int
lock_count
;
///< Number of times the mutex has been acquired
std
::
string
name
;
///< Name of mutex (optional)
SharedPtr
<
Thread
>
holding_thread
;
///< Thread that has acquired the mutex
...
...
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