Example #1
0
static int32 my_readv (int fd, struct iovec *iov, int32 iovcnt)
{
  int32 i, totalCharsRead=0, charsRead;
  int32 readResult;

  for(i=0;i<iovcnt; i++){
    charsRead = 0;
    while (charsRead < iov[i].iov_len) {
#ifdef _WINSOCK_
      SAFE_IO(readResult, 
	      recv(fd,iov[i].iov_base+charsRead,
		   min(iov[i].iov_len-charsRead,MAX_SOCKET_PACKET), 0));
#else
      SAFE_IO(readResult, 
	      read(fd,iov[i].iov_base+charsRead,
		   MIN(iov[i].iov_len-charsRead,MAX_SOCKET_PACKET)));
#endif
      if (readResult < 0) {
	/* Errror, return and  */
	return readResult;
      } else {
	/* Read some, update amounts. */
	charsRead += readResult;
	totalCharsRead += readResult;
      }
    }
  }
  return totalCharsRead;
}
Example #2
0
static int32 my_writev (int fd, struct iovec *iov, int32 iovcnt)
{
  int32 i, totalCharsWrite=0, charsWrite;
  int32 writeResult;
  
  for(i=0;i<iovcnt; i++){
    charsWrite = 0;
    while (charsWrite <  iov[i].iov_len) {
#ifdef _WINSOCK_
      SAFE_IO(writeResult, 
	      send(fd,iov[i].iov_base+charsWrite,
		   min(iov[i].iov_len-charsWrite,MAX_SOCKET_PACKET),0));
#else
      SAFE_IO(writeResult, 
	      write(fd,iov[i].iov_base+charsWrite,
		    MIN(iov[i].iov_len-charsWrite,MAX_SOCKET_PACKET)));
#endif
      if (writeResult < 0) {
	/* Errror, return and  */
	return writeResult;
      } else {
	/* Write some, update amounts. */
	charsWrite += writeResult;
	totalCharsWrite += writeResult;
      }
    }
  }
  return totalCharsWrite;
  
}
Example #3
0
X_IPC_RETURN_STATUS_TYPE x_ipc_readNBytes(int sd, char *buf, int32 nbytes)
{
  int32 amountRead, amountToRead;
  
  amountToRead = nbytes;
  LOCK_IO_MUTEX;
  for(;;){
#ifdef _WINSOCK_
    SAFE_IO(amountRead, recv(sd, buf, amountToRead, 0));
#else
#ifdef OS2
    SAFE_IO(amountRead, read(sd, buf, MIN(amountToRead,MAX_SOCKET_PACKET)));
#else
    SAFE_IO(amountRead, read(sd, buf, amountToRead));
#endif
#endif
    if (amountRead < 0) {
      UNLOCK_IO_MUTEX;
      return StatError;
    }
    if (!amountRead) {
      UNLOCK_IO_MUTEX;
      return StatEOF;
    }
    amountToRead -= amountRead;
    if (!amountToRead) {
      UNLOCK_IO_MUTEX;
      return StatOK;
    }
    buf += amountRead;
  }
  UNLOCK_IO_MUTEX;
}
Example #4
0
X_IPC_RETURN_STATUS_TYPE x_ipc_writeNBytes(int sd, char *buf, int32 nbytes)
{
  int32 amountWritten = 0;
  BOOLEAN *pipeBrokenPtr;
  
  LOCK_IO_MUTEX;
  LOCK_M_MUTEX;
  pipeBrokenPtr = &GET_M_GLOBAL(pipeBroken);
  UNLOCK_M_MUTEX;
  while (nbytes > 0) {
    *pipeBrokenPtr = FALSE;
#ifndef OS2
    errno = 0;
#endif
#ifdef _WINSOCK_
    SAFE_IO(amountWritten, send(sd, buf, nbytes,0));
#else
    SAFE_IO(amountWritten, write(sd, buf, nbytes));
#endif
    if (*pipeBrokenPtr || (errno == EPIPE)) {
      X_IPC_MOD_WARNING( "\nWARNING: pipe broken!\n");
      UNLOCK_IO_MUTEX;
      return StatError;
    } else if (amountWritten < 0) {
#if defined(VXWORKS) || defined(THINK_C) || defined(macintosh)
      UNLOCK_IO_MUTEX;
      return StatError;
#else
#ifdef _WINSOCK_
      if (WSAGetLastError() == WSAEWOULDBLOCK)
#else
	if (errno == EWOULDBLOCK)
#endif
	  {
	    X_IPC_MOD_WARNING(
			  "\nWARNING: x_ipc_writeNBytes: EWOULDBLOCK: trying again!\n");
	    PAUSE_MIN_DELAY();
	} else {
	  UNLOCK_IO_MUTEX;
	  return StatError;
	}
#endif
    } else {
      nbytes -= amountWritten;
      buf += amountWritten;
    }
  }
  UNLOCK_IO_MUTEX;
  return StatOK;
}
Example #5
0
void float_thread_t::run()
{
    float result;
    register float r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13,
	r14, r15, r16, r17, r18, r19, r20, r21, r22, r23, r24, r25,
	r26, r27, r28, r29, r30, r31;

    r1 = (float) id;
    r2 = (float) id;
    r3 = (float) id;
    r4 = (float) id;
    r5 = (float) id;
    r6 = (float) id;
    r7 = (float) id;
    r8 = (float) id;
    r9 = (float) id;
    r10 = (float) id;
    r11 = (float) id;
    r12 = (float) id;
    r13 = (float) id;
    r14 = (float) id;
    r15= (float) id;
    r16= (float) id;
    r17= (float) id;
    r18= (float) id;
    r19= (float) id;
    r20 = (float) id;
    r21 = (float) id;
    r22 = (float) id;
    r23 = (float) id;
    r24 = (float) id;
    r25 = (float) id;
    r26 = (float) id;
    r27 = (float) id;
    r28 = (float) id;
    r29 = (float) id;
    r30 = (float) id;
    r31 = (float) id;

    result = r1+ r2+ r3+ r4+ r5+ r6+ r7+ r8+ r9+ r10+ r11+ r12+ r13+
	r14+ r15+ r16+ r17+ r18+ r19+ r20+ r21+ r22+ r23+ r24+ r25+
	r26+ r27+ r28+ r29+ r30+ r31;

    SAFE_IO ( "Hello, world from " << id 
	 << ", result = " 
	 << setprecision(6) << setiosflags(ios::fixed) 
	 << result << resetiosflags(ios::fixed)
	 << ", check = " << 31 * id << endl
    )
    sthread_t::yield();

    result = r1+ r2+ r3+ r4+ r5+ r6+ r7+ r8+ r9+ r10+ r11+ r12+ r13+
	r14+ r15+ r16+ r17+ r18+ r19+ r20+ r21+ r22+ r23+ r24+ r25+
	r26+ r27+ r28+ r29+ r30+ r31;

    SAFE_IO( "Hello, world from " << id 
	 << ", result = " << setprecision(6) << setiosflags(ios::fixed) 
	 << result << resetiosflags(ios::fixed)
	 << ", check = " << 31 * id << endl;)
Example #6
0
void simple_thread_t::run() 
{ 
    SAFE_IO( "IDs" << endl
    << "thread ptr " << ::hex << uint64_t(this) << endl
    << "self " << uint64_t(pthread_self()) << endl
    << "sthread_t::id " << ::dec << uint64_t(this->id) << endl
    << endl << flush
    ) 
    pthread_barrier_wait(&b);
}
Example #7
0
void harvest(int threads)
{
	int	i;

	for(i=0; i < threads; ++i){
		W_COERCE( worker[i]->join() );
		if (verbose) {
			SAFE_IO( "Finished: " << endl << *worker[i] << endl);
		}

		w_assert1(ack[i]);
		delete worker[i];
	}
}
Example #8
0
void harvest(int threads)
{
        int     i;

        for(i=0; i < threads; ++i){
                EXPECT_FALSE( worker[i]->join().is_error() );
                if (verbose) {
                        SAFE_IO( "Finished: " << endl << *worker[i] << endl);
                }

                EXPECT_TRUE(ack[i] != 0);
                delete worker[i];
        }
}
Example #9
0
static X_IPC_RETURN_STATUS_TYPE x_ipc_read2Buffers(int sd,
						   char *buf1, int32 nbytes1,
						   char *buf2, int32 nbytes2)
{
  int32 amountRead, amountToRead;
  int32 numBuffers = 2;
  
  struct iovec vec[2];
  
  vec[0].iov_base = buf1;
  vec[0].iov_len = nbytes1;
  vec[1].iov_base = buf2;
  vec[1].iov_len = nbytes2;
  
  amountToRead = nbytes1 + nbytes2;
  LOCK_IO_MUTEX;
  for(;;){
    SAFE_IO(amountRead, readv(sd, vec, numBuffers));
    if (amountRead < 0) {
      UNLOCK_IO_MUTEX;
      return StatError;
    }
    if (!amountRead) {
      UNLOCK_IO_MUTEX;
      return StatEOF;
    }
    amountToRead -= amountRead;
    if (!amountToRead) {
      UNLOCK_IO_MUTEX;
      return StatOK;
    }
    /* Need to adjust buffers */
    if (amountToRead <= vec[1].iov_len) {
      /* Only need to use one buffer */
      numBuffers = 1;
      vec[0].iov_base = buf2 + nbytes2 - amountToRead;
      vec[0].iov_len = amountToRead;
    } else {
      /* Still need both buffers. */
      vec[0].iov_base = ((char *) vec[0].iov_base) + amountRead;
      vec[0].iov_len -= amountRead;
    }
  }
  UNLOCK_IO_MUTEX;
}
Example #10
0
static X_IPC_RETURN_STATUS_TYPE x_ipc_writeNBuffers(int sd, struct iovec *vec,
						    int32 amount)
{
  int32 amountWritten = 0;
  int32 numBuffers=0;
  int32 amountToWrite=0;
  int32 i, start=0;
  BOOLEAN *pipeBrokenPtr;
  
  for (i=0; (vec[i].iov_base != NULL); i++) {
    numBuffers++;
    amountToWrite += vec[i].iov_len;
  }
  
  if (amountToWrite != amount) {
    X_IPC_MOD_ERROR("Internal Error: Amounts incorrect in msg send.\n");
    return StatError;
  }
  
  LOCK_IO_MUTEX;
  LOCK_M_MUTEX;
  pipeBrokenPtr = &GET_M_GLOBAL(pipeBroken);
  UNLOCK_M_MUTEX;
  while (amountToWrite > 0) {
    *pipeBrokenPtr = FALSE;
#ifndef OS2
    errno = 0;
#endif
    SAFE_IO(amountWritten, writev(sd, &vec[start], numBuffers));
    if (*pipeBrokenPtr || (errno == EPIPE)) {
      X_IPC_MOD_WARNING( "\nWARNING: pipe broken!\n");
      x_ipcFree((char *)vec);
      UNLOCK_IO_MUTEX;
      return StatError;
    } else if (amountWritten < 0) {
#if defined(VXWORKS) || defined(THINK_C) || defined(macintosh)
      x_ipcFree((char *)vec);
      UNLOCK_IO_MUTEX;
      return StatError;
#else
#ifdef _WINSOCK_
      if (WSAGetLastError() == WSAEWOULDBLOCK)
#else
	if (errno == EWOULDBLOCK)
#endif
	  {
	    X_IPC_MOD_WARNING(
			  "\nWARNING: x_ipc_writeNBytes: EWOULDBLOCK: trying again!\n");
	    PAUSE_MIN_DELAY();
	} else {
	  x_ipcFree((char *)vec);
	  UNLOCK_IO_MUTEX;
	  return StatError;
	}
#endif
    } else {
      amountToWrite -= amountWritten;
      if (amountToWrite > 0) {
	while (amountWritten > 0) {
	  if (vec[start].iov_len <= amountWritten) {
	    amountWritten -= vec[start].iov_len;
	    start++;
	    numBuffers--;
	  } else if (vec[start].iov_len > amountWritten) {
	    vec[start].iov_len -= amountWritten;
#ifndef _SGI_SOURCE
	    vec[start].iov_base += amountWritten;
#else
	    vec[start].iov_base =
	      (caddr_t)((int32)vec[start].iov_base + amountWritten);
#endif
	    amountWritten = 0;
	  }
	}
      }
    }
  }
  UNLOCK_IO_MUTEX;
  x_ipcFree((char *)vec);
  return StatOK;
}