home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 November / PCONLINE_11_99.ISO / filesbbs / OS2 / CDR18A24.ZIP / source / fifo.c.diff < prev    next >
Encoding:
Text File  |  1999-08-22  |  6.8 KB  |  280 lines

  1. *** d:/os2/tmp/fifo.c_a00037    Sun Aug 22 11:49:48 1999
  2. --- d:/os2/tmp/fifo.c_b00037    Sun Aug 22 11:49:48 1999
  3. ***************
  4. *** 31,37 ****
  5.   #define    DEBUG
  6.   /*#define    XDEBUG*/
  7.   #include <mconfig.h>
  8. ! #if    !defined(HAVE_SMMAP) && !defined(HAVE_USGSHM)
  9.   #undef    FIFO            /* We cannot have a FIFO on this platform */
  10.   #endif
  11.   #ifdef    FIFO
  12. --- 31,37 ----
  13.   #define    DEBUG
  14.   /*#define    XDEBUG*/
  15.   #include <mconfig.h>
  16. ! #if    !defined(HAVE_SMMAP) && !defined(HAVE_USGSHM) && !defined(HAVE_ALLOCSHAREDMEM)
  17.   #undef    FIFO            /* We cannot have a FIFO on this platform */
  18.   #endif
  19.   #ifdef    FIFO
  20. ***************
  21. *** 46,51 ****
  22. --- 46,57 ----
  23.   #    undef    USE_USGSHM    /* mmap() is preferred            */
  24.   #endif
  25.   
  26. + #ifdef HAVE_ALLOCSHAREDMEM /* This is for OS/2 */
  27. + #define     USE_OS2SHM
  28. + #    undef    USE_MMAP
  29. + #    undef    USE_USGSHM
  30. + #endif
  31.   #include <fctldefs.h>
  32.   #include <sys/types.h>
  33.   #if defined(HAVE_SMMAP) && defined(USE_MMAP)
  34. ***************
  35. *** 129,134 ****
  36. --- 135,141 ----
  37.   #define    READER_MAXWAIT    (240*SECS)    /* 240 seconds max wait for reader */
  38.   
  39.   LOCAL    char    *buf;
  40.   LOCAL    char    *bufbase;
  41.   LOCAL    char    *bufend;
  42.   LOCAL    long    buflen;
  43. ***************
  44. *** 143,148 ****
  45. --- 150,159 ----
  46.   #ifdef    USE_USGSHM
  47.   LOCAL    char*    mkshm        __PR((int size));
  48.   #endif
  49. + #ifdef    USE_OS2SHM
  50. + LOCAL    char*    mkos2shm        __PR((int size));
  51. + #endif
  52.   EXPORT    BOOL    init_faio    __PR((int tracks, track_t *track, int));
  53.   EXPORT    BOOL    await_faio    __PR((void));
  54.   EXPORT    void    kill_faio    __PR((void));
  55. ***************
  56. *** 182,187 ****
  57. --- 193,202 ----
  58.   #if    defined(USE_USGSHM)
  59.       buf = mkshm(buflen);
  60.   #endif
  61. + #if    defined(USE_OS2SHM)
  62. +     buf = mkos2shm(buflen);
  63. + #endif
  64.       bufbase = buf;
  65.       bufend = buf + buflen;
  66.       EDEBUG(("buf: %X bufend: %X, buflen: %ld\n", buf, bufend, buflen));
  67. ***************
  68. *** 193,198 ****
  69. --- 208,214 ----
  70.        * Dirty the whole buffer. This can die with various signals if
  71.        * we're trying to lock too much memory
  72.        */
  73.       fillbytes(buf, buflen, '\0');
  74.   
  75.   #ifdef    XDEBUG
  76. ***************
  77. *** 268,281 ****
  78.        * Although SHM_LOCK is standard, it seems that all versions of AIX
  79.        * ommit this definition.
  80.        */
  81.       if (shmctl(id, SHM_LOCK, 0) < 0)
  82. !         comerr("shmctl failed to lock shared memory segment\n");
  83.   #endif
  84.   
  85.       return (addr);
  86.   }
  87.   #endif
  88.   
  89.   LOCAL    int    faio_buffers;
  90.   LOCAL    int    faio_buf_size;
  91.   LOCAL    int    buf_idx;
  92. --- 284,316 ----
  93.        * Although SHM_LOCK is standard, it seems that all versions of AIX
  94.        * ommit this definition.
  95.        */
  96.       if (shmctl(id, SHM_LOCK, 0) < 0)
  97. !     comerr("shmctl failed to lock shared memory segment\n");
  98.   #endif
  99.   
  100.       return (addr);
  101.   }
  102.   #endif
  103.   
  104. + #ifdef USE_OS2SHM
  105. + LOCAL char *
  106. + mkos2shm(size)
  107. +     int    size;
  108. + {
  109. +     char    *addr;
  110. +     /* The OS/2 implementation of shm (using shm.dll) limits the size of one shared
  111. +        memory segment to 0x3fa000 (aprox. 4MBytes). Using OS/2 native API we have
  112. +        no such restriction so I decided to use it allowing fifos of arbitrary size.  
  113. +        */
  114. +     if(DosAllocSharedMem(&addr,NULL,size,0X100L | 0x1L | 0x2L | 0x10L)) 
  115. +       comerr("\nDosAllocSharedMem() failed\n");
  116. +     if (debug) errmsgno(EX_BAD, "shared memory allocated at address: %x\n", addr);    
  117. +     return (addr);
  118. + }
  119. + #endif
  120.   LOCAL    int    faio_buffers;
  121.   LOCAL    int    faio_buf_size;
  122.   LOCAL    int    buf_idx;
  123. ***************
  124. *** 330,336 ****
  125.                           MIN_BUFFERS*bufsize/1024);
  126.           return (FALSE);
  127.       }
  128. !     
  129.       if (debug)
  130.           printf("Using %d buffers of %d bytes.\n", faio_buffers, faio_buf_size);
  131.   
  132. --- 365,371 ----
  133.                           MIN_BUFFERS*bufsize/1024);
  134.           return (FALSE);
  135.       }
  136.       if (debug)
  137.           printf("Using %d buffers of %d bytes.\n", faio_buffers, faio_buf_size);
  138.   
  139. ***************
  140. *** 344,349 ****
  141. --- 379,385 ----
  142.           f->bufp = base;
  143.           f->fd = -1;
  144.       }
  145.       sp = (struct faio_stats *)f;    /* point past headers */
  146.       sp->gets = sp->puts = sp->done = 0L;
  147.   
  148. ***************
  149. *** 354,360 ****
  150.       if (faio_pid == 0) {
  151.           /* child process */
  152.           raisepri(1);        /* almost max priority */
  153.           /* Ignoring SIGALRM cures the SCO usleep() bug */
  154.   /*        signal(SIGALRM, SIG_IGN);*/
  155.           faio_reader(tracks, track);
  156. --- 390,398 ----
  157.       if (faio_pid == 0) {
  158.           /* child process */
  159.           raisepri(1);        /* almost max priority */
  160. ! #ifdef USE_OS2SHM
  161. !         DosGetSharedMem(buf,3);/* PAG_READ|PAG_WRITE */
  162. ! #endif
  163.           /* Ignoring SIGALRM cures the SCO usleep() bug */
  164.   /*        signal(SIGALRM, SIG_IGN);*/
  165.           faio_reader(tracks, track);
  166. ***************
  167. *** 363,368 ****
  168. --- 401,407 ----
  169.           /* close all file-descriptors that only the child will use */
  170.           for (n = 1; n <= tracks; n++)
  171.               close(track[n].f);
  172. +         /*printf("Init 2... PID: %d, f: %X, &buf: %X, buf: %X, *buf: %X\n",faio_pid,1,&buf, (int)buf,*buf);*/
  173.       }
  174.   
  175.       return (TRUE);
  176. ***************
  177. *** 420,432 ****
  178.       int    trackno;
  179.   
  180.       if (debug)
  181. !         printf("\nfaio_reader starting\n");
  182.   
  183.       for (trackno = 1; trackno <= tracks; trackno++) {
  184.           if (debug)
  185.               printf("\nfaio_reader reading track %d\n", trackno);
  186.           faio_read_track(&track[trackno]);
  187.       }
  188.       sp->done++;
  189.       if (debug)
  190.           printf("\nfaio_reader all tracks read, exiting\n");
  191. --- 459,472 ----
  192.       int    trackno;
  193.   
  194.       if (debug)
  195. !         printf("\nfaio_reader starting, PID: %d\n",faio_pid);
  196.   
  197.       for (trackno = 1; trackno <= tracks; trackno++) {
  198.           if (debug)
  199.               printf("\nfaio_reader reading track %d\n", trackno);
  200.           faio_read_track(&track[trackno]);
  201.       }
  202.       sp->done++;
  203.       if (debug)
  204.           printf("\nfaio_reader all tracks read, exiting\n");
  205. ***************
  206. *** 435,443 ****
  207.       if (sp->gets == 0)
  208.           faio_ref(faio_buffers - 1)->owner = owner_reader;
  209.   
  210.       if (debug)
  211. !         error("\faio_reader _exit(0)\n");
  212. !     _exit(0);
  213.   }
  214.   
  215.   #ifndef    faio_ref
  216. --- 475,488 ----
  217.       if (sp->gets == 0)
  218.           faio_ref(faio_buffers - 1)->owner = owner_reader;
  219.   
  220. + #ifdef USE_OS2SHM
  221. +     DosFreeMem(buf);
  222. +     sleep(30000); /* If calling _exit() here the parent process seems to be blocked */
  223. + #endif
  224.       if (debug)
  225. !         error("\nfaio_reader _exit(0)\n");
  226. !         _exit(0);     
  227.   }
  228.   
  229.   #ifndef    faio_ref
  230. ***************
  231. *** 481,486 ****
  232. --- 526,532 ----
  233.           if (l <= 0)
  234.               break;
  235.           bytes_read += l;
  236.       } while (tracksize < 0 || bytes_read < tracksize);
  237.   
  238.       close(fd);    /* Don't keep files open longer than neccesary */
  239. ***************
  240. *** 495,506 ****
  241.   {
  242.       unsigned long max_loops;
  243.   
  244. !     if (f->owner == s)
  245. !         return;        /* return immediately if the buffer is ours */
  246.   
  247.       if (s == owner_reader)
  248.           sp->empty++;
  249. !     else
  250.           sp->full++;
  251.   
  252.       max_loops = max_wait / delay + 1;
  253. --- 541,552 ----
  254.   {
  255.       unsigned long max_loops;
  256.   
  257. !     if (f->owner == s)
  258. !       return;        /* return immediately if the buffer is ours */
  259.   
  260.       if (s == owner_reader)
  261.           sp->empty++;
  262. !     else 
  263.           sp->full++;
  264.   
  265.       max_loops = max_wait / delay + 1;
  266.