Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
osv
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Verlässliche Systemsoftware
projects
osv
Commits
ec1d09c0
Commit
ec1d09c0
authored
12 years ago
by
Avi Kivity
Browse files
Options
Downloads
Patches
Plain Diff
mutex: allow recusrive locking
prex code depends on this. TODO: make it optional
parent
e74f5a0d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/mutex.cc
+13
-6
13 additions, 6 deletions
core/mutex.cc
include/osv/mutex.h
+2
-0
2 additions, 0 deletions
include/osv/mutex.h
with
15 additions
and
6 deletions
core/mutex.cc
+
13
−
6
View file @
ec1d09c0
...
@@ -14,8 +14,9 @@ extern "C" void mutex_lock(mutex_t *mutex)
...
@@ -14,8 +14,9 @@ extern "C" void mutex_lock(mutex_t *mutex)
w
.
thread
=
sched
::
thread
::
current
();
w
.
thread
=
sched
::
thread
::
current
();
spin_lock
(
&
mutex
->
_wait_lock
);
spin_lock
(
&
mutex
->
_wait_lock
);
if
(
!
mutex
->
_owner
)
{
if
(
!
mutex
->
_owner
||
mutex
->
_owner
==
w
.
thread
)
{
mutex
->
_owner
=
w
.
thread
;
mutex
->
_owner
=
w
.
thread
;
++
mutex
->
_depth
;
spin_unlock
(
&
mutex
->
_wait_lock
);
spin_unlock
(
&
mutex
->
_wait_lock
);
return
;
return
;
}
}
...
@@ -43,8 +44,9 @@ extern "C" bool mutex_trylock(mutex_t *mutex)
...
@@ -43,8 +44,9 @@ extern "C" bool mutex_trylock(mutex_t *mutex)
{
{
bool
ret
=
false
;
bool
ret
=
false
;
spin_lock
(
&
mutex
->
_wait_lock
);
spin_lock
(
&
mutex
->
_wait_lock
);
if
(
!
mutex
->
_owner
)
{
if
(
!
mutex
->
_owner
||
mutex
->
_owner
==
sched
::
thread
::
current
()
)
{
mutex
->
_owner
=
sched
::
thread
::
current
();
mutex
->
_owner
=
sched
::
thread
::
current
();
++
mutex
->
_depth
;
ret
=
true
;
ret
=
true
;
}
}
spin_unlock
(
&
mutex
->
_wait_lock
);
spin_unlock
(
&
mutex
->
_wait_lock
);
...
@@ -54,11 +56,16 @@ extern "C" bool mutex_trylock(mutex_t *mutex)
...
@@ -54,11 +56,16 @@ extern "C" bool mutex_trylock(mutex_t *mutex)
extern
"C"
void
mutex_unlock
(
mutex_t
*
mutex
)
extern
"C"
void
mutex_unlock
(
mutex_t
*
mutex
)
{
{
spin_lock
(
&
mutex
->
_wait_lock
);
spin_lock
(
&
mutex
->
_wait_lock
);
if
(
mutex
->
_wait_list
.
first
)
{
if
(
mutex
->
_depth
==
1
)
{
mutex
->
_owner
=
mutex
->
_wait_list
.
first
->
thread
;
if
(
mutex
->
_wait_list
.
first
)
{
mutex
->
_wait_list
.
first
->
thread
->
wake
();
mutex
->
_owner
=
mutex
->
_wait_list
.
first
->
thread
;
mutex
->
_wait_list
.
first
->
thread
->
wake
();
}
else
{
mutex
->
_owner
=
nullptr
;
--
mutex
->
_depth
;
}
}
else
{
}
else
{
mutex
->
_
owner
=
null
pt
r
;
--
mutex
->
_
de
pt
h
;
}
}
spin_unlock
(
&
mutex
->
_wait_lock
);
spin_unlock
(
&
mutex
->
_wait_lock
);
}
}
...
...
This diff is collapsed.
Click to expand it.
include/osv/mutex.h
+
2
−
0
View file @
ec1d09c0
...
@@ -21,6 +21,7 @@ static inline void spinlock_init(spinlock_t *sl)
...
@@ -21,6 +21,7 @@ static inline void spinlock_init(spinlock_t *sl)
struct
cmutex
{
struct
cmutex
{
spinlock_t
_wait_lock
;
spinlock_t
_wait_lock
;
unsigned
_depth
;
void
*
_owner
;
void
*
_owner
;
struct
wait_list
{
struct
wait_list
{
struct
waiter
*
first
;
struct
waiter
*
first
;
...
@@ -38,6 +39,7 @@ void mutex_unlock(mutex_t* m);
...
@@ -38,6 +39,7 @@ void mutex_unlock(mutex_t* m);
static
__always_inline
void
mutex_init
(
mutex_t
*
m
)
static
__always_inline
void
mutex_init
(
mutex_t
*
m
)
{
{
m
->
_depth
=
0
;
m
->
_owner
=
0
;
m
->
_owner
=
0
;
m
->
_wait_list
.
first
=
0
;
m
->
_wait_list
.
first
=
0
;
m
->
_wait_list
.
last
=
0
;
m
->
_wait_list
.
last
=
0
;
...
...
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