diff options
-rw-r--r-- | newlib/ChangeLog | 16 | ||||
-rw-r--r-- | newlib/libc/include/stdio.h | 1 | ||||
-rw-r--r-- | newlib/libc/include/stdio_ext.h | 6 | ||||
-rw-r--r-- | newlib/libc/stdio/Makefile.am | 3 | ||||
-rw-r--r-- | newlib/libc/stdio/Makefile.in | 11 | ||||
-rw-r--r-- | newlib/libc/stdio/fsetlocking.c | 90 | ||||
-rw-r--r-- | newlib/libc/stdio/local.h | 29 | ||||
-rw-r--r-- | newlib/libc/stdio/stdio.tex | 3 |
8 files changed, 151 insertions, 8 deletions
diff --git a/newlib/ChangeLog b/newlib/ChangeLog index 526a66de2..e092d1f62 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,19 @@ +2014-12-15 Yaakov Selkowitz <yselkowi@redhat.com> + + * libc/include/stdio.h (__SNLK): Define. + * libc/include/stdio_ext.h (FSETLOCKING_QUERY, FSETLOCKING_INTERNAL, + FSETLOCKING_BYCALLER): Define. + (__fsetlocking): Declare. + * libc/stdio/Makefile.am: Build fsetlocking.c. + * libc/stdio/Makefile.in: Regenerate. + * libc/stdio/fsetlocking.c: New file. + * libc/stdio/local.h (_newlib_flockfile_start): Make _flockfile + call dependent on __SNLK flag. + (_newlib_flockfile_exit, _newlib_flockfile_end): Ditto for + _funlockfile calls. + Define all locking macros as empty if __SINGLE_THREAD__. + * libc/stdio/stdio.tex: Include fsetlocking.def. + 2014-12-15 Nick Hung <nick@andestech.com> * newlib/libc/include/machine/setjmp.h: Add FPU support. diff --git a/newlib/libc/include/stdio.h b/newlib/libc/include/stdio.h index 620bfbcf2..eb2d24939 100644 --- a/newlib/libc/include/stdio.h +++ b/newlib/libc/include/stdio.h @@ -83,6 +83,7 @@ typedef _fpos64_t fpos64_t; #define __SL64 0x8000 /* is 64-bit offset large file */ /* _flags2 flags */ +#define __SNLK 0x0001 /* stdio functions do not lock streams themselves */ #define __SWID 0x2000 /* true => stream orientation wide, false => byte, only valid if __SORD in _flags is true */ /* diff --git a/newlib/libc/include/stdio_ext.h b/newlib/libc/include/stdio_ext.h index 4b6f8ae36..029ab0253 100644 --- a/newlib/libc/include/stdio_ext.h +++ b/newlib/libc/include/stdio_ext.h @@ -13,14 +13,18 @@ #include <stdio.h> +#define FSETLOCKING_QUERY 0 +#define FSETLOCKING_INTERNAL 1 +#define FSETLOCKING_BYCALLER 2 + _BEGIN_STD_C void _EXFUN(__fpurge,(FILE *)); +int _EXFUN(__fsetlocking,(FILE *, int)); /* TODO: void _flushlbf (void); - int __fsetlocking (FILE *__fp, int __type); */ #ifdef __GNUC__ diff --git a/newlib/libc/stdio/Makefile.am b/newlib/libc/stdio/Makefile.am index 8069ead16..360d0de4b 100644 --- a/newlib/libc/stdio/Makefile.am +++ b/newlib/libc/stdio/Makefile.am @@ -146,6 +146,7 @@ ELIX_4_SOURCES = \ fpurge.c \ fputwc.c \ fputws.c \ + fsetlocking.c \ funopen.c \ fwide.c \ fwprintf.c \ @@ -357,6 +358,7 @@ CHEWOUT_FILES = \ fread.def \ freopen.def \ fseek.def \ + fsetlocking.def \ fsetpos.def \ ftell.def \ funopen.def \ @@ -433,6 +435,7 @@ $(lpfx)fputws.$(oext): local.h fvwrite.h $(lpfx)fread.$(oext): local.h $(lpfx)freopen.$(oext): local.h $(lpfx)fseek.$(oext): local.h +$(lpfx)fsetlocking.$(oext): local.h $(lpfx)ftell.$(oext): local.h $(lpfx)funopen.$(oext): local.h $(lpfx)fvwrite.$(oext): local.h fvwrite.h diff --git a/newlib/libc/stdio/Makefile.in b/newlib/libc/stdio/Makefile.in index e1c4866f1..72b386e18 100644 --- a/newlib/libc/stdio/Makefile.in +++ b/newlib/libc/stdio/Makefile.in @@ -143,6 +143,7 @@ am__objects_2 = $(am__objects_1) lib_a-clearerr.$(OBJEXT) \ @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-fpurge.$(OBJEXT) \ @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-fputwc.$(OBJEXT) \ @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-fputws.$(OBJEXT) \ +@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-fsetlocking.$(OBJEXT) \ @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-funopen.$(OBJEXT) \ @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-fwide.$(OBJEXT) \ @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-fwprintf.$(OBJEXT) \ @@ -206,6 +207,7 @@ am__objects_8 = $(am__objects_7) clearerr.lo fclose.lo fdopen.lo \ @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ fpurge.lo \ @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ fputwc.lo \ @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ fputws.lo \ +@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ fsetlocking.lo \ @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ funopen.lo \ @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ fwide.lo \ @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ fwprintf.lo \ @@ -514,6 +516,7 @@ GENERAL_SOURCES = \ @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ fpurge.c \ @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ fputwc.c \ @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ fputws.c \ +@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ fsetlocking.c \ @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ funopen.c \ @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ fwide.c \ @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ fwprintf.c \ @@ -631,6 +634,7 @@ CHEWOUT_FILES = \ fread.def \ freopen.def \ fseek.def \ + fsetlocking.def \ fsetpos.def \ ftell.def \ funopen.def \ @@ -1355,6 +1359,12 @@ lib_a-fputws.o: fputws.c lib_a-fputws.obj: fputws.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-fputws.obj `if test -f 'fputws.c'; then $(CYGPATH_W) 'fputws.c'; else $(CYGPATH_W) '$(srcdir)/fputws.c'; fi` +lib_a-fsetlocking.o: fsetlocking.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-fsetlocking.o `test -f 'fsetlocking.c' || echo '$(srcdir)/'`fsetlocking.c + +lib_a-fsetlocking.obj: fsetlocking.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-fsetlocking.obj `if test -f 'fsetlocking.c'; then $(CYGPATH_W) 'fsetlocking.c'; else $(CYGPATH_W) '$(srcdir)/fsetlocking.c'; fi` + lib_a-funopen.o: funopen.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-funopen.o `test -f 'funopen.c' || echo '$(srcdir)/'`funopen.c @@ -1772,6 +1782,7 @@ $(lpfx)fputws.$(oext): local.h fvwrite.h $(lpfx)fread.$(oext): local.h $(lpfx)freopen.$(oext): local.h $(lpfx)fseek.$(oext): local.h +$(lpfx)fsetlocking.$(oext): local.h $(lpfx)ftell.$(oext): local.h $(lpfx)funopen.$(oext): local.h $(lpfx)fvwrite.$(oext): local.h fvwrite.h diff --git a/newlib/libc/stdio/fsetlocking.c b/newlib/libc/stdio/fsetlocking.c new file mode 100644 index 000000000..3c489f54d --- /dev/null +++ b/newlib/libc/stdio/fsetlocking.c @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2014 Red Hat, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +/* +FUNCTION +<<__fsetlocking>>---set or query locking mode on FILE stream + +INDEX + __fsetlocking + +ANSI_SYNOPSIS + #include <stdio.h> + #include <stdio_ext.h> + int __fsetlocking(FILE *<[fp]>, int <[type]>); + +DESCRIPTION +This function sets how the stdio functions handle locking of FILE <[fp]>. +The following values describe <[type]>: + +<<FSETLOCKING_INTERNAL>> is the default state, where stdio functions +automatically lock and unlock the stream. + +<<FSETLOCKING_BYCALLER>> means that automatic locking in stdio functions +is disabled. Applications which set this take all responsibility for file +locking themselves. + +<<FSETLOCKING_QUERY>> returns the current locking mode without changing it. + +RETURNS +<<__fsetlocking>> returns the current locking mode of <[fp]>. + +PORTABILITY +This function originates from Solaris and is also provided by GNU libc. + +No supporting OS subroutines are required. +*/ + +#ifndef __rtems__ + +#include <_ansi.h> +#include <stdio.h> +#include <stdio_ext.h> +#include "local.h" + +int +_DEFUN(__fsetlocking, (fp, type), + FILE * fp _AND + int type) +{ + int result; + CHECK_INIT(_REENT, fp); + result = (fp->_flags2 & __SNLK) ? FSETLOCKING_BYCALLER : FSETLOCKING_INTERNAL; + switch (type) + { + case FSETLOCKING_BYCALLER: + fp->_flags2 |= __SNLK; + break; + case FSETLOCKING_INTERNAL: + fp->_flags2 &= ~__SNLK; + break; + case FSETLOCKING_QUERY: + default: + break; + } + return result; +} + +#endif /* __rtems__ */ diff --git a/newlib/libc/stdio/local.h b/newlib/libc/stdio/local.h index 24d21360e..434d3f85c 100644 --- a/newlib/libc/stdio/local.h +++ b/newlib/libc/stdio/local.h @@ -68,16 +68,19 @@ { \ int __oldfpcancel; \ pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &__oldfpcancel); \ - _flockfile (_fp) + if (!(_fp->_flags2 & __SNLK)) \ + _flockfile (_fp) /* Exit from a stream oriented critical section prematurely: */ # define _newlib_flockfile_exit(_fp) \ - _funlockfile (_fp); \ + if (!(_fp->_flags2 & __SNLK)) \ + _funlockfile (_fp); \ pthread_setcancelstate (__oldfpcancel, &__oldfpcancel); /* End a stream oriented critical section: */ # define _newlib_flockfile_end(_fp) \ - _funlockfile (_fp); \ + if (!(_fp->_flags2 & __SNLK)) \ + _funlockfile (_fp); \ pthread_setcancelstate (__oldfpcancel, &__oldfpcancel); \ } @@ -99,17 +102,20 @@ pthread_setcancelstate (__oldsfpcancel, &__oldsfpcancel); \ } -#else /* !_STDIO_WITH_THREAD_CANCELLATION_SUPPORT */ +#elif !defined(__SINGLE_THREAD__) /* !_STDIO_WITH_THREAD_CANCELLATION_SUPPORT */ # define _newlib_flockfile_start(_fp) \ { \ - _flockfile(_fp) + if (!(_fp->_flags2 & __SNLK)) \ + _flockfile (_fp) # define _newlib_flockfile_exit(_fp) \ - _funlockfile(_fp); \ + if (!(_fp->_flags2 & __SNLK)) \ + _funlockfile(_fp); \ # define _newlib_flockfile_end(_fp) \ - _funlockfile(_fp); \ + if (!(_fp->_flags2 & __SNLK)) \ + _funlockfile(_fp); \ } # define _newlib_sfp_lock_start() \ @@ -123,6 +129,15 @@ __sfp_lock_release (); \ } +#else /* __SINGLE_THREAD__ */ + +# define _newlib_flockfile_start(_fp) +# define _newlib_flockfile_exit(_fp) +# define _newlib_flockfile_end(_fp) +# define _newlib_sfp_lock_start() +# define _newlib_sfp_lock_exit() +# define _newlib_sfp_lock_end() + #endif /* _STDIO_WITH_THREAD_CANCELLATION_SUPPORT */ extern u_char *_EXFUN(__sccl, (char *, u_char *fmt)); diff --git a/newlib/libc/stdio/stdio.tex b/newlib/libc/stdio/stdio.tex index 7b5427d7b..69a210a24 100644 --- a/newlib/libc/stdio/stdio.tex +++ b/newlib/libc/stdio/stdio.tex @@ -178,6 +178,9 @@ structure. @include stdio/fseek.def @page +@include stdio/fsetlocking.def + +@page @include stdio/fsetpos.def @page |