Changeset 1370


Ignore:
Timestamp:
Apr 15, 2004, 1:00:48 AM (21 years ago)
Author:
bird
Message:

o #1023: Wrote away the _file2 part of streams.
o #1023: Removed _fassign(), _setmode() and _setdummymode().

Location:
trunk/src/emx/src/lib
Files:
1 deleted
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/src/lib/app/stdio.c

    • Property cvs2svn:cvs-rev changed from 1.8 to 1.9
    r1369 r1370  
    33
    44#include "libc-alias.h"
    5 #include <stdio.h>
    6 #include <stdlib.h>
    75#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    86#include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    97#include <sys/rmutex.h>
     8#include <stdio.h>
     9#include <stdlib.h>
    1010#include <emx/io.h>
    1111#include <emx/startup.h>
     
    2222
    2323/** Vector entry for preallocated streams. */
    24 static struct streamvec     gPreStreamVec = {&gaPreFiles[0], NULL, _NFILES};
    25 
    26 /** More structures for preallocated streams. */
    27 static struct _file2        gaPreFile2s[_NFILES];
     24static struct streamvec     gPreStreamVec = {_NFILES, NULL, &gaPreFiles[0], NULL, _NFILES};
    2825
    2926/** The buffer for stdin. */
     
    3835 */
    3936
    40 /** Head of the stream vector. */
     37/** Head of the stream vector list. */
    4138struct streamvec           *_streamvec_head = NULL;
     39/** Tail of the stream vector list. */
     40struct streamvec           *_streamvec_tail = NULL;
    4241
    4342/** Standard input stream pointer. */
     
    5857    LIBCLOG_ENTER("\n");
    5958    struct _FILE       *pFile;
    60     struct _file2      *pFile2;
    6159    int                 i;
    6260    static char         fInited = 0;
     
    7472     */
    7573    pFile   = &gaPreFiles[0];
    76     pFile2  = &gaPreFile2s[0];
    77     for (i = 0; i < _NFILES; i++, pFile++, pFile2++)
    78     {
    79         pFile2->owner = pFile; /* obsolete? */
    80         pFile->_more = pFile2;
    81     }
     74    for (i = 0; i < _NFILES; i++, pFile++)
     75        pFile->__pSV = &gPreStreamVec;
    8276
    8377    /*
     
    8579     * ASSUME: we're ALONE at this point.
    8680     */
    87     gPreStreamVec.next  = _streamvec_head;
    8881    _streamvec_head     = &gPreStreamVec;
     82    _streamvec_tail     = &gPreStreamVec;
    8983    _rmutex_checked_create(&_streamv_rmutex, 0);
    9084
     
    10296             * Common init - recall everything is ZERO.
    10397             */
    104             gaPreFiles[i]._flags    |= _IOOPEN;
     98            gPreStreamVec.cFree--;
     99            gaPreFiles[i]._flags    |= _IOOPEN | _IONOCLOSEALL;
    105100            gaPreFiles[i]._handle    = i;
    106101            gaPreFiles[i]._flush     = _flushstream;
    107             if (_setmore(&gaPreFiles[i], 0))
     102            if (_rmutex_create (&gaPreFiles[i].__u.__rsem, 0) != 0)
    108103            {
    109104                LIBC_ASSERTM_FAILED("_setmore failed for i=%d\n", i);
  • trunk/src/emx/src/lib/io/_fopen.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1369 r1370  
    22
    33#include "libc-alias.h"
    4 #include <stdio.h>
    54#include <io.h>
    65#include <fcntl.h>
    76#include <errno.h>
     7#include <sys/builtin.h>        /* For <sys/fmutex.h> */
     8#include <sys/fmutex.h>         /* For <sys/rmutex.h> */
     9#include <sys/rmutex.h>
     10#include <stdio.h>
    811#include <emx/io.h>
    912
     
    7578      if (ok) ++mode;
    7679    }
    77   dst->_ptr = NULL;
    78   dst->_buffer = NULL;
    79   dst->_buf_size = 0;
    80   dst->_rcount = 0;
    81   dst->_wcount = 0;
    82   dst->_tmpidx = 0;
    83   dst->_ungetc_count = 0;
    8480  dst->_flags |= _IOOPEN | _IOBUFNONE;
    8581  dst->_flush = _flushstream;
    86   if (_setmore (dst, lock) != 0)
    87     return NULL;
     82  if (_rmutex_create (&dst->__u.__rsem, 0) != 0)
     83    {
     84      _closestream (dst);
     85      return NULL;
     86    }
    8887  dst->_handle = sopen (fname, omode, shflag, 0644);
    8988  if (dst->_handle < 0)
  • trunk/src/emx/src/lib/io/_mfopen.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1369 r1370  
    22
    33#include "libc-alias.h"
    4 #include <stdio.h>
    54#include <stdlib.h>
    65#include <errno.h>
     6#include <sys/builtin.h>        /* For <sys/fmutex.h> */
     7#include <sys/fmutex.h>         /* For <sys/rmutex.h> */
     8#include <sys/rmutex.h>
     9#include <stdio.h>
    710#include <emx/io.h>
    811
     
    8689  stream->_tmpidx = inc;
    8790  stream->_ungetc_count = 0;
    88   if (_setmore (stream, 1) != 0)
     91  if (_rmutex_create (&stream->__u.__rsem, 0) != 0)
    8992    {
    9093      if (abuf != NULL) free (abuf);
  • trunk/src/emx/src/lib/io/_newstre.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1369 r1370  
    33
    44#include "libc-alias.h"
    5 #include <stdio.h>
    65#include <stdlib.h>
    76#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    87#include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    98#include <sys/rmutex.h>
     9#include <stdio.h>
     10#include <emx/io.h>
    1011#include <emx/umalloc.h>
    11 #include <emx/io.h>
    1212
    13 #define INC     32
     13#define INC     64
    1414#define ALIGN(p, a) (((unsigned long)(p) + (a) - 1) & ~((a) - 1))
    1515
     
    1818    int                 i;
    1919    struct streamvec   *pSV;
    20     struct streamvec   *pSVNew;
    2120
    2221    /*
    2322     * Search thru the list of streams.
     23     * Backwards as we're more likely to find free itmes at the end.
    2424     */
    2525    STREAMV_LOCK;
    26     for (pSV = _streamvec_head; pSV != NULL; pSV = pSV->next)
     26    for (pSV = _streamvec_tail; pSV != NULL; pSV = pSV->pPrev)
    2727    {
    28         for (i = 0; i < pSV->n; ++i)
     28        if (pSV->cFree > 0)
    2929        {
    30             if (!(pSV->vec[i]._flags & (_IOOPEN|_IONEW)))
     30            for (i = 0; i < pSV->cFiles; ++i)
    3131            {
    32                 pSV->vec[i]._flags = _IONEW;
    33                 STREAMV_UNLOCK;
    34                 return &pSV->vec[i];
     32                if (!(pSV->aFiles[i]._flags & (_IOOPEN|_IONEW)))
     33                {
     34                    pSV->aFiles[i]._flags = _IONEW;
     35                    pSV->cFree--;
     36                    STREAMV_UNLOCK;
     37
     38                    /*
     39                     * We zero all members up till the __pSV member
     40                     * before returning the handle to the caller.
     41                     */
     42                    memset(&pSV->aFiles[i], 0, offsetof(FILE, __pSV));
     43                    return &pSV->aFiles[i];
     44                }
    3545            }
    3646        }
     
    4252     * (As the entries must not move, we add another segment.)
    4353     */
    44     pSVNew = _hcalloc(1, sizeof(*pSV) + 15
    45                       + INC * sizeof(struct _FILE)
    46                       + 15
    47                       + INC * sizeof(struct _file2));
    48     if (pSVNew)
     54    pSV = _hcalloc(1, sizeof(*pSV) + 15
     55                   + INC * sizeof(struct _FILE)
     56                   + 15
     57                   );
     58    if (pSV)
    4959    {
    5060        struct _FILE       *pFile;
    51         struct _file2      *pFile2;
    5261
    5362        /*
     
    5564         * Remember everything is ZEROed by calloc()!
    5665         */
    57         pSVNew->vec = pFile = (struct _FILE  *)ALIGN(pSVNew + 1, 16);
    58         pFile2              = (struct _file2 *)ALIGN(&pFile[INC], 16);
    59         pSVNew->vec         = pFile;
    60         pSVNew->n           = INC;
    61         for (i = 0; i < INC; i++, pFile++, pFile2++)
    62         {
    63             pFile2->owner = pFile; /* obsolete? */
    64             pFile->_more = pFile2;
    65         }
     66        pSV->aFiles = pFile = (struct _FILE  *)ALIGN(pSV + 1, 16);
     67        pSV->aFiles         = pFile;
     68        pSV->cFiles         = INC;
     69        pSV->cFree          = INC - 1;
     70        for (i = 0; i < INC; i++, pFile++)
     71            pFile->__pSV = pSV;
    6672
    6773        /*
    6874         * Allocate the first one.
    6975         */
    70         pFile = &pSVNew->vec[0];
     76        pFile = &pSV->aFiles[0];
    7177        pFile->_flags = _IONEW;
    7278
     
    7581         */
    7682        STREAMV_LOCK;
    77         if (_streamvec_head)
    78         {
    79             for (pSV = _streamvec_head; pSV; pSV = pSV->next)
    80                 if (!pSV->next)
    81                 {
    82                     pSV->next = pSVNew;
    83                     break;
    84                 }
    85         }
     83        pSV->pPrev = _streamvec_tail;
     84        /* pNext is NULLed by calloc(). */
     85        if (_streamvec_tail)
     86            _streamvec_tail = _streamvec_tail->pNext = pSV;
    8687        else
    8788            /* Someone fopen'ed something before streams were initated. */
    88             _streamvec_head = pSVNew;
     89            _streamvec_head = _streamvec_tail = pSV;
    8990        STREAMV_UNLOCK;
    9091        return pFile;
     
    9293
    9394    return NULL;
    94 }
    95 
    96 /**
    97  * This used to set the _more member, but now it only create the mutex and
    98  * init _mbstate.
    99  *
    100  * @returns 0 on success.
    101  * @returns -1 on failure
    102  * @param   stream  Stream to init.
    103  * @param   lock    Ignored.
    104  */
    105 int _setmore(FILE *stream, int lock)
    106 {
    107     /*
    108      * Now this isn't so much work any longer, the streams are
    109      * allocated with a more buffer by default now.
    110      * All we gotta do is init _mbstate and create the mutex.
    111      */
    112     stream->_mbstate = 0;
    113     if (_rmutex_create(&stream->_more->rsem, 0) != 0)
    114     {
    115         /* free the stream */
    116         stream->_flags = 0;
    117         lock = lock;
    118         return -1;
    119     }
    120     return 0;
    121 }
    122 
    123 /**
    124  * This is used when creating a special stream for instance in vsprintf().
    125  *
    126  * @param   stream  Special stream.
    127  * @param   more    Dummy more block
    128  */
    129 void _setdummymore (FILE *stream, struct _file2 *more)
    130 {
    131     stream->_mbstate = 0;
    132     stream->_more = more;
    133     more->owner = stream;
    134     _rmutex_dummy(&more->rsem);
    13595}
    13696
     
    143103void _closestream(FILE *stream)
    144104{
    145     if (    stream->_more != NULL
    146         &&  stream->_more->owner == stream) /* paranoia */
    147         _rmutex_close(&stream->_more->rsem);
    148105    stream->_flags = 0;
     106    /* Assumption hare made about how the dummy stuff is made. */
     107    if (stream->__u.__rsem.fm.hev)
     108        _rmutex_close(&stream->__u.__rsem);
     109
     110    if (stream->__pSV)
     111    {
     112        STREAMV_LOCK;
     113        ((struct streamvec *)stream->__pSV)->cFree++;
     114        STREAMV_UNLOCK;
     115    }
    149116}
  • trunk/src/emx/src/lib/io/_rmtmp.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1369 r1370  
    1717
    1818  n = 0;
    19   for (sv = _streamvec_head; sv != NULL; sv = sv->next)
    20     for (i = 0; i < sv->n; ++i)
    21       if ((sv->vec[i]._flags & _IOOPEN) && (sv->vec[i]._flags & _IOTMP)
    22           && STREAM_UNLOCKED (&sv->vec[i])
    23           && fclose (&sv->vec[i]) == 0)
     19  for (sv = _streamvec_head; sv != NULL; sv = sv->pNext)
     20    for (i = 0; i < sv->cFiles; ++i)
     21      if ((sv->aFiles[i]._flags & _IOOPEN) && (sv->aFiles[i]._flags & _IOTMP)
     22          && STREAM_UNLOCKED (&sv->aFiles[i])
     23          && fclose (&sv->aFiles[i]) == 0)
    2424        ++n;
    2525  return n;
  • trunk/src/emx/src/lib/io/fcloseal.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1369 r1370  
    1212
    1313  n = 0; ok = 1;
    14   for (sv = _streamvec_head; sv != NULL; sv = sv->next)
     14  for (sv = _streamvec_head; sv != NULL; sv = sv->pNext)
    1515    {
    16       for (i = sv->vec == stdin ? 3 : 0; /* Keep stdin, stdout, stderr */
    17            i < sv->n;
    18            ++i)
    19         if (sv->vec[i]._flags & _IOOPEN)
     16      for (i = 0; i < sv->cFiles; ++i)
     17        if ((sv->aFiles[i]._flags & (_IOOPEN | _IONOCLOSEALL)) == _IOOPEN)
    2018          {
    21             if (fclose (&sv->vec[i]) == 0)
     19            if (fclose (&sv->aFiles[i]) == 0)
    2220              ++n;
    2321            else
  • trunk/src/emx/src/lib/io/fdopen.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1369 r1370  
    22
    33#include "libc-alias.h"
    4 #include <stdio.h>
    54#include <io.h>
    65#include <fcntl.h>
    76#include <errno.h>
     7#include <sys/builtin.h>        /* For <sys/fmutex.h> */
     8#include <sys/fmutex.h>         /* For <sys/rmutex.h> */
     9#include <sys/rmutex.h>
     10#include <stdio.h>
     11#include <stdio.h>
    812#include <emx/io.h>
    913
     
    2529    }
    2630  dst = _newstream ();
     31  if (!dst)
     32    return NULL;
     33  if (_rmutex_create (&dst->__u.__rsem, 0) != 0)
     34    {
     35      _closestream (dst);
     36      return NULL;
     37    }
    2738  switch (*mode)
    2839    {
     
    8091    setmode (handle, omode);
    8192  dst->_handle = handle;
    82   dst->_ptr = NULL;
    83   dst->_buffer = NULL;
    84   dst->_buf_size = 0;
    85   dst->_rcount = 0;
    86   dst->_wcount = 0;
    8793  dst->_flags |= _IOOPEN | _IOBUFNONE;
    8894  dst->_flush = _flushstream;
    89   dst->_ungetc_count = 0;
    90   if (_setmore (dst, 1) != 0)
    91     return NULL;
    9295  return dst;
    9396}
  • trunk/src/emx/src/lib/io/fflush.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1369 r1370  
    7373  if (stream == NULL)
    7474    {
    75       for (sv = _streamvec_head; sv != NULL; sv = sv->next)
    76         for (n = 0; n < sv->n; ++n)
    77           if ((sv->vec[n]._flags & (_IOOPEN|_IOWRT)) == (_IOOPEN|_IOWRT))
    78             if (fflush (&sv->vec[n]) != 0)
     75      for (sv = _streamvec_head; sv != NULL; sv = sv->pNext)
     76        for (n = 0; n < sv->cFiles; ++n)
     77          if ((sv->aFiles[n]._flags & (_IOOPEN|_IOWRT)) == (_IOOPEN|_IOWRT))
     78            if (fflush (&sv->aFiles[n]) != 0)
    7979              result = EOF;
    8080      return result;
  • trunk/src/emx/src/lib/io/flushall.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1369 r1370  
    1818
    1919  n = 0;
    20   for (sv = _streamvec_head; sv != NULL; sv = sv->next)
    21     for (i = 0; i < sv->n; ++i)
    22       if ((sv->vec[i]._flags & _IOOPEN) && STREAM_LOCK_NOWAIT (&sv->vec[i]))
     20  for (sv = _streamvec_head; sv != NULL; sv = sv->pNext)
     21    for (i = 0; i < sv->cFiles; ++i)
     22      if ((sv->aFiles[i]._flags & _IOOPEN) && STREAM_LOCK_NOWAIT (&sv->aFiles[i]))
    2323        {
    2424          ++n;
    25           _fflush_nolock (&sv->vec[i]);
    26           STREAM_UNLOCK (&sv->vec[i]);
     25          _fflush_nolock (&sv->aFiles[i]);
     26          STREAM_UNLOCK (&sv->aFiles[i]);
    2727        }
    2828  return n;
  • trunk/src/emx/src/lib/io/snprintf.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1369 r1370  
    22
    33#include "libc-alias.h"
     4#include <sys/builtin.h>        /* For <sys/fmutex.h> */
     5#include <sys/fmutex.h>         /* For <sys/rmutex.h> */
     6#include <sys/rmutex.h>
     7#include <stdio.h>
    48#include <stdio.h>
    59#include <stdarg.h>
     
    1115  va_list arg_ptr;
    1216  FILE trick;
    13   struct _file2 trick2;
    1417  int result;
    1518
     
    2629  trick._flush = NULL;
    2730  trick._ungetc_count = 0;
    28   _setdummymore (&trick, &trick2);
     31  trick._mbstate = 0;
     32  _rmutex_dummy(&trick.__u.__rsem);
    2933  result = _output (&trick, format, arg_ptr);
    3034  if (n != 0)
  • trunk/src/emx/src/lib/io/sprintf.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1369 r1370  
    22
    33#include "libc-alias.h"
     4#include <sys/builtin.h>        /* For <sys/fmutex.h> */
     5#include <sys/fmutex.h>         /* For <sys/rmutex.h> */
     6#include <sys/rmutex.h>
     7#include <stdio.h>
    48#include <stdio.h>
    59#include <stdarg.h>
     
    1115  va_list arg_ptr;
    1216  FILE trick;
    13   struct _file2 trick2;
    1417  int result;
    1518
     
    2427  trick._flush = NULL;
    2528  trick._ungetc_count = 0;
    26   _setdummymore (&trick, &trick2);
     29  trick._mbstate = 0;
     30  _rmutex_dummy(&trick.__u.__rsem);
    2731  result = _output (&trick, format, arg_ptr);
    2832  putc (0, &trick);
  • trunk/src/emx/src/lib/io/sscanf.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1369 r1370  
    22
    33#include "libc-alias.h"
     4#include <sys/builtin.h>        /* For <sys/fmutex.h> */
     5#include <sys/fmutex.h>         /* For <sys/rmutex.h> */
     6#include <sys/rmutex.h>
     7#include <stdio.h>
    48#include <stdio.h>
    59#include <stdarg.h>
     
    1216  va_list arg_ptr;
    1317  FILE trick;
    14   struct _file2 trick2;
    1518  int result;
    1619
     
    2528  trick._flush = NULL;
    2629  trick._ungetc_count = 0;
    27   _setdummymore (&trick, &trick2);
     30  trick._mbstate = 0;
     31  _rmutex_dummy(&trick.__u.__rsem);
    2832  result = _input (&trick, format, arg_ptr);
    2933  va_end (arg_ptr);
  • trunk/src/emx/src/lib/io/vsnprint.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1369 r1370  
    22
    33#include "libc-alias.h"
     4#include <sys/builtin.h>        /* For <sys/fmutex.h> */
     5#include <sys/fmutex.h>         /* For <sys/rmutex.h> */
     6#include <sys/rmutex.h>
     7#include <stdio.h>
    48#include <stdio.h>
    59#include <limits.h>
     
    913{
    1014  FILE trick;
    11   struct _file2 trick2;
    1215  int result;
    1316
     
    2326  trick._flush = NULL;
    2427  trick._ungetc_count = 0;
    25   _setdummymore (&trick, &trick2);
     28  trick._mbstate = 0;
     29  _rmutex_dummy(&trick.__u.__rsem);
    2630  result = _output (&trick, format, arg_ptr);
    2731  if (n != 0)
  • trunk/src/emx/src/lib/io/vsprintf.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1369 r1370  
    22
    33#include "libc-alias.h"
     4#include <sys/builtin.h>        /* For <sys/fmutex.h> */
     5#include <sys/fmutex.h>         /* For <sys/rmutex.h> */
     6#include <sys/rmutex.h>
     7#include <stdio.h>
    48#include <stdio.h>
    59#include <limits.h>
     
    913{
    1014  FILE trick;
    11   struct _file2 trick2;
    1215  int result;
    1316
     
    2124  trick._flush = NULL;
    2225  trick._ungetc_count = 0;
    23   _setdummymore (&trick, &trick2);
     26  trick._mbstate = 0;
     27  _rmutex_dummy(&trick.__u.__rsem);
    2428  result = _output (&trick, format, arg_ptr);
    2529  putc (0, &trick);
  • trunk/src/emx/src/lib/io/vsscanf.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1369 r1370  
    22
    33#include "libc-alias.h"
     4#include <sys/builtin.h>        /* For <sys/fmutex.h> */
     5#include <sys/fmutex.h>         /* For <sys/rmutex.h> */
     6#include <sys/rmutex.h>
     7#include <stdio.h>
    48#include <stdio.h>
    59#include <stdarg.h>
     
    1115{
    1216  FILE trick;
    13   struct _file2 trick2;
    1417  int result;
    1518
     
    2326  trick._flush = NULL;
    2427  trick._ungetc_count = 0;
    25   _setdummymore (&trick, &trick2);
     28  trick._mbstate = 0;
     29  _rmutex_dummy(&trick.__u.__rsem);
    2630  result = _input (&trick, format, arg_ptr);
    2731  return result;
Note: See TracChangeset for help on using the changeset viewer.