Open System Services Programmer's Guide
/*
*-----------------------------------------------------------------
* OSS_read_thread --
*
* Description:
*
* This thread reads an OSS file using OSS I/O. Because this program
* uses the define SPT_THREAD_AWARE_XNONBLOCK, the read() function is
* mapped to the spt_readz() function, which is thread-aware and 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)
{
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)
{
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))
{
Thread-Aware and Nonblocking OSS Functions 361