Date: Wed, 17 Nov 1999 19:41:31 -0800 (PST) From: jake@checker.org To: FreeBSD-gnats-submit@freebsd.org Subject: kern/14968: Convert resource_head and resource.r_link from CIRCLEQ to TAILQ Message-ID: <19991118034131.78F481F9D@24.66.174.118.bc.wave.home.com>
index | next in thread | raw e-mail
>Number: 14968
>Category: kern
>Synopsis: Convert resource_head and resource.r_link from CIRCLEQ to TAILQ
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Wed Nov 17 19:50:00 PST 1999
>Closed-Date:
>Last-Modified:
>Originator: Jake Burkholder
>Release: FreeBSD 4.0-CURRENT i386
>Organization:
none
>Environment:
4.0-CURRENT
>Description:
struct resource_head and struct resource.r_link have no business being a
CIRCLEQ. Change them to TAILQ_HEAD and TAILQ_ENTRY respectively.
This removes an ugly macro that should not have been defined locally
in the first place.
>How-To-Repeat:
n/a
>Fix:
Index: sys/rman.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/rman.h,v
retrieving revision 1.3
diff -c -r1.3 rman.h
*** rman.h 1999/08/28 00:51:58 1.3
--- rman.h 1999/11/17 01:34:57
***************
*** 42,50 ****
* address space). That is also why the indices are defined to have type
* `unsigned long' -- that being the largest integral type in Standard C.
*/
! CIRCLEQ_HEAD(resource_head, resource);
struct resource {
! CIRCLEQ_ENTRY(resource) r_link;
LIST_ENTRY(resource) r_sharelink;
LIST_HEAD(, resource) *r_sharehead;
u_long r_start; /* index of the first entry in this resource */
--- 42,50 ----
* address space). That is also why the indices are defined to have type
* `unsigned long' -- that being the largest integral type in Standard C.
*/
! TAILQ_HEAD(resource_head, resource);
struct resource {
! TAILQ_ENTRY(resource) r_link;
LIST_ENTRY(resource) r_sharelink;
LIST_HEAD(, resource) *r_sharehead;
u_long r_start; /* index of the first entry in this resource */
Index: kern/subr_rman.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/subr_rman.c,v
retrieving revision 1.10
diff -c -r1.10 subr_rman.c
*** subr_rman.c 1999/11/16 16:28:57 1.10
--- subr_rman.c 1999/11/17 07:36:58
***************
*** 77,84 ****
static int int_rman_deactivate_resource(struct resource *r);
static int int_rman_release_resource(struct rman *rm, struct resource *r);
- #define CIRCLEQ_TERMCOND(var, head) (var == (void *)&(head))
-
int
rman_init(struct rman *rm)
{
--- 77,82 ----
***************
*** 95,101 ****
if (rm->rm_type == RMAN_GAUGE)
panic("implement RMAN_GAUGE");
! CIRCLEQ_INIT(&rm->rm_list);
rm->rm_slock = malloc(sizeof *rm->rm_slock, M_RMAN, M_NOWAIT);
if (rm->rm_slock == 0)
return ENOMEM;
--- 93,99 ----
if (rm->rm_type == RMAN_GAUGE)
panic("implement RMAN_GAUGE");
! TAILQ_INIT(&rm->rm_list);
rm->rm_slock = malloc(sizeof *rm->rm_slock, M_RMAN, M_NOWAIT);
if (rm->rm_slock == 0)
return ENOMEM;
***************
*** 128,142 ****
r->r_rm = rm;
simple_lock(rm->rm_slock);
! for (s = CIRCLEQ_FIRST(&rm->rm_list);
! !CIRCLEQ_TERMCOND(s, rm->rm_list) && s->r_end < r->r_start;
! s = CIRCLEQ_NEXT(s, r_link))
;
! if (CIRCLEQ_TERMCOND(s, rm->rm_list)) {
! CIRCLEQ_INSERT_TAIL(&rm->rm_list, r, r_link);
} else {
! CIRCLEQ_INSERT_BEFORE(&rm->rm_list, s, r, r_link);
}
simple_unlock(rm->rm_slock);
--- 126,140 ----
r->r_rm = rm;
simple_lock(rm->rm_slock);
! for (s = TAILQ_FIRST(&rm->rm_list);
! s != NULL && s->r_end < r->r_start;
! s = TAILQ_NEXT(s, r_link))
;
! if (s == NULL) {
! TAILQ_INSERT_TAIL(&rm->rm_list, r, r_link);
} else {
! TAILQ_INSERT_BEFORE(s, r, r_link);
}
simple_unlock(rm->rm_slock);
***************
*** 149,155 ****
struct resource *r;
simple_lock(rm->rm_slock);
! CIRCLEQ_FOREACH(r, &rm->rm_list, r_link) {
if (r->r_flags & RF_ALLOCATED) {
simple_unlock(rm->rm_slock);
return EBUSY;
--- 147,153 ----
struct resource *r;
simple_lock(rm->rm_slock);
! TAILQ_FOREACH(r, &rm->rm_list, r_link) {
if (r->r_flags & RF_ALLOCATED) {
simple_unlock(rm->rm_slock);
return EBUSY;
***************
*** 160,168 ****
* There really should only be one of these if we are in this
* state and the code is working properly, but it can't hurt.
*/
! while (!CIRCLEQ_EMPTY(&rm->rm_list)) {
! r = CIRCLEQ_FIRST(&rm->rm_list);
! CIRCLEQ_REMOVE(&rm->rm_list, r, r_link);
free(r, M_RMAN);
}
simple_unlock(rm->rm_slock);
--- 158,166 ----
* There really should only be one of these if we are in this
* state and the code is working properly, but it can't hurt.
*/
! while (!TAILQ_EMPTY(&rm->rm_list)) {
! r = TAILQ_FIRST(&rm->rm_list);
! TAILQ_REMOVE(&rm->rm_list, r, r_link);
free(r, M_RMAN);
}
simple_unlock(rm->rm_slock);
***************
*** 194,205 ****
simple_lock(rm->rm_slock);
! for (r = CIRCLEQ_FIRST(&rm->rm_list);
! !CIRCLEQ_TERMCOND(r, rm->rm_list) && r->r_end < start;
! r = CIRCLEQ_NEXT(r, r_link))
;
! if (CIRCLEQ_TERMCOND(r, rm->rm_list)) {
#ifdef RMAN_DEBUG
printf("could not find a region\n");
#endif RMAN_DEBUG
--- 192,203 ----
simple_lock(rm->rm_slock);
! for (r = TAILQ_FIRST(&rm->rm_list);
! r != NULL && r->r_end < start;
! r = TAILQ_NEXT(r, r_link))
;
! if (r == NULL) {
#ifdef RMAN_DEBUG
printf("could not find a region\n");
#endif RMAN_DEBUG
***************
*** 209,216 ****
/*
* First try to find an acceptable totally-unshared region.
*/
! for (s = r; !CIRCLEQ_TERMCOND(s, rm->rm_list);
! s = CIRCLEQ_NEXT(s, r_link)) {
#ifdef RMAN_DEBUG
printf("considering [%#lx, %#lx]\n", s->r_start, s->r_end);
#endif /* RMAN_DEBUG */
--- 207,213 ----
/*
* First try to find an acceptable totally-unshared region.
*/
! for (s = r; s != NULL; s = TAILQ_NEXT(s, r_link)) {
#ifdef RMAN_DEBUG
printf("considering [%#lx, %#lx]\n", s->r_start, s->r_end);
#endif /* RMAN_DEBUG */
***************
*** 294,302 ****
r->r_sharehead = 0;
r->r_rm = rm;
s->r_end = rv->r_start - 1;
! CIRCLEQ_INSERT_AFTER(&rm->rm_list, s, rv,
r_link);
! CIRCLEQ_INSERT_AFTER(&rm->rm_list, rv, r,
r_link);
} else if (s->r_start == rv->r_start) {
#ifdef RMAN_DEBUG
--- 291,299 ----
r->r_sharehead = 0;
r->r_rm = rm;
s->r_end = rv->r_start - 1;
! TAILQ_INSERT_AFTER(&rm->rm_list, s, rv,
r_link);
! TAILQ_INSERT_AFTER(&rm->rm_list, rv, r,
r_link);
} else if (s->r_start == rv->r_start) {
#ifdef RMAN_DEBUG
***************
*** 306,313 ****
* We are allocating at the beginning.
*/
s->r_start = rv->r_end + 1;
! CIRCLEQ_INSERT_BEFORE(&rm->rm_list, s, rv,
! r_link);
} else {
#ifdef RMAN_DEBUG
printf("allocating at the end\n");
--- 303,309 ----
* We are allocating at the beginning.
*/
s->r_start = rv->r_end + 1;
! TAILQ_INSERT_BEFORE(s, rv, r_link);
} else {
#ifdef RMAN_DEBUG
printf("allocating at the end\n");
***************
*** 316,322 ****
* We are allocating at the end.
*/
s->r_end = rv->r_start - 1;
! CIRCLEQ_INSERT_AFTER(&rm->rm_list, s, rv,
r_link);
}
goto out;
--- 312,318 ----
* We are allocating at the end.
*/
s->r_end = rv->r_start - 1;
! TAILQ_INSERT_AFTER(&rm->rm_list, s, rv,
r_link);
}
goto out;
***************
*** 337,344 ****
if ((flags & (RF_SHAREABLE | RF_TIMESHARE)) == 0)
goto out;
! for (s = r; !CIRCLEQ_TERMCOND(s, rm->rm_list);
! s = CIRCLEQ_NEXT(s, r_link)) {
if (s->r_start > end)
break;
if ((s->r_flags & flags) != flags)
--- 333,339 ----
if ((flags & (RF_SHAREABLE | RF_TIMESHARE)) == 0)
goto out;
! for (s = r; s != NULL; s = TAILQ_NEXT(s, r_link)) {
if (s->r_start > end)
break;
if ((s->r_flags & flags) != flags)
***************
*** 533,540 ****
s = LIST_FIRST(r->r_sharehead);
if (r->r_flags & RF_FIRSTSHARE) {
s->r_flags |= RF_FIRSTSHARE;
! CIRCLEQ_INSERT_BEFORE(&rm->rm_list, r, s, r_link);
! CIRCLEQ_REMOVE(&rm->rm_list, r, r_link);
}
/*
--- 528,535 ----
s = LIST_FIRST(r->r_sharehead);
if (r->r_flags & RF_FIRSTSHARE) {
s->r_flags |= RF_FIRSTSHARE;
! TAILQ_INSERT_BEFORE(r, s, r_link);
! TAILQ_REMOVE(&rm->rm_list, r, r_link);
}
/*
***************
*** 553,584 ****
* Look at the adjacent resources in the list and see if our
* segment can be merged with any of them.
*/
! s = CIRCLEQ_PREV(r, r_link);
! t = CIRCLEQ_NEXT(r, r_link);
! if (s != (void *)&rm->rm_list && (s->r_flags & RF_ALLOCATED) == 0
! && t != (void *)&rm->rm_list && (t->r_flags & RF_ALLOCATED) == 0) {
/*
* Merge all three segments.
*/
s->r_end = t->r_end;
! CIRCLEQ_REMOVE(&rm->rm_list, r, r_link);
! CIRCLEQ_REMOVE(&rm->rm_list, t, r_link);
free(t, M_RMAN);
! } else if (s != (void *)&rm->rm_list
! && (s->r_flags & RF_ALLOCATED) == 0) {
/*
* Merge previous segment with ours.
*/
s->r_end = r->r_end;
! CIRCLEQ_REMOVE(&rm->rm_list, r, r_link);
! } else if (t != (void *)&rm->rm_list
! && (t->r_flags & RF_ALLOCATED) == 0) {
/*
* Merge next segment with ours.
*/
t->r_start = r->r_start;
! CIRCLEQ_REMOVE(&rm->rm_list, r, r_link);
} else {
/*
* At this point, we know there is nothing we
--- 548,577 ----
* Look at the adjacent resources in the list and see if our
* segment can be merged with any of them.
*/
! s = TAILQ_PREV(r, resource_head, r_link);
! t = TAILQ_NEXT(r, r_link);
! if (s != NULL && (s->r_flags & RF_ALLOCATED) == 0
! && t != NULL && (t->r_flags & RF_ALLOCATED) == 0) {
/*
* Merge all three segments.
*/
s->r_end = t->r_end;
! TAILQ_REMOVE(&rm->rm_list, r, r_link);
! TAILQ_REMOVE(&rm->rm_list, t, r_link);
free(t, M_RMAN);
! } else if (s != NULL && (s->r_flags & RF_ALLOCATED) == 0) {
/*
* Merge previous segment with ours.
*/
s->r_end = r->r_end;
! TAILQ_REMOVE(&rm->rm_list, r, r_link);
! } else if (t != NULL && (t->r_flags & RF_ALLOCATED) == 0) {
/*
* Merge next segment with ours.
*/
t->r_start = r->r_start;
! TAILQ_REMOVE(&rm->rm_list, r, r_link);
} else {
/*
* At this point, we know there is nothing we
>Release-Note:
>Audit-Trail:
>Unformatted:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
home |
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19991118034131.78F481F9D>
