Open System Services Programmer's Guide

/* size of files that are written - 1Mb */
#define WRITE_FILESIZE 1048576
/* -----------------------------------------------------------------
* OSS_read_thread --
*
* Description:
*
* This thread reads an OSS file using OSS I/O. Because this program
* uses the define _PUT_MODEL>, the read() function is
* mapped to the threadaware read() function, which blocks
* the thread instead of the entire process.
* Other threads are free to do
* work while this thread is blocked waiting for an I/O completion.
*
* Results:
* none.
*------------------------------------------------------------------
*/
void *OSS_read_thread(void *OSS_read_file)
{
int fd;
int nbytes;
char *iobuf;
int ret;
long long filesize = 0;
/*****************************************************************/
/* prepare I/O buffer (page aligned, paged into physical memory) */
/*****************************************************************/
if ((iobuf = malloc(IOSIZE)) == NULL)
{
my_printf("*** ERROR in OSS_read_thread: unable to allocate
I/O buffer ***\n");
exit(0);
}
memset(iobuf, 0, IOSIZE);
/*********************/
/* open the OSS file */
/*********************/
if ((fd = open(OSS_read_file, O_RDONLY | O_NONBLOCK)) < 0)
{
my_printf("*** ERROR in OSS_read_thread: open() of %s failed
w/error %d \***\n", OSS_read_file, errno);
exit(0);
}
/**********************************************/
/* read the OSS file in a thread aware manner */
/**********************************************/
while (1)
{
nbytes = read(fd, iobuf, IOSIZE);
if (nbytes < 0)
{
if ((errno == EWOULDBLOCK) || (errno == EAGAIN))
{
402 Using the POSIX User Thread (PUT) Model Library