Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F147907918
D54143.1784755302.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
D54143.1784755302.diff
View Options
diff --git a/sys/kern/subr_rman.c b/sys/kern/subr_rman.c
--- a/sys/kern/subr_rman.c
+++ b/sys/kern/subr_rman.c
@@ -131,10 +131,7 @@
panic("implement RMAN_GAUGE");
TAILQ_INIT(&rm->rm_list);
- rm->rm_mtx = malloc(sizeof *rm->rm_mtx, M_RMAN, M_NOWAIT | M_ZERO);
- if (rm->rm_mtx == NULL)
- return ENOMEM;
- mtx_init(rm->rm_mtx, "rman", NULL, MTX_DEF);
+ mtx_init(&rm->rm_mtx, "rman", NULL, MTX_DEF);
mtx_lock(&rman_mtx);
TAILQ_INSERT_TAIL(&rman_head, rm, rm_link);
@@ -159,7 +156,7 @@
r->r_end = end;
r->r_rm = rm;
- mtx_lock(rm->rm_mtx);
+ mtx_lock(&rm->rm_mtx);
/* Skip entries before us. */
TAILQ_FOREACH(s, &rm->rm_list, r_link) {
@@ -216,7 +213,7 @@
}
}
out:
- mtx_unlock(rm->rm_mtx);
+ mtx_unlock(&rm->rm_mtx);
return rv;
}
@@ -235,10 +232,10 @@
{
struct resource_i *r;
- mtx_lock(rm->rm_mtx);
+ mtx_lock(&rm->rm_mtx);
TAILQ_FOREACH(r, &rm->rm_list, r_link) {
if (r->r_flags & RF_ALLOCATED) {
- mtx_unlock(rm->rm_mtx);
+ mtx_unlock(&rm->rm_mtx);
return EBUSY;
}
}
@@ -252,12 +249,11 @@
TAILQ_REMOVE(&rm->rm_list, r, r_link);
free(r, M_RMAN);
}
- mtx_unlock(rm->rm_mtx);
+ mtx_unlock(&rm->rm_mtx);
mtx_lock(&rman_mtx);
TAILQ_REMOVE(&rman_head, rm, rm_link);
mtx_unlock(&rman_mtx);
- mtx_destroy(rm->rm_mtx);
- free(rm->rm_mtx, M_RMAN);
+ mtx_destroy(&rm->rm_mtx);
return 0;
}
@@ -267,16 +263,16 @@
{
struct resource_i *r;
- mtx_lock(rm->rm_mtx);
+ mtx_lock(&rm->rm_mtx);
TAILQ_FOREACH(r, &rm->rm_list, r_link) {
if (!(r->r_flags & RF_ALLOCATED)) {
*start = r->r_start;
*end = r->r_end;
- mtx_unlock(rm->rm_mtx);
+ mtx_unlock(&rm->rm_mtx);
return (0);
}
}
- mtx_unlock(rm->rm_mtx);
+ mtx_unlock(&rm->rm_mtx);
return (ENOENT);
}
@@ -285,16 +281,16 @@
{
struct resource_i *r;
- mtx_lock(rm->rm_mtx);
+ mtx_lock(&rm->rm_mtx);
TAILQ_FOREACH_REVERSE(r, &rm->rm_list, resource_head, r_link) {
if (!(r->r_flags & RF_ALLOCATED)) {
*start = r->r_start;
*end = r->r_end;
- mtx_unlock(rm->rm_mtx);
+ mtx_unlock(&rm->rm_mtx);
return (0);
}
}
- mtx_unlock(rm->rm_mtx);
+ mtx_unlock(&rm->rm_mtx);
return (ENOENT);
}
@@ -323,7 +319,7 @@
* allocated resource.
*/
rm = r->r_rm;
- mtx_lock(rm->rm_mtx);
+ mtx_lock(&rm->rm_mtx);
#ifdef INVARIANTS
TAILQ_FOREACH(s, &rm->rm_list, r_link) {
if (s == r)
@@ -345,12 +341,12 @@
*/
if (start < r->r_start && (s == NULL || (s->r_flags & RF_ALLOCATED) ||
s->r_start > start)) {
- mtx_unlock(rm->rm_mtx);
+ mtx_unlock(&rm->rm_mtx);
return (EBUSY);
}
if (end > r->r_end && (t == NULL || (t->r_flags & RF_ALLOCATED) ||
t->r_end < end)) {
- mtx_unlock(rm->rm_mtx);
+ mtx_unlock(&rm->rm_mtx);
return (EBUSY);
}
@@ -380,7 +376,7 @@
} else
t->r_start = end + 1;
}
- mtx_unlock(rm->rm_mtx);
+ mtx_unlock(&rm->rm_mtx);
/*
* Handle the shrinking cases that require allocating a new
@@ -392,7 +388,7 @@
new->r_start = r->r_start;
new->r_end = start - 1;
new->r_rm = rm;
- mtx_lock(rm->rm_mtx);
+ mtx_lock(&rm->rm_mtx);
r->r_start = start;
s = TAILQ_PREV(r, resource_head, r_link);
if (s != NULL && !(s->r_flags & RF_ALLOCATED)) {
@@ -400,14 +396,14 @@
free(new, M_RMAN);
} else
TAILQ_INSERT_BEFORE(r, new, r_link);
- mtx_unlock(rm->rm_mtx);
+ mtx_unlock(&rm->rm_mtx);
}
if (end < r->r_end) {
new = int_alloc_resource(M_WAITOK);
new->r_start = end + 1;
new->r_end = r->r_end;
new->r_rm = rm;
- mtx_lock(rm->rm_mtx);
+ mtx_lock(&rm->rm_mtx);
r->r_end = end;
t = TAILQ_NEXT(r, r_link);
if (t != NULL && !(t->r_flags & RF_ALLOCATED)) {
@@ -415,7 +411,7 @@
free(new, M_RMAN);
} else
TAILQ_INSERT_AFTER(&rm->rm_list, r, new, r_link);
- mtx_unlock(rm->rm_mtx);
+ mtx_unlock(&rm->rm_mtx);
}
return (0);
}
@@ -441,7 +437,7 @@
("invalid flags %#x", flags));
new_rflags = (flags & ~RF_FIRSTSHARE) | RF_ALLOCATED;
- mtx_lock(rm->rm_mtx);
+ mtx_lock(&rm->rm_mtx);
r = TAILQ_FIRST(&rm->rm_list);
if (r == NULL)
@@ -628,7 +624,7 @@
*/
out:
- mtx_unlock(rm->rm_mtx);
+ mtx_unlock(&rm->rm_mtx);
return (rv == NULL ? NULL : &rv->r_r);
}
@@ -640,9 +636,9 @@
r = re->__r_i;
rm = r->r_rm;
- mtx_lock(rm->rm_mtx);
+ mtx_lock(&rm->rm_mtx);
r->r_flags |= RF_ACTIVE;
- mtx_unlock(rm->rm_mtx);
+ mtx_unlock(&rm->rm_mtx);
return 0;
}
@@ -652,9 +648,9 @@
struct rman *rm;
rm = r->__r_i->r_rm;
- mtx_lock(rm->rm_mtx);
+ mtx_lock(&rm->rm_mtx);
r->__r_i->r_flags &= ~RF_ACTIVE;
- mtx_unlock(rm->rm_mtx);
+ mtx_unlock(&rm->rm_mtx);
return 0;
}
@@ -761,9 +757,9 @@
r = re->__r_i;
rm = r->r_rm;
- mtx_lock(rm->rm_mtx);
+ mtx_lock(&rm->rm_mtx);
rv = int_rman_release_resource(rm, r);
- mtx_unlock(rm->rm_mtx);
+ mtx_unlock(&rm->rm_mtx);
return (rv);
}
@@ -991,7 +987,7 @@
/*
* Find the indexed resource and return it.
*/
- mtx_lock(rm->rm_mtx);
+ mtx_lock(&rm->rm_mtx);
TAILQ_FOREACH(res, &rm->rm_list, r_link) {
if (res->r_sharehead != NULL) {
LIST_FOREACH(sres, res->r_sharehead, r_sharelink)
@@ -1003,7 +999,7 @@
else if (res_idx-- == 0)
goto found;
}
- mtx_unlock(rm->rm_mtx);
+ mtx_unlock(&rm->rm_mtx);
return (ENOENT);
found:
@@ -1028,7 +1024,7 @@
ures.r_size = res->r_end - res->r_start + 1;
ures.r_flags = res->r_flags;
- mtx_unlock(rm->rm_mtx);
+ mtx_unlock(&rm->rm_mtx);
error = SYSCTL_OUT(req, &ures, sizeof(ures));
return (error);
}
diff --git a/sys/sys/rman.h b/sys/sys/rman.h
--- a/sys/sys/rman.h
+++ b/sys/sys/rman.h
@@ -35,6 +35,7 @@
#ifndef _KERNEL
#include <sys/queue.h>
#else
+#include <sys/_mutex.h>
#include <machine/_bus.h>
#include <machine/resource.h>
#endif
@@ -112,7 +113,7 @@
struct rman {
struct resource_head rm_list;
- struct mtx *rm_mtx; /* mutex used to protect rm_list */
+ struct mtx rm_mtx; /* mutex used to protect rm_list */
TAILQ_ENTRY(rman) rm_link; /* link in list of all rmans */
rman_res_t rm_start; /* index of globally first entry */
rman_res_t rm_end; /* index of globally last entry */
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Jul 22, 9:21 PM (14 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29231340
Default Alt Text
D54143.1784755302.diff (5 KB)
Attached To
Mode
D54143: rman: Embed the mutex in struct rman instead of using a separate allocation
Attached
Detach File
Event Timeline
Log In to Comment