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.
This commit is contained in:
Jeff Johnston 2004-06-11 20:37:10 +00:00
parent af6b55758b
commit d0bd3e6f56
14 changed files with 183 additions and 56 deletions

View File

@ -1,3 +1,32 @@
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.
2004-06-09 Jeff Johnston <jjohnstn@redhat.com>
* libc/sys/linux/Makefile.am: Change siglist.inc to be generated

View File

@ -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;

View File

@ -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
}

View File

@ -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 */

View File

@ -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;

View File

@ -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 ();

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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);
}

View File

@ -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;

View File

@ -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
}

View File

@ -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

View File

@ -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 */