From 7c844e30abf4729cc1cd058455f18fd4a8a7a5d5 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Fri, 17 May 2002 18:03:34 +0000 Subject: 2001-05-17 Joel Sherrill * 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. --- c/src/exec/libcsupport/src/envlock.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'c/src/exec/libcsupport/src') 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 , 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 + +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 -- cgit v1.2.3