This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] remove one nested function from nptl/allocatestack.c
- From: Konstantin Serebryany <konstantin dot s dot serebryany at gmail dot com>
- To: Roland McGrath <roland at hack dot frob dot com>
- Cc: GNU C Library <libc-alpha at sourceware dot org>
- Date: Thu, 5 Jun 2014 12:53:10 +0400
- Subject: Re: [PATCH] remove one nested function from nptl/allocatestack.c
- Authentication-results: sourceware.org; auth=none
- References: <CAGQ9bdw9_bgxZ3UOMNnnMC7EXtyUbBs5AkHvEF3jT0uB3GhaSg at mail dot gmail dot com> <20140604171623 dot 362652C39B4 at topped-with-meat dot com>
Bool is easy, done. (I did not realize that this code uses bool. Great!)
Comments are harder -- I do not feel comfortable re-commenting someone
else's code.
Do you have a suggestion?
On Wed, Jun 4, 2014 at 9:16 PM, Roland McGrath <roland@hack.frob.com> wrote:
> That is fine, though it wouldn't hurt to improve the commentary and use
> bool while you're there.
diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c
index 1e22f7d..359c444 100644
--- a/nptl/allocatestack.c
+++ b/nptl/allocatestack.c
@@ -809,6 +809,24 @@ __make_stacks_executable (void **stack_endp)
return err;
}
+/* We always add at the beginning of the list. So in this
+ case we only need to check the beginning of these lists. */
+static bool
+check_list (list_t *l, list_t *elem)
+{
+ if (l->next->prev != l)
+ {
+ assert (l->next->prev == elem);
+
+ elem->next = l->next;
+ elem->prev = l;
+ l->next = elem;
+
+ return true;
+ }
+
+ return false;
+}
/* In case of a fork() call the memory allocation in the child will be
the same but only one thread is running. All stacks except that of
@@ -830,26 +848,8 @@ __reclaim_stacks (void)
if (add_p)
{
- /* We always add at the beginning of the list. So in this
- case we only need to check the beginning of these lists. */
- int check_list (list_t *l)
- {
- if (l->next->prev != l)
- {
- assert (l->next->prev == elem);
-
- elem->next = l->next;
- elem->prev = l;
- l->next = elem;
-
- return 1;
- }
-
- return 0;
- }
-
- if (check_list (&stack_used) == 0)
- (void) check_list (&stack_cache);
+ if (!check_list (&stack_used, elem))
+ (void) check_list (&stack_cache, elem);
}
else
{