From 3db40db7d83ca924a935680b1c210dd11f1f660d Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Tue, 3 Sep 2002 19:40:36 +0000 Subject: 2002-09-03 Jeff Johnston * libc/include/sys/_types.h (_flock_t): Added. * libc/include/sys/lock.h (__lock_try_acquire): New interface. (__lock_try_acquire_recursive): Ditto. * libc/include/sys/reent.h (__sFILE, __sFILE64): Add new _lock field. * libc/stdio/findfp.c (std)[!__SINGLE_THREAD__]: Initialize _lock field. * libc/stdio/fopen.c (_fopen_r)[!__SINGLE_THREAD__]: Ditto. * libc/stdio64/fopen64.c (_fopen64_r)[!__SINGLE_THREAD__]: Ditto. * libc/sys/linux/include/time.h (struct timespec): Moved from and added check for __need_timespec flag so type can be defined by itself. * libc/sys/linux/sys/_types.h (_flock_t): New type. * libc/sys/linux/sys/types.h (struct timespec): Moved to . --- newlib/ChangeLog | 18 +++++++++++++ newlib/libc/include/sys/_types.h | 2 ++ newlib/libc/include/sys/lock.h | 2 ++ newlib/libc/include/sys/reent.h | 11 +++++++- newlib/libc/stdio/findfp.c | 4 +++ newlib/libc/stdio/fopen.c | 5 ++++ newlib/libc/stdio64/fopen64.c | 5 ++++ newlib/libc/sys/linux/include/time.h | 22 ++++++++++++--- newlib/libc/sys/linux/sys/_types.h | 52 ++++++++++++++++++++++++++++++++++++ newlib/libc/sys/linux/sys/types.h | 10 ------- 10 files changed, 117 insertions(+), 14 deletions(-) create mode 100644 newlib/libc/sys/linux/sys/_types.h diff --git a/newlib/ChangeLog b/newlib/ChangeLog index 9d409f2..238800b 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,21 @@ +2002-09-03 Jeff Johnston + + * libc/include/sys/_types.h (_flock_t): Added. + * libc/include/sys/lock.h (__lock_try_acquire): New interface. + (__lock_try_acquire_recursive): Ditto. + * libc/include/sys/reent.h (__sFILE, __sFILE64): Add new + _lock field. + * libc/stdio/findfp.c (std)[!__SINGLE_THREAD__]: Initialize _lock + field. + * libc/stdio/fopen.c (_fopen_r)[!__SINGLE_THREAD__]: Ditto. + * libc/stdio64/fopen64.c (_fopen64_r)[!__SINGLE_THREAD__]: Ditto. + * libc/sys/linux/include/time.h (struct timespec): Moved from + and added check for __need_timespec flag so type + can be defined by itself. + * libc/sys/linux/sys/_types.h (_flock_t): New type. + * libc/sys/linux/sys/types.h (struct timespec): Moved to + . + 2002-08-29 Thomas Fitzsimmons * libc/sys/linux/argp: New directory. diff --git a/newlib/libc/include/sys/_types.h b/newlib/libc/include/sys/_types.h index 9f3b05b..c47a6ad 100644 --- a/newlib/libc/include/sys/_types.h +++ b/newlib/libc/include/sys/_types.h @@ -43,4 +43,6 @@ typedef _mbstate_t mbstate_t; # define WEOF (0xffffffffu) #endif /* __CYGWIN__ */ +typedef int _flock_t; + #endif /* _SYS__TYPES_H */ diff --git a/newlib/libc/include/sys/lock.h b/newlib/libc/include/sys/lock.h index efdd731..984bc5f 100644 --- a/newlib/libc/include/sys/lock.h +++ b/newlib/libc/include/sys/lock.h @@ -14,6 +14,8 @@ typedef int _LOCK_RECURSIVE_T; #define __lock_close_recursive(lock) {} #define __lock_acquire(lock) {} #define __lock_acquire_recursive(lock) {} +#define __lock_try_acquire(lock) {} +#define __lock_try_acquire_recursive(lock) {} #define __lock_release(lock) {} #define __lock_release_recursive(lock) {} diff --git a/newlib/libc/include/sys/reent.h b/newlib/libc/include/sys/reent.h index ebdf32a..09160a9 100644 --- a/newlib/libc/include/sys/reent.h +++ b/newlib/libc/include/sys/reent.h @@ -192,7 +192,11 @@ struct __sFILE { int _offset; /* current lseek offset */ #ifndef _REENT_SMALL - struct _reent *_data; /* Here for binary compatibility? Remove? */ + struct _reent *_data; /* Here for binary compatibility? Remove? */ +#endif + +#ifndef __SINGLE_THREAD__ + _flock_t _lock; /* for thread-safety locking */ #endif }; @@ -232,8 +236,13 @@ struct __sFILE64 { /* Unix stdio files get aligned to block boundaries on fseek() */ int _blksize; /* stat.st_blksize (may be != _bf._size) */ int _flags2; /* for future use */ + _off64_t _offset; /* current lseek offset */ _fpos64_t _EXFUN((*_seek64),(_PTR _cookie, _fpos64_t _offset, int _whence)); + +#ifndef __SINGLE_THREAD__ + _flock_t _lock; /* for thread-safety locking */ +#endif }; typedef struct __sFILE64 __FILE; #else diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c index a42a692..4f1387c 100644 --- a/newlib/libc/stdio/findfp.c +++ b/newlib/libc/stdio/findfp.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "local.h" static void @@ -45,6 +46,9 @@ std (ptr, flags, file, data) ptr->_seek = __sseek; ptr->_close = __sclose; ptr->_data = data; +#ifndef __SINGLE_THREAD__ + __lock_init_recursive (*(_LOCK_RECURSIVE_T *)&ptr->_lock); +#endif #ifdef __SCLE if (__stextmode(ptr->_file)) diff --git a/newlib/libc/stdio/fopen.c b/newlib/libc/stdio/fopen.c index e470878..ff2cbec 100644 --- a/newlib/libc/stdio/fopen.c +++ b/newlib/libc/stdio/fopen.c @@ -119,6 +119,7 @@ static char sccsid[] = "%W% (Berkeley) %G%"; #ifdef __CYGWIN__ #include #endif +#include FILE * _DEFUN (_fopen_r, (ptr, file, mode), @@ -157,6 +158,10 @@ _DEFUN (_fopen_r, (ptr, file, mode), fp->_flags |= __SCLE; #endif +#ifndef __SINGLE_THREAD__ + __lock_init_recursive (*(_LOCK_RECURSIVE_T *)&fp->_lock); +#endif + return fp; } diff --git a/newlib/libc/stdio64/fopen64.c b/newlib/libc/stdio64/fopen64.c index 1eb8987..d2ab74c 100644 --- a/newlib/libc/stdio64/fopen64.c +++ b/newlib/libc/stdio64/fopen64.c @@ -70,6 +70,7 @@ static char sccsid[] = "%W% (Berkeley) %G%"; #ifdef __CYGWIN__ #include #endif +#include #ifdef __LARGE64_FILES @@ -113,6 +114,10 @@ _DEFUN (_fopen64_r, (ptr, file, mode), fp->_flags |= __SL64; +#ifndef __SINGLE_THREAD__ + __lock_init_recursive (*(_LOCK_RECURSIVE_T *)&fp->_lock); +#endif + return fp; } diff --git a/newlib/libc/sys/linux/include/time.h b/newlib/libc/sys/linux/include/time.h index 2db3324..8b4b284 100644 --- a/newlib/libc/sys/linux/include/time.h +++ b/newlib/libc/sys/linux/include/time.h @@ -5,7 +5,6 @@ */ #ifndef _TIME_H_ -#define _TIME_H_ #include "_ansi.h" #include @@ -21,6 +20,20 @@ extern "C" { /* Get _CLOCKS_PER_SEC_ */ #include +#include + +/* Time Value Specification Structures, P1003.1b-1993, p. 261 */ +#ifndef _STRUCT_TIMESPEC +#define _STRUCT_TIMESPEC +struct timespec { + time_t tv_sec; /* Seconds */ + long tv_nsec; /* Nanoseconds */ +}; +#endif /* !_STRUCT_TIMESPEC */ + +#ifndef __need_timespec + +#define _TIME_H_ 1 #ifndef _CLOCKS_PER_SEC_ #define _CLOCKS_PER_SEC_ 1000 @@ -31,8 +44,6 @@ extern "C" { #define __need_size_t #include -#include - struct tm { int tm_sec; @@ -208,5 +219,10 @@ int _EXFUN(clock_getenable_attr, (clockid_t clock_id, int *attr)); #ifdef __cplusplus } #endif + +#endif /* ! __need_timespec */ + +#undef __need_timespec + #endif /* _TIME_H_ */ diff --git a/newlib/libc/sys/linux/sys/_types.h b/newlib/libc/sys/linux/sys/_types.h new file mode 100644 index 0000000..3160129 --- /dev/null +++ b/newlib/libc/sys/linux/sys/_types.h @@ -0,0 +1,52 @@ +/* ANSI C namespace clean utility typedefs */ + +/* This file defines various typedefs needed by the system calls that support + the C library. Basically, they're just the POSIX versions with an '_' + prepended. This file lives in the `sys' directory so targets can provide + their own if desired (or they can put target dependant conditionals here). +*/ + +#ifndef _SYS__TYPES_H +#define _SYS__TYPES_H + +typedef long _off_t; +__extension__ typedef long long _off64_t; + +#if defined(__INT_MAX__) && __INT_MAX__ == 2147483647 +typedef int _ssize_t; +#else +typedef long _ssize_t; +#endif + +#define __need_wint_t +#include + +#ifndef _MBSTATE_T +#define _MBSTATE_T +/* Conversion state information. */ +typedef struct +{ + int __count; + union + { + wint_t __wch; + char __wchb[4]; + } __value; /* Value so far. */ +} _mbstate_t; +#endif /* _MBSTATE_T */ + +struct __flock_t_tmp; +typedef struct +{ + int __a; + int __b; + struct + { + long int __c1; + int __c2; + } __c; + int __d; + struct __flock_t_tmp * __e; +} _flock_t; + +#endif /* _SYS__TYPES_H */ diff --git a/newlib/libc/sys/linux/sys/types.h b/newlib/libc/sys/linux/sys/types.h index 5541f09..90011ea 100644 --- a/newlib/libc/sys/linux/sys/types.h +++ b/newlib/libc/sys/linux/sys/types.h @@ -94,16 +94,6 @@ typedef struct typedef int clockid_t; -/* Time Value Specification Structures, P1003.1b-1993, p. 261 */ - -#ifndef _STRUCT_TIMESPEC -#define _STRUCT_TIMESPEC -struct timespec { - time_t tv_sec; /* Seconds */ - long tv_nsec; /* Nanoseconds */ -}; -#endif /* !_STRUCT_TIMESPEC */ - # define _SYS_TYPES_FD_SET # define NBBY 8 /* number of bits in a byte */ /* -- cgit v1.1