home *** CD-ROM | disk | FTP | other *** search
- *** d:/os2/tmp/fifo.c_a00037 Sun Aug 22 11:49:48 1999
- --- d:/os2/tmp/fifo.c_b00037 Sun Aug 22 11:49:48 1999
- ***************
- *** 31,37 ****
- #define DEBUG
- /*#define XDEBUG*/
- #include <mconfig.h>
- ! #if !defined(HAVE_SMMAP) && !defined(HAVE_USGSHM)
- #undef FIFO /* We cannot have a FIFO on this platform */
- #endif
- #ifdef FIFO
- --- 31,37 ----
- #define DEBUG
- /*#define XDEBUG*/
- #include <mconfig.h>
- ! #if !defined(HAVE_SMMAP) && !defined(HAVE_USGSHM) && !defined(HAVE_ALLOCSHAREDMEM)
- #undef FIFO /* We cannot have a FIFO on this platform */
- #endif
- #ifdef FIFO
- ***************
- *** 46,51 ****
- --- 46,57 ----
- # undef USE_USGSHM /* mmap() is preferred */
- #endif
-
- + #ifdef HAVE_ALLOCSHAREDMEM /* This is for OS/2 */
- + #define USE_OS2SHM
- + # undef USE_MMAP
- + # undef USE_USGSHM
- + #endif
- +
- #include <fctldefs.h>
- #include <sys/types.h>
- #if defined(HAVE_SMMAP) && defined(USE_MMAP)
- ***************
- *** 129,134 ****
- --- 135,141 ----
- #define READER_MAXWAIT (240*SECS) /* 240 seconds max wait for reader */
-
- LOCAL char *buf;
- +
- LOCAL char *bufbase;
- LOCAL char *bufend;
- LOCAL long buflen;
- ***************
- *** 143,148 ****
- --- 150,159 ----
- #ifdef USE_USGSHM
- LOCAL char* mkshm __PR((int size));
- #endif
- + #ifdef USE_OS2SHM
- + LOCAL char* mkos2shm __PR((int size));
- + #endif
- +
- EXPORT BOOL init_faio __PR((int tracks, track_t *track, int));
- EXPORT BOOL await_faio __PR((void));
- EXPORT void kill_faio __PR((void));
- ***************
- *** 182,187 ****
- --- 193,202 ----
- #if defined(USE_USGSHM)
- buf = mkshm(buflen);
- #endif
- + #if defined(USE_OS2SHM)
- + buf = mkos2shm(buflen);
- + #endif
- +
- bufbase = buf;
- bufend = buf + buflen;
- EDEBUG(("buf: %X bufend: %X, buflen: %ld\n", buf, bufend, buflen));
- ***************
- *** 193,198 ****
- --- 208,214 ----
- * Dirty the whole buffer. This can die with various signals if
- * we're trying to lock too much memory
- */
- +
- fillbytes(buf, buflen, '\0');
-
- #ifdef XDEBUG
- ***************
- *** 268,281 ****
- * Although SHM_LOCK is standard, it seems that all versions of AIX
- * ommit this definition.
- */
- if (shmctl(id, SHM_LOCK, 0) < 0)
- ! comerr("shmctl failed to lock shared memory segment\n");
- #endif
-
- return (addr);
- }
- #endif
-
- LOCAL int faio_buffers;
- LOCAL int faio_buf_size;
- LOCAL int buf_idx;
- --- 284,316 ----
- * Although SHM_LOCK is standard, it seems that all versions of AIX
- * ommit this definition.
- */
- +
- if (shmctl(id, SHM_LOCK, 0) < 0)
- ! comerr("shmctl failed to lock shared memory segment\n");
- #endif
-
- return (addr);
- }
- #endif
-
- + #ifdef USE_OS2SHM
- + LOCAL char *
- + mkos2shm(size)
- + int size;
- + {
- + char *addr;
- + /* The OS/2 implementation of shm (using shm.dll) limits the size of one shared
- + memory segment to 0x3fa000 (aprox. 4MBytes). Using OS/2 native API we have
- + no such restriction so I decided to use it allowing fifos of arbitrary size.
- + */
- + if(DosAllocSharedMem(&addr,NULL,size,0X100L | 0x1L | 0x2L | 0x10L))
- + comerr("\nDosAllocSharedMem() failed\n");
- +
- + if (debug) errmsgno(EX_BAD, "shared memory allocated at address: %x\n", addr);
- + return (addr);
- + }
- + #endif
- +
- LOCAL int faio_buffers;
- LOCAL int faio_buf_size;
- LOCAL int buf_idx;
- ***************
- *** 330,336 ****
- MIN_BUFFERS*bufsize/1024);
- return (FALSE);
- }
- !
- if (debug)
- printf("Using %d buffers of %d bytes.\n", faio_buffers, faio_buf_size);
-
- --- 365,371 ----
- MIN_BUFFERS*bufsize/1024);
- return (FALSE);
- }
- !
- if (debug)
- printf("Using %d buffers of %d bytes.\n", faio_buffers, faio_buf_size);
-
- ***************
- *** 344,349 ****
- --- 379,385 ----
- f->bufp = base;
- f->fd = -1;
- }
- +
- sp = (struct faio_stats *)f; /* point past headers */
- sp->gets = sp->puts = sp->done = 0L;
-
- ***************
- *** 354,360 ****
- if (faio_pid == 0) {
- /* child process */
- raisepri(1); /* almost max priority */
- !
- /* Ignoring SIGALRM cures the SCO usleep() bug */
- /* signal(SIGALRM, SIG_IGN);*/
- faio_reader(tracks, track);
- --- 390,398 ----
- if (faio_pid == 0) {
- /* child process */
- raisepri(1); /* almost max priority */
- ! #ifdef USE_OS2SHM
- ! DosGetSharedMem(buf,3);/* PAG_READ|PAG_WRITE */
- ! #endif
- /* Ignoring SIGALRM cures the SCO usleep() bug */
- /* signal(SIGALRM, SIG_IGN);*/
- faio_reader(tracks, track);
- ***************
- *** 363,368 ****
- --- 401,407 ----
- /* close all file-descriptors that only the child will use */
- for (n = 1; n <= tracks; n++)
- close(track[n].f);
- + /*printf("Init 2... PID: %d, f: %X, &buf: %X, buf: %X, *buf: %X\n",faio_pid,1,&buf, (int)buf,*buf);*/
- }
-
- return (TRUE);
- ***************
- *** 420,432 ****
- int trackno;
-
- if (debug)
- ! printf("\nfaio_reader starting\n");
-
- for (trackno = 1; trackno <= tracks; trackno++) {
- if (debug)
- printf("\nfaio_reader reading track %d\n", trackno);
- faio_read_track(&track[trackno]);
- }
- sp->done++;
- if (debug)
- printf("\nfaio_reader all tracks read, exiting\n");
- --- 459,472 ----
- int trackno;
-
- if (debug)
- ! printf("\nfaio_reader starting, PID: %d\n",faio_pid);
-
- for (trackno = 1; trackno <= tracks; trackno++) {
- if (debug)
- printf("\nfaio_reader reading track %d\n", trackno);
- faio_read_track(&track[trackno]);
- }
- +
- sp->done++;
- if (debug)
- printf("\nfaio_reader all tracks read, exiting\n");
- ***************
- *** 435,443 ****
- if (sp->gets == 0)
- faio_ref(faio_buffers - 1)->owner = owner_reader;
-
- if (debug)
- ! error("\faio_reader _exit(0)\n");
- ! _exit(0);
- }
-
- #ifndef faio_ref
- --- 475,488 ----
- if (sp->gets == 0)
- faio_ref(faio_buffers - 1)->owner = owner_reader;
-
- + #ifdef USE_OS2SHM
- + DosFreeMem(buf);
- + sleep(30000); /* If calling _exit() here the parent process seems to be blocked */
- + #endif
- if (debug)
- ! error("\nfaio_reader _exit(0)\n");
- !
- ! _exit(0);
- }
-
- #ifndef faio_ref
- ***************
- *** 481,486 ****
- --- 526,532 ----
- if (l <= 0)
- break;
- bytes_read += l;
- +
- } while (tracksize < 0 || bytes_read < tracksize);
-
- close(fd); /* Don't keep files open longer than neccesary */
- ***************
- *** 495,506 ****
- {
- unsigned long max_loops;
-
- ! if (f->owner == s)
- ! return; /* return immediately if the buffer is ours */
-
- if (s == owner_reader)
- sp->empty++;
- ! else
- sp->full++;
-
- max_loops = max_wait / delay + 1;
- --- 541,552 ----
- {
- unsigned long max_loops;
-
- ! if (f->owner == s)
- ! return; /* return immediately if the buffer is ours */
-
- if (s == owner_reader)
- sp->empty++;
- ! else
- sp->full++;
-
- max_loops = max_wait / delay + 1;
-