diff options
Diffstat (limited to 'c/src')
-rw-r--r-- | c/src/exec/libcsupport/src/envlock.c | 30 | ||||
-rw-r--r-- | c/src/lib/ChangeLog | 6 | ||||
-rw-r--r-- | c/src/lib/libc/envlock.c | 30 |
3 files changed, 62 insertions, 4 deletions
diff --git a/c/src/exec/libcsupport/src/envlock.c b/c/src/exec/libcsupport/src/envlock.c index c9489b3e88..444d0e6b63 100644 --- a/c/src/exec/libcsupport/src/envlock.c +++ b/c/src/exec/libcsupport/src/envlock.c @@ -1,7 +1,7 @@ /* - * $Id$ - * * Author: Till Straumann <strauman@slac.stanford.edu>, 3/2002 + * + * $Id$ */ /* provide locking for the global environment 'environ' */ @@ -29,9 +29,14 @@ * lock-lock-unlock-unlock). * - NEWLIB-1.8.2 has an ugly BUG: if environ is NULL, _findenv_r() bails * out leaving the lock held :-( + * + * Used by the following functions: + * findenv_r(), setenv_r(), and unsetenv_r() which are called by + * getenv(), getenv_r(), setenv(), and unsetenv(). * */ +#if defined(ENVLOCK_DEDIDCATED_MUTEX) static rtems_id envLock=0; static void @@ -80,3 +85,24 @@ __env_unlock(struct _reent *r) if (_Thread_Executing) rtems_semaphore_release(envLock); } +#else + +/* + * Reuse the libio mutex -- it is always initialized before we + * could possibly run. + */ + +#include <rtems/libio_.h> + +void +__env_lock(struct _reent *r) +{ + rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); +} + +void +__env_unlock(struct _reent *r) +{ + rtems_semaphore_release( rtems_libio_semaphore ); +} +#endif diff --git a/c/src/lib/ChangeLog b/c/src/lib/ChangeLog index 0369ab6575..45f8bbe252 100644 --- a/c/src/lib/ChangeLog +++ b/c/src/lib/ChangeLog @@ -1,3 +1,9 @@ +2001-05-17 Joel Sherrill <joel@OARcorp.com> + + * libc/envlock.c: Implemented code to let newlib's envlock share + the libio open/close mutex. Since both should be lightly used, + this should not lead to problems and saves resources. + 2002-05-15 Chris Johns <ccj@acm.org> * libc/newlibc.c: Per PR141, move the C library re-enterrant diff --git a/c/src/lib/libc/envlock.c b/c/src/lib/libc/envlock.c index c9489b3e88..444d0e6b63 100644 --- a/c/src/lib/libc/envlock.c +++ b/c/src/lib/libc/envlock.c @@ -1,7 +1,7 @@ /* - * $Id$ - * * Author: Till Straumann <strauman@slac.stanford.edu>, 3/2002 + * + * $Id$ */ /* provide locking for the global environment 'environ' */ @@ -29,9 +29,14 @@ * lock-lock-unlock-unlock). * - NEWLIB-1.8.2 has an ugly BUG: if environ is NULL, _findenv_r() bails * out leaving the lock held :-( + * + * Used by the following functions: + * findenv_r(), setenv_r(), and unsetenv_r() which are called by + * getenv(), getenv_r(), setenv(), and unsetenv(). * */ +#if defined(ENVLOCK_DEDIDCATED_MUTEX) static rtems_id envLock=0; static void @@ -80,3 +85,24 @@ __env_unlock(struct _reent *r) if (_Thread_Executing) rtems_semaphore_release(envLock); } +#else + +/* + * Reuse the libio mutex -- it is always initialized before we + * could possibly run. + */ + +#include <rtems/libio_.h> + +void +__env_lock(struct _reent *r) +{ + rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); +} + +void +__env_unlock(struct _reent *r) +{ + rtems_semaphore_release( rtems_libio_semaphore ); +} +#endif |