| 1 | greg | 2.1 | #ifndef lint | 
| 2 | greg | 2.2 | static const char RCSid[] = "$Id: raypwin.c,v 2.1 2008/02/08 18:27:31 greg Exp $"; | 
| 3 | greg | 2.1 | #endif | 
| 4 |  |  | /* | 
| 5 |  |  | *  raypwin.c - interface for parallel rendering using Radiance (Windows ver) | 
| 6 |  |  | * | 
| 7 |  |  | *  External symbols declared in ray.h | 
| 8 |  |  | */ | 
| 9 |  |  |  | 
| 10 |  |  | #include "copyright.h" | 
| 11 |  |  |  | 
| 12 |  |  | /* | 
| 13 |  |  | * See raypcalls.c for an explanation of these routines. | 
| 14 |  |  | */ | 
| 15 |  |  |  | 
| 16 | greg | 2.2 | /***** XXX CURRENTLY, THIS IS JUST A COLLECTION OF IMPOTENT STUBS XXX *****/ | 
| 17 | greg | 2.1 |  | 
| 18 |  |  | #include  "ray.h" | 
| 19 |  |  |  | 
| 20 | greg | 2.2 | int             ray_pnprocs = 0;        /* number of child processes */ | 
| 21 |  |  | int             ray_pnidle = 0;         /* number of idle children */ | 
| 22 |  |  |  | 
| 23 |  |  | static RAY      queued_ray; | 
| 24 | greg | 2.1 |  | 
| 25 |  |  | extern void | 
| 26 |  |  | ray_pinit(              /* initialize ray-tracing processes */ | 
| 27 |  |  | char    *otnm, | 
| 28 |  |  | int     nproc | 
| 29 |  |  | ) | 
| 30 |  |  | { | 
| 31 | greg | 2.2 | if (nproc > 1) | 
| 32 |  |  | error(WARNING, "Only single process supported"); | 
| 33 |  |  | ray_pdone(0); | 
| 34 |  |  | ray_init(otnm); | 
| 35 |  |  | ray_popen(nproc); | 
| 36 | greg | 2.1 | } | 
| 37 |  |  |  | 
| 38 |  |  |  | 
| 39 |  |  | extern void | 
| 40 |  |  | ray_psend(                      /* add a ray to our send queue */ | 
| 41 |  |  | RAY     *r | 
| 42 |  |  | ) | 
| 43 |  |  | { | 
| 44 | greg | 2.2 | if (r == NULL) | 
| 45 |  |  | return; | 
| 46 |  |  | if (ray_pnidle <= 0) | 
| 47 |  |  | error(INTERNAL, "illegal call to ray_psend"); | 
| 48 |  |  | queued_ray = *r; | 
| 49 |  |  | ray_pnidle = 0; | 
| 50 | greg | 2.1 | } | 
| 51 |  |  |  | 
| 52 |  |  |  | 
| 53 |  |  | extern int | 
| 54 |  |  | ray_pqueue(                     /* queue a ray for computation */ | 
| 55 |  |  | RAY     *r | 
| 56 |  |  | ) | 
| 57 |  |  | { | 
| 58 | greg | 2.2 | if (r == NULL) | 
| 59 |  |  | return(0); | 
| 60 |  |  | ray_value(r); | 
| 61 |  |  | return(1); | 
| 62 | greg | 2.1 | } | 
| 63 |  |  |  | 
| 64 |  |  |  | 
| 65 |  |  | extern int | 
| 66 |  |  | ray_presult(            /* check for a completed ray */ | 
| 67 |  |  | RAY     *r, | 
| 68 |  |  | int     poll | 
| 69 |  |  | ) | 
| 70 |  |  | { | 
| 71 | greg | 2.2 | if (r == NULL) | 
| 72 |  |  | return(0); | 
| 73 |  |  | if (!poll & (ray_pnidle <= 0)) { | 
| 74 |  |  | ray_value(&queued_ray); | 
| 75 |  |  | *r = queued_ray; | 
| 76 |  |  | ray_pnidle = 1; | 
| 77 |  |  | return(1); | 
| 78 |  |  | } | 
| 79 |  |  | return(0); | 
| 80 | greg | 2.1 | } | 
| 81 |  |  |  | 
| 82 |  |  |  | 
| 83 |  |  | extern void | 
| 84 |  |  | ray_pdone(              /* reap children and free data */ | 
| 85 |  |  | int     freall | 
| 86 |  |  | ) | 
| 87 |  |  | { | 
| 88 | greg | 2.2 | ray_done(freall); | 
| 89 |  |  | ray_pnprocs = ray_pnidle = 0; | 
| 90 | greg | 2.1 | } | 
| 91 |  |  |  | 
| 92 |  |  |  | 
| 93 |  |  | extern void | 
| 94 |  |  | ray_popen(                      /* open the specified # processes */ | 
| 95 |  |  | int     nadd | 
| 96 |  |  | ) | 
| 97 |  |  | { | 
| 98 | greg | 2.2 | if (ray_pnprocs + nadd > 1) { | 
| 99 |  |  | error(WARNING, "Only single process supported"); | 
| 100 |  |  | nadd = 1 - ray_pnprocs; | 
| 101 |  |  | } | 
| 102 |  |  | ray_pnprocs += nadd; | 
| 103 |  |  | ray_pnidle += nadd; | 
| 104 | greg | 2.1 | } | 
| 105 |  |  |  | 
| 106 |  |  |  | 
| 107 |  |  | extern void | 
| 108 |  |  | ray_pclose(             /* close one or more child processes */ | 
| 109 |  |  | int     nsub | 
| 110 |  |  | ) | 
| 111 |  |  | { | 
| 112 | greg | 2.2 | if (nsub > ray_pnprocs) | 
| 113 |  |  | nsub = ray_pnprocs; | 
| 114 |  |  | ray_pnprocs -= nsub; | 
| 115 |  |  | if ((ray_pnidle -= nsub) < 0) | 
| 116 |  |  | ray_pnidle = 0; | 
| 117 | greg | 2.1 | } | 
| 118 |  |  |  | 
| 119 |  |  |  | 
| 120 |  |  | void | 
| 121 |  |  | quit(ec)                        /* make sure exit is called */ | 
| 122 |  |  | int     ec; | 
| 123 |  |  | { | 
| 124 |  |  | exit(ec); | 
| 125 |  |  | } |