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
c8ff89a5
Commit
c8ff89a5
authored
12 years ago
by
Guy Zana
Browse files
Options
Downloads
Patches
Plain Diff
Added rwlock stub, which is basically a mutex that can be taken recursively
parent
0264797f
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
bsd/porting/rwlock.c
+36
-29
36 additions, 29 deletions
bsd/porting/rwlock.c
bsd/porting/rwlock.h
+8
-18
8 additions, 18 deletions
bsd/porting/rwlock.h
core/mutex.cc
+5
-0
5 additions, 0 deletions
core/mutex.cc
include/osv/mutex.h
+2
-0
2 additions, 0 deletions
include/osv/mutex.h
with
51 additions
and
47 deletions
bsd/porting/rwlock.c
+
36
−
29
View file @
c8ff89a5
#include
<assert.h>
#include
<stdint.h>
#include
<osv/mutex.h>
#include
<bsd/porting/netport.h>
#include
<bsd/porting/rwlock.h>
void
rw_init_flags
(
struct
rwlock
*
rw
,
const
char
*
name
,
int
opts
)
{
u_int
flags
=
0
;
}
void
rw_destroy
(
struct
rwlock
*
rw
)
{
}
void
rw_sysinit
(
void
*
arg
)
{
if
(
opts
&
RW_RECURSE
)
flags
|=
LO_RECURSABLE
;
mutex_init
(
&
rw
->
_mutex
);
rw
->
_rw_recurse
=
0
;
rw
->
_lo_flags
=
flags
|
LO_INITIALIZED
;
}
void
rw_
sysinit_flags
(
void
*
arg
)
void
rw_
destroy
(
struct
rwlock
*
rw
)
{
assert
(
rw
->
_rw_recurse
==
0
);
mutex_destroy
(
&
rw
->
_mutex
);
}
int
rw_wowned
(
struct
rwlock
*
rw
)
{
return
(
0
);
/* Is owned by current thread */
return
(
mutex_owned
(
&
rw
->
_mutex
));
}
void
_rw_wlock
(
struct
rwlock
*
rw
,
const
char
*
file
,
int
line
)
{
_rw_rlock
(
rw
,
file
,
line
);
}
int
_rw_try_wlock
(
struct
rwlock
*
rw
,
const
char
*
file
,
int
line
)
{
return
(
0
);
return
(
_rw_try_rlock
(
rw
,
file
,
line
)
);
}
void
_rw_wunlock
(
struct
rwlock
*
rw
,
const
char
*
file
,
int
line
)
{
_rw_runlock
(
rw
,
file
,
line
);
}
void
_rw_rlock
(
struct
rwlock
*
rw
,
const
char
*
file
,
int
line
)
{
if
(
rw_wowned
(
rw
))
{
rw
->
_rw_recurse
++
;
}
else
{
mutex_lock
(
&
rw
->
_mutex
);
}
}
int
_rw_try_rlock
(
struct
rwlock
*
rw
,
const
char
*
file
,
int
line
)
{
return
(
0
);
}
void
_rw_runlock
(
struct
rwlock
*
rw
,
const
char
*
file
,
int
line
)
{
if
(
rw_wowned
(
rw
))
{
rw
->
_rw_recurse
++
;
return
(
1
);
}
return
(
mutex_trylock
(
&
rw
->
_mutex
));
}
void
_rw_wlock_hard
(
struct
rwlock
*
rw
,
uintptr_t
tid
,
const
char
*
file
,
int
line
)
{
}
void
_rw_wunlock_hard
(
struct
rwlock
*
rw
,
uintptr_t
tid
,
const
char
*
file
,
int
line
)
void
_rw_runlock
(
struct
rwlock
*
rw
,
const
char
*
file
,
int
line
)
{
if
(
rw
->
_rw_recurse
>
0
)
{
rw
->
_rw_recurse
--
;
}
if
(
rw
->
_rw_recurse
==
0
)
{
mutex_unlock
(
&
rw
->
_mutex
);
}
}
int
_rw_try_upgrade
(
struct
rwlock
*
rw
,
const
char
*
file
,
int
line
)
{
return
(
0
);
/* The lock is already exclusive... */
return
(
1
);
}
void
_rw_downgrade
(
struct
rwlock
*
rw
,
const
char
*
file
,
int
line
)
{
/* No-op */
}
This diff is collapsed.
Click to expand it.
bsd/porting/rwlock.h
+
8
−
18
View file @
c8ff89a5
...
...
@@ -35,8 +35,14 @@
#include
<bsd/porting/netport.h>
#include
<osv/mutex.h>
#define LO_INITIALIZED 0x00010000
/* Lock has been initialized. */
#define LO_RECURSABLE 0x00080000
/* Lock may recurse. */
struct
rwlock
{
mutex_t
_osv_mtx
;
mutex_t
_mutex
;
/* Use a sleeping mutex */
u_int
_rw_recurse
;
/* Counter for recursion support */
u_int
_lo_flags
;
/* Allow threads to recursively acquire
exclusive locks for rw */
};
#define LOCK_FILE __FILE__
...
...
@@ -51,8 +57,6 @@ struct rwlock {
#define rw_init(rw, name) rw_init_flags((rw), (name), 0)
void
rw_init_flags
(
struct
rwlock
*
rw
,
const
char
*
name
,
int
opts
);
void
rw_destroy
(
struct
rwlock
*
rw
);
void
rw_sysinit
(
void
*
arg
);
void
rw_sysinit_flags
(
void
*
arg
);
int
rw_wowned
(
struct
rwlock
*
rw
);
void
_rw_wlock
(
struct
rwlock
*
rw
,
const
char
*
file
,
int
line
);
int
_rw_try_wlock
(
struct
rwlock
*
rw
,
const
char
*
file
,
int
line
);
...
...
@@ -60,10 +64,6 @@ void _rw_wunlock(struct rwlock *rw, const char *file, int line);
void
_rw_rlock
(
struct
rwlock
*
rw
,
const
char
*
file
,
int
line
);
int
_rw_try_rlock
(
struct
rwlock
*
rw
,
const
char
*
file
,
int
line
);
void
_rw_runlock
(
struct
rwlock
*
rw
,
const
char
*
file
,
int
line
);
void
_rw_wlock_hard
(
struct
rwlock
*
rw
,
uintptr_t
tid
,
const
char
*
file
,
int
line
);
void
_rw_wunlock_hard
(
struct
rwlock
*
rw
,
uintptr_t
tid
,
const
char
*
file
,
int
line
);
int
_rw_try_upgrade
(
struct
rwlock
*
rw
,
const
char
*
file
,
int
line
);
void
_rw_downgrade
(
struct
rwlock
*
rw
,
const
char
*
file
,
int
line
);
...
...
@@ -86,17 +86,7 @@ void _rw_downgrade(struct rwlock *rw, const char *file, int line);
rw_runlock(rw); \
} while (0)
struct
rw_args
{
struct
rwlock
*
ra_rw
;
const
char
*
ra_desc
;
};
struct
rw_args_flags
{
struct
rwlock
*
ra_rw
;
const
char
*
ra_desc
;
int
ra_flags
;
};
/* Disable static initialization */
#define RW_SYSINIT(name, rw, desc)
#define RW_SYSINIT_FLAGS(name, rw, desc, flags)
...
...
This diff is collapsed.
Click to expand it.
core/mutex.cc
+
5
−
0
View file @
c8ff89a5
...
...
@@ -60,6 +60,11 @@ extern "C" void mutex_unlock(mutex_t *mutex)
spin_unlock
(
&
mutex
->
_wait_lock
);
}
extern
"C"
bool
mutex_owned
(
mutex_t
*
mutex
)
{
return
(
mutex
->
_owner
==
sched
::
thread
::
current
());
}
void
mutex
::
lock
()
{
mutex_lock
(
&
_mutex
);
...
...
This diff is collapsed.
Click to expand it.
include/osv/mutex.h
+
2
−
0
View file @
c8ff89a5
...
...
@@ -36,6 +36,8 @@ typedef struct cmutex mutex_t;
void
mutex_lock
(
mutex_t
*
m
);
bool
mutex_trylock
(
mutex_t
*
m
);
void
mutex_unlock
(
mutex_t
*
m
);
/* Is owned by current thread */
bool
mutex_owned
(
mutex_t
*
m
);
static
__always_inline
void
mutex_init
(
mutex_t
*
m
)
{
...
...
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