Back to index

radiance  4R0+20100331
Defines | Functions | Variables
rayfifo.c File Reference
#include "copyright.h"
#include "ray.h"
#include <string.h>

Go to the source code of this file.

Defines

#define r_fifo(rn)   (&r_fifo_buf[(rn)&(r_fifo_len-1)])

Functions

static void ray_fifo_growbuf (void)
static int ray_fifo_push (RAY *r)
int ray_fifo_in (RAY *r)
int ray_fifo_flush (void)

Variables

static const char RCSid [] = "$Id: rayfifo.c,v 2.4 2009/12/13 19:13:04 greg Exp $"
int(* ray_fifo_out )(RAY *r) = NULL
static RAYr_fifo_buf = NULL
static int r_fifo_len = 0
static RNUMBER r_fifo_start = 1
static RNUMBER r_fifo_end = 1
static RNUMBER r_fifo_next = 1

Define Documentation

#define r_fifo (   rn)    (&r_fifo_buf[(rn)&(r_fifo_len-1)])

Definition at line 47 of file rayfifo.c.


Function Documentation

int ray_fifo_flush ( void  )

Definition at line 148 of file rayfifo.c.

{
       RAY    myRay;
       int    rv, rval = 0;
                                          /* clear parallel queue */
       while ((rv = ray_presult(&myRay, 0)) > 0 &&
                     (rv = ray_fifo_push(&myRay)) >= 0)
              rval += rv;

       if (rv < 0)                        /* check for exception */
              return(-1);

       if (r_fifo_start != r_fifo_end)
              error(INTERNAL, "could not empty queue in ray_fifo_flush()");

       if (r_fifo_buf != NULL) {
              free(r_fifo_buf);
              r_fifo_buf = NULL; r_fifo_len = 0;
       }
       r_fifo_next = r_fifo_end = r_fifo_start = 1;

       return(rval);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void ray_fifo_growbuf ( void  ) [static]

Definition at line 51 of file rayfifo.c.

{
       RAY    *old_buf = r_fifo_buf;
       int    old_len = r_fifo_len;
       int    i;

       if (r_fifo_buf == NULL)
              r_fifo_len = 1<<5;
       else
              r_fifo_len <<= 1;
                                          /* allocate new */
       r_fifo_buf = (RAY *)calloc(r_fifo_len, sizeof(RAY));
       if (r_fifo_buf == NULL)
              error(SYSTEM, "out of memory in ray_fifo_growbuf");
       if (old_buf == NULL)
              return;
                                          /* copy old & free */
       for (i = r_fifo_start; i < r_fifo_end; i++)
              *r_fifo(i) = old_buf[i&(old_len-1)];

       free(old_buf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int ray_fifo_in ( RAY r)

Definition at line 113 of file rayfifo.c.

{
       static int    incall = 0;          /* prevent recursion */
       int           rv, rval = 0;

       if (incall++)
              error(INTERNAL, "recursive call to ray_fifo_in()");

       if (r_fifo_start >= 1L<<30) {             /* reset our counters */
              if ((rv = ray_fifo_flush()) < 0)
                     {--incall; return(-1);}
              rval += rv;
       }
                                          /* queue ray */
       r->rno = r_fifo_next++;
       if ((rv = ray_pqueue(r)) < 0)
              {--incall; return(-1);}

       if (!rv)                           /* no result this time? */
              {--incall; return(rval);}
       
       do {                               /* else send/queue result */
              if ((rv = ray_fifo_push(r)) < 0)
                     {--incall; return(-1);}
              rval += rv;

       } while (ray_presult(r, -1) > 0);  /* empty in-core queue */

       --incall; return(rval);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int ray_fifo_push ( RAY r) [static]

Definition at line 76 of file rayfifo.c.

{
       int    rv, nsent = 0;

       if (ray_fifo_out == NULL)
              error(INTERNAL, "ray_fifo_out is NULL");
       if ((r->rno < r_fifo_start) | (r->rno >= r_fifo_next))
              error(INTERNAL, "unexpected ray number in ray_fifo_push()");

       if (r->rno > r_fifo_start) {              /* insert into output queue */
              while (r->rno - r_fifo_start >= r_fifo_len)
                     ray_fifo_growbuf();  /* need more space */
              *r_fifo(r->rno) = *r;
              if (r->rno >= r_fifo_end)
                     r_fifo_end = r->rno + 1;
              return(0);
       }
                     /* r->rno == r_fifo_start, so transfer ray(s) */
       do {
              rv = (*ray_fifo_out)(r);
              r->rno = 0;                 /* flag this entry complete */
              if (rv < 0)
                     return(-1);
              nsent += rv;
              if (++r_fifo_start < r_fifo_end)
                     r = r_fifo(r_fifo_start);
              else if (r_fifo_start > r_fifo_end)
                     r_fifo_end = r_fifo_start;
       } while (r->rno == r_fifo_start);

       return(nsent);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

RAY* r_fifo_buf = NULL [static]

Definition at line 41 of file rayfifo.c.

RNUMBER r_fifo_end = 1 [static]

Definition at line 44 of file rayfifo.c.

int r_fifo_len = 0 [static]

Definition at line 42 of file rayfifo.c.

RNUMBER r_fifo_next = 1 [static]

Definition at line 45 of file rayfifo.c.

RNUMBER r_fifo_start = 1 [static]

Definition at line 43 of file rayfifo.c.

int(* ray_fifo_out)(RAY *r) = NULL

Definition at line 39 of file rayfifo.c.

const char RCSid[] = "$Id: rayfifo.c,v 2.4 2009/12/13 19:13:04 greg Exp $" [static]

Definition at line 2 of file rayfifo.c.