[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gnulib and threaded execution
From: |
Paul Eggert |
Subject: |
Re: gnulib and threaded execution |
Date: |
Tue, 28 Dec 2010 20:44:23 -0800 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7 |
On 12/02/2010 04:39 PM, Paul Eggert wrote:
> This should be fixable by making 'addr' auto instead of static, no?
> Something like the following (untested) patch.
No further comment on that, so I installed it:
>From b9d6ad8aec25d6b7a01a70b7ebc0dc7c221f1cf6 Mon Sep 17 00:00:00 2001
From: Paul Eggert <address@hidden>
Date: Tue, 28 Dec 2010 20:41:30 -0800
Subject: [PATCH] alloca: one step towards thread-safety
* lib/alloca.c (find_stack_direction): New arg PTR, to avoid the
need for a static variable. All callers changed. This does not
make the alloca replacement thread-safe, but it's one step.
---
ChangeLog | 5 +++++
lib/alloca.c | 16 +++++++++-------
2 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 2c9d4c7..5c95bc4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2010-12-28 Paul Eggert <address@hidden>
+ alloca: one step towards thread-safety
+ * lib/alloca.c (find_stack_direction): New arg PTR, to avoid the
+ need for a static variable. All callers changed. This does not
+ make the alloca replacement thread-safe, but it's one step.
+
tests: minor indenting change
* tests/init.sh: Sync from coreutils housekeeping patch
<http://lists.gnu.org/archive/html/coreutils/2010-12/msg00116.html>
diff --git a/lib/alloca.c b/lib/alloca.c
index b652765..2f5e27e 100644
--- a/lib/alloca.c
+++ b/lib/alloca.c
@@ -94,21 +94,20 @@ static int stack_dir; /* 1 or -1 once known. */
# define STACK_DIR stack_dir
static void
-find_stack_direction (void)
+find_stack_direction (char **ptr)
{
- static char *addr = NULL; /* Address of first `dummy', once known. */
auto char dummy; /* To get stack address. */
- if (addr == NULL)
+ if (*ptr == NULL)
{ /* Initial entry. */
- addr = ADDRESS_FUNCTION (dummy);
+ *ptr = ADDRESS_FUNCTION (dummy);
- find_stack_direction (); /* Recurse once. */
+ find_stack_direction (ptr); /* Recurse once. */
}
else
{
/* Second entry. */
- if (ADDRESS_FUNCTION (dummy) > addr)
+ if (ADDRESS_FUNCTION (dummy) > *ptr)
stack_dir = 1; /* Stack grew upward. */
else
stack_dir = -1; /* Stack grew downward. */
@@ -155,7 +154,10 @@ alloca (size_t size)
# if STACK_DIRECTION == 0
if (STACK_DIR == 0) /* Unknown growth direction. */
- find_stack_direction ();
+ {
+ char *addr = NULL; /* Address of first `dummy', once known. */
+ find_stack_direction (&addr);
+ }
# endif
/* Reclaim garbage, defined as all alloca'd storage that
--
1.7.2