diff options
author | Jeff Johnston <jjohnstn@redhat.com> | 2004-06-12 00:37:10 +0400 |
---|---|---|
committer | Jeff Johnston <jjohnstn@redhat.com> | 2004-06-12 00:37:10 +0400 |
commit | d0bd3e6f5653a16c8e82c969fb805f4a7d4faf40 (patch) | |
tree | 32f677032512db74362efe46308b87437c5fc58e /newlib/libc | |
parent | af6b55758bc44c58e70a1baf4061d8a8028f31d6 (diff) |
2004-06-11 Antony King <antony.king@st.com>
* libc/include/sys/_types.h: Include <sys/lock.h> and change
_flock_t to be of type _LOCK_RECURSIVE_T.
* libc/include/sys/reent.h: (_REENT_INIT): Reformat.
(_REENT_INIT_PTR): Ditto. Use memset where appropriate.
(_global_impure_ptr): New declaration.
(_GLOBAL_REENT): Change to be _global_impure_ptr.
* libc/include/sys/stdio.h: Include <sys/lock.h> and
<sys/reent.h>.
(_flockfile)[!_SINGLE_THREAD]: Add code for lock call.
(_funlockfile)[!SINGLE_THREAD]: Ditto.
* libc/reent/impure.c: Set _global_impure_ptr to _impure_ptr.
* libc/stdio/fclose.c: Remove casting of fp lock to
_LOCK_RECURSIVE_T.
* libc/stdio/findfp.c: Ditto.
* libc/stdio/fopen.c: Ditto.
* libc/stdio/freopen.c: Ditto.
* libc/stdio/vfprintf.c: Ditto.
* libc/stdio64/fopen64.c: Ditto.
* libc/stdlib/envlock.c: Add default stubs that use generic
locking code.
* libc/stdlib/mlock.c: Ditto.
Jeff Johnston <jjohnstn@redhat.com>
* libc/sys/linux/sys/_types.h (__flock_mutex_t): New subtype.
(_flock_t): Change to be a struct containing a single member
named mutex which is of type __flock_mutex_t.
Diffstat (limited to 'newlib/libc')
-rw-r--r-- | newlib/libc/include/sys/_types.h | 4 | ||||
-rw-r--r-- | newlib/libc/include/sys/reent.h | 106 | ||||
-rw-r--r-- | newlib/libc/include/sys/stdio.h | 11 | ||||
-rw-r--r-- | newlib/libc/reent/impure.c | 1 | ||||
-rw-r--r-- | newlib/libc/stdio/fclose.c | 2 | ||||
-rw-r--r-- | newlib/libc/stdio/findfp.c | 8 | ||||
-rw-r--r-- | newlib/libc/stdio/fopen.c | 2 | ||||
-rw-r--r-- | newlib/libc/stdio/freopen.c | 2 | ||||
-rw-r--r-- | newlib/libc/stdio/vfprintf.c | 4 | ||||
-rw-r--r-- | newlib/libc/stdio64/fopen64.c | 2 | ||||
-rw-r--r-- | newlib/libc/stdlib/envlock.c | 32 | ||||
-rw-r--r-- | newlib/libc/stdlib/mlock.c | 26 | ||||
-rw-r--r-- | newlib/libc/sys/linux/sys/_types.h | 8 |
13 files changed, 153 insertions, 55 deletions
diff --git a/newlib/libc/include/sys/_types.h b/newlib/libc/include/sys/_types.h index c498f7c8f..d3f68cef5 100644 --- a/newlib/libc/include/sys/_types.h +++ b/newlib/libc/include/sys/_types.h @@ -9,6 +9,8 @@ #ifndef _SYS__TYPES_H #define _SYS__TYPES_H +#include <sys/lock.h> + typedef long _off_t; __extension__ typedef long long _off64_t; @@ -32,7 +34,7 @@ typedef struct } __value; /* Value so far. */ } _mbstate_t; -typedef int _flock_t; +typedef _LOCK_RECURSIVE_T _flock_t; /* Iconv descriptor type */ typedef void *_iconv_t; diff --git a/newlib/libc/include/sys/reent.h b/newlib/libc/include/sys/reent.h index fa19a2980..f8cc41ed1 100644 --- a/newlib/libc/include/sys/reent.h +++ b/newlib/libc/include/sys/reent.h @@ -381,10 +381,31 @@ struct _reent }; #define _REENT_INIT(var) \ - { (__FILE *)&var.__sf_fake, (__FILE *)&var.__sf_fake, \ - (__FILE *)&var.__sf_fake, 0, 0, _NULL, 0, 0, \ - "C", _NULL, _NULL, 0, 0, _NULL, _NULL, _NULL, _NULL, _NULL, \ - { 0, _NULL, _NULL, 0 }, { _NULL, 0, _NULL }, _NULL, 0, _NULL, _NULL } + { (__FILE *)&var.__sf_fake, \ + (__FILE *)&var.__sf_fake, \ + (__FILE *)&var.__sf_fake, \ + 0, \ + 0, \ + _NULL, \ + 0, \ + 0, \ + "C", \ + _NULL, \ + _NULL, \ + 0, \ + 0, \ + _NULL, \ + _NULL, \ + _NULL, \ + _NULL, \ + _NULL, \ + {0, {_NULL}, _NULL}, \ + {_NULL, 0, _NULL}, \ + _NULL, \ + {_NULL, 0, 0, 0, 0, {_NULL, 0}, 0, _NULL}, \ + _NULL, \ + _NULL \ + } #define _REENT_INIT_PTR(var) \ { var->_stdin = (__FILE *)&var->__sf_fake; \ @@ -412,16 +433,17 @@ struct _reent var->__sglue._niobs = 0; \ var->__sglue._iobs = _NULL; \ var->__sf = 0; \ - var->_misc = _NULL; \ - var->_signal_buf = _NULL; \ - var->_getdate_err = 0; \ var->__sf_fake._p = _NULL; \ var->__sf_fake._r = 0; \ var->__sf_fake._w = 0; \ var->__sf_fake._flags = 0; \ var->__sf_fake._file = 0; \ + var->__sf_fake._bf._base = _NULL; \ + var->__sf_fake._bf._size = 0; \ var->__sf_fake._lbfsize = 0; \ var->__sf_fake._data = _NULL; \ + var->_misc = _NULL; \ + var->_signal_buf = _NULL; \ } /* Only built the assert() calls if we are built with debugging. */ @@ -608,23 +630,61 @@ struct _reent }; #define _REENT_INIT(var) \ - { 0, &var.__sf[0], &var.__sf[1], &var.__sf[2], 0, "", 0, "C", \ - 0, _NULL, _NULL, 0, _NULL, _NULL, 0, _NULL, { {0, _NULL, "", \ - { 0,0,0,0,0,0,0,0}, 0, 1, \ - {{_RAND48_SEED_0, _RAND48_SEED_1, _RAND48_SEED_2}, \ - {_RAND48_MULT_0, _RAND48_MULT_1, _RAND48_MULT_2}, _RAND48_ADD}, \ - {0, {0}}, {0, {0}}, {0, {0}}, "", "", 0, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}} } } } + { 0, \ + &var.__sf[0], \ + &var.__sf[1], \ + &var.__sf[2], \ + 0, \ + "", \ + 0, \ + "C", \ + 0, \ + _NULL, \ + _NULL, \ + 0, \ + _NULL, \ + _NULL, \ + 0, \ + _NULL, \ + { \ + { \ + 0, \ + _NULL, \ + "", \ + {0, 0, 0, 0, 0, 0, 0, 0, 0}, \ + 0, \ + 1, \ + { \ + {_RAND48_SEED_0, _RAND48_SEED_1, _RAND48_SEED_2}, \ + {_RAND48_MULT_0, _RAND48_MULT_1, _RAND48_MULT_2}, \ + _RAND48_ADD \ + }, \ + {0, {0}}, \ + {0, {0}}, \ + {0, {0}}, \ + "", \ + "", \ + 0, \ + {0, {0}}, \ + {0, {0}}, \ + {0, {0}}, \ + {0, {0}}, \ + {0, {0}} \ + } \ + }, \ + _NULL, \ + {_NULL, 0, {_NULL}, {{_NULL}, 0}}, \ + _NULL, \ + {_NULL, 0, _NULL} \ + } #define _REENT_INIT_PTR(var) \ - { int i; \ - char *tmp_ptr; \ - var->_errno = 0; \ + { var->_errno = 0; \ var->_stdin = &var->__sf[0]; \ var->_stdout = &var->__sf[1]; \ var->_stderr = &var->__sf[2]; \ var->_inc = 0; \ - for (i = 0; i < _REENT_EMERGENCY_SIZE; ++i) \ - var->_emergency[i] = 0; \ + memset(&var->_emergency, 0, sizeof(var->_emergency)); \ var->_current_category = 0; \ var->_current_locale = "C"; \ var->__sdidinit = 0; \ @@ -638,9 +698,7 @@ struct _reent var->_new._reent._unused_rand = 0; \ var->_new._reent._strtok_last = _NULL; \ var->_new._reent._asctime_buf[0] = 0; \ - tmp_ptr = (char *)&var->_new._reent._localtime_buf; \ - for (i = 0; i < sizeof(struct __tm); ++i) \ - tmp_ptr[i] = 0; \ + memset(&var->_new._reent._localtime_buf, 0, sizeof(var->_new._reent._localtime_buf)); \ var->_new._reent._gamma_signgam = 0; \ var->_new._reent._rand_next = 1; \ var->_new._reent._r48._seed[0] = _RAND48_SEED_0; \ @@ -670,6 +728,7 @@ struct _reent var->_new._reent._signal_buf[0] = '\0'; \ var->_new._reent._getdate_err = 0; \ var->_atexit = _NULL; \ + var->_atexit0._next = _NULL; \ var->_atexit0._ind = 0; \ var->_atexit0._fns[0] = _NULL; \ var->_atexit0._on_exit_args._fntypes = 0; \ @@ -678,7 +737,7 @@ struct _reent var->__sglue._next = _NULL; \ var->__sglue._niobs = 0; \ var->__sglue._iobs = _NULL; \ - memset(var->__sf,0,sizeof(var->__sf)); \ + memset(&var->__sf, 0, sizeof(var->__sf)); \ } #define _REENT_CHECK_RAND48(ptr) /* nothing */ @@ -728,6 +787,7 @@ struct _reent #endif extern struct _reent *_impure_ptr __ATTRIBUTE_IMPURE_PTR__; +extern struct _reent *_CONST _global_impure_ptr __ATTRIBUTE_IMPURE_PTR__; void _reclaim_reent _PARAMS ((struct _reent *)); @@ -746,7 +806,7 @@ void _reclaim_reent _PARAMS ((struct _reent *)); #endif /* !_REENT_ONLY */ -#define _GLOBAL_REENT _impure_ptr +#define _GLOBAL_REENT _global_impure_ptr #ifdef __cplusplus } diff --git a/newlib/libc/include/sys/stdio.h b/newlib/libc/include/sys/stdio.h index 8177322a0..c0cf33893 100644 --- a/newlib/libc/include/sys/stdio.h +++ b/newlib/libc/include/sys/stdio.h @@ -1,14 +1,25 @@ #ifndef _NEWLIB_STDIO_H #define _NEWLIB_STDIO_H +#include <sys/lock.h> +#include <sys/reent.h> + /* Internal locking macros, used to protect stdio functions. In the general case, expand to nothing. */ #if !defined(_flockfile) +#ifndef __SINGLE_THREAD__ +# define _flockfile(fp) __lock_acquire_recursive(fp->_lock) +#else # define _flockfile(fp) #endif +#endif #if !defined(_funlockfile) +#ifndef __SINGLE_THREAD__ +# define _funlockfile(fp) __lock_release_recursive(fp->_lock) +#else # define _funlockfile(fp) #endif +#endif #endif /* _NEWLIB_STDIO_H */ diff --git a/newlib/libc/reent/impure.c b/newlib/libc/reent/impure.c index a14f5c3cd..27c0e0b5a 100644 --- a/newlib/libc/reent/impure.c +++ b/newlib/libc/reent/impure.c @@ -11,3 +11,4 @@ static struct _reent __ATTRIBUTE_IMPURE_DATA__ impure_data = _REENT_INIT (impure_data); struct _reent *__ATTRIBUTE_IMPURE_PTR__ _impure_ptr = &impure_data; +struct _reent *_CONST __ATTRIBUTE_IMPURE_PTR__ _global_impure_ptr = &impure_data; diff --git a/newlib/libc/stdio/fclose.c b/newlib/libc/stdio/fclose.c index 2f2ae47fa..f9fd17cb0 100644 --- a/newlib/libc/stdio/fclose.c +++ b/newlib/libc/stdio/fclose.c @@ -98,7 +98,7 @@ _DEFUN(_fclose_r, (rptr, fp), fp->_flags = 0; /* release this FILE for reuse */ _funlockfile (fp); #ifndef __SINGLE_THREAD__ - __lock_close_recursive (*(_LOCK_RECURSIVE_T *)&fp->_lock); + __lock_close_recursive (fp->_lock); #endif __sfp_lock_release (); diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c index 9a9cb037e..a9695ffff 100644 --- a/newlib/libc/stdio/findfp.c +++ b/newlib/libc/stdio/findfp.c @@ -47,7 +47,7 @@ _DEFUN(std, (ptr, flags, file, data), ptr->_seek = __sseek; ptr->_close = __sclose; #if !defined(__SINGLE_THREAD__) && !defined(_REENT_SMALL) - __lock_init_recursive (*(_LOCK_RECURSIVE_T *)&ptr->_lock); + __lock_init_recursive (ptr->_lock); /* * #else * lock is already initialized in __sfp @@ -112,7 +112,7 @@ found: fp->_file = -1; /* no file */ fp->_flags = 1; /* reserve this slot; caller sets real flags */ #ifndef __SINGLE_THREAD__ - __lock_init_recursive (*(_LOCK_RECURSIVE_T *)&fp->_lock); + __lock_init_recursive (fp->_lock); #endif __sfp_lock_release (); @@ -143,8 +143,8 @@ _VOID _DEFUN(_cleanup_r, (ptr), struct _reent *ptr) { - /* _CAST_VOID _fwalk(fclose); */ - _CAST_VOID _fwalk (ptr, fflush); /* `cheating' */ + _CAST_VOID _fwalk(ptr, fclose); + /* _CAST_VOID _fwalk (ptr, fflush); */ /* `cheating' */ } #ifndef _REENT_ONLY diff --git a/newlib/libc/stdio/fopen.c b/newlib/libc/stdio/fopen.c index 816e1725c..64c24e7ef 100644 --- a/newlib/libc/stdio/fopen.c +++ b/newlib/libc/stdio/fopen.c @@ -143,7 +143,7 @@ _DEFUN(_fopen_r, (ptr, file, mode), __sfp_lock_acquire (); fp->_flags = 0; /* release */ #ifndef __SINGLE_THREAD__ - __lock_close_recursive (*(_LOCK_RECURSIVE_T *)&fp->_lock); + __lock_close_recursive (fp->_lock); #endif __sfp_lock_release (); return NULL; diff --git a/newlib/libc/stdio/freopen.c b/newlib/libc/stdio/freopen.c index 83128525a..d4a65e77b 100644 --- a/newlib/libc/stdio/freopen.c +++ b/newlib/libc/stdio/freopen.c @@ -157,7 +157,7 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp), ptr->_errno = e; /* restore in case _close clobbered */ _funlockfile (fp); #ifndef __SINGLE_THREAD__ - __lock_close_recursive (*(_LOCK_RECURSIVE_T *)&fp->_lock); + __lock_close_recursive (fp->_lock); #endif __sfp_lock_release (); return NULL; diff --git a/newlib/libc/stdio/vfprintf.c b/newlib/libc/stdio/vfprintf.c index b589d18d7..9e970cef3 100644 --- a/newlib/libc/stdio/vfprintf.c +++ b/newlib/libc/stdio/vfprintf.c @@ -255,7 +255,7 @@ _DEFUN(__sbprintf, (rptr, fp, fmt, ap), fake._bf._size = fake._w = sizeof (buf); fake._lbfsize = 0; /* not actually used, but Just In Case */ #ifndef __SINGLE_THREAD__ - __lock_init_recursive (*(_LOCK_RECURSIVE_T *)&fake._lock); + __lock_init_recursive (fake._lock); #endif /* do the work, then copy any error status */ @@ -266,7 +266,7 @@ _DEFUN(__sbprintf, (rptr, fp, fmt, ap), fp->_flags |= __SERR; #ifndef __SINGLE_THREAD__ - __lock_close_recursive (*(_LOCK_RECURSIVE_T *)&fake._lock); + __lock_close_recursive (fake._lock); #endif return (ret); } diff --git a/newlib/libc/stdio64/fopen64.c b/newlib/libc/stdio64/fopen64.c index 1feffd1db..61c4e4f45 100644 --- a/newlib/libc/stdio64/fopen64.c +++ b/newlib/libc/stdio64/fopen64.c @@ -94,7 +94,7 @@ _DEFUN (_fopen64_r, (ptr, file, mode), __sfp_lock_acquire (); fp->_flags = 0; /* release */ #ifndef __SINGLE_THREAD__ - __lock_close_recursive (*(_LOCK_RECURSIVE_T *)&fp->_lock); + __lock_close_recursive (fp->_lock); #endif __sfp_lock_release (); return NULL; diff --git a/newlib/libc/stdlib/envlock.c b/newlib/libc/stdlib/envlock.c index 8e55de288..24d0083be 100644 --- a/newlib/libc/stdlib/envlock.c +++ b/newlib/libc/stdlib/envlock.c @@ -9,24 +9,24 @@ INDEX ANSI_SYNOPSIS #include "envlock.h" - void __env_lock (struct _reent *<[reent]>); - void __env_unlock (struct _reent *<[reent]>); + void __env_lock (struct _reent *<[reent]>); + void __env_unlock (struct _reent *<[reent]>); TRAD_SYNOPSIS void __env_lock(<[reent]>) - struct _reent *<[reent]>; + struct _reent *<[reent]>; void __env_unlock(<[reent]>) - struct _reent *<[reent]>; + struct _reent *<[reent]>; DESCRIPTION -The <<setenv>> family of routines call these functions when they need -to modify the environ variable. The version of these routines supplied -in the library does not do anything. If multiple threads of execution -can call <<setenv>>, or if <<setenv>> can be called reentrantly, then -you need to define your own versions of these functions in order to -safely lock the memory pool during a call. If you do not, the memory -pool may become corrupted. +The <<setenv>> family of routines call these functions when they need to +modify the environ variable. The version of these routines supplied in the +library use the lock API defined in sys/lock.h. If multiple threads of +execution can call <<setenv>>, or if <<setenv>> can be called reentrantly, +then you need to define your own versions of these functions in order to +safely lock the memory pool during a call. If you do not, the memory pool +may become corrupted. A call to <<setenv>> may call <<__env_lock>> recursively; that is, the sequence of calls may go <<__env_lock>>, <<__env_lock>>, @@ -36,16 +36,26 @@ that it already holds. */ #include "envlock.h" +#include <sys/lock.h> +#ifndef __SINGLE_THREAD__ +__LOCK_INIT_RECURSIVE(static, __env_lock_object); +#endif void __env_lock (ptr) struct _reent *ptr; { +#ifndef __SINGLE_THREAD__ + __lock_acquire_recursive (__env_lock_object); +#endif } void __env_unlock (ptr) struct _reent *ptr; { +#ifndef __SINGLE_THREAD__ + __lock_release_recursive (__env_lock_object); +#endif } diff --git a/newlib/libc/stdlib/mlock.c b/newlib/libc/stdlib/mlock.c index c603fbcda..378b4e691 100644 --- a/newlib/libc/stdlib/mlock.c +++ b/newlib/libc/stdlib/mlock.c @@ -21,13 +21,13 @@ TRAD_SYNOPSIS struct _reent *<[reent]>; DESCRIPTION -The <<malloc>> family of routines call these functions when they need -to lock the memory pool. The version of these routines supplied in -the library does not do anything. If multiple threads of execution -can call <<malloc>>, or if <<malloc>> can be called reentrantly, then -you need to define your own versions of these functions in order to -safely lock the memory pool during a call. If you do not, the memory -pool may become corrupted. +The <<malloc>> family of routines call these functions when they need to lock +the memory pool. The version of these routines supplied in the library use +the lock API defined in sys/lock.h. If multiple threads of execution can +call <<malloc>>, or if <<malloc>> can be called reentrantly, then you need to +define your own versions of these functions in order to safely lock the +memory pool during a call. If you do not, the memory pool may become +corrupted. A call to <<malloc>> may call <<__malloc_lock>> recursively; that is, the sequence of calls may go <<__malloc_lock>>, <<__malloc_lock>>, @@ -37,16 +37,28 @@ that it already holds. */ #include <malloc.h> +#include <sys/lock.h> + +#ifndef __SINGLE_THREAD__ +__LOCK_INIT_RECURSIVE(static, __malloc_lock_object); +#endif void __malloc_lock (ptr) struct _reent *ptr; { +#ifndef __SINGLE_THREAD__ + __lock_acquire_recursive (__malloc_lock_object); +#endif } void __malloc_unlock (ptr) struct _reent *ptr; { +#ifndef __SINGLE_THREAD__ + __lock_release_recursive (__malloc_lock_object); +#endif } + #endif diff --git a/newlib/libc/sys/linux/sys/_types.h b/newlib/libc/sys/linux/sys/_types.h index 15ccf1061..994df899a 100644 --- a/newlib/libc/sys/linux/sys/_types.h +++ b/newlib/libc/sys/linux/sys/_types.h @@ -32,7 +32,7 @@ typedef struct } __value; /* Value so far. */ } _mbstate_t; -struct __flock_t_tmp; +struct __flock_mutex_t_tmp; typedef struct { int __a; @@ -43,7 +43,9 @@ typedef struct int __c2; } __c; int __d; - struct __flock_t_tmp * __e; -} _flock_t; + struct __flock_mutex_t_tmp * __e; +} __flock_mutex_t; + +typedef struct { __flock_mutex_t mutex; } _flock_t; #endif /* _SYS__TYPES_H */ |