| 196 |
|
return NThreads(); |
| 197 |
|
} |
| 198 |
|
|
| 199 |
– |
// Assign ray to subthread (fails if NThreads()<2) |
| 200 |
– |
bool |
| 201 |
– |
RadSimulManager::SplitRay(RAY *r) |
| 202 |
– |
{ |
| 203 |
– |
if (!ray_pnprocs || ThreadsAvailable() < 1) |
| 204 |
– |
return false; |
| 205 |
– |
|
| 206 |
– |
return (ray_psend(r) > 0); |
| 207 |
– |
} |
| 208 |
– |
|
| 199 |
|
// Process a ray (in subthread), optional result |
| 200 |
< |
bool |
| 200 |
> |
int |
| 201 |
|
RadSimulManager::ProcessRay(RAY *r) |
| 202 |
|
{ |
| 203 |
|
if (!Ready()) return false; |
| 205 |
|
if (!ray_pnprocs) { // single-threaded mode? |
| 206 |
|
samplendx++; |
| 207 |
|
rayvalue(r); |
| 208 |
< |
return true; |
| 208 |
> |
return 1; |
| 209 |
|
} |
| 210 |
< |
int rv = ray_pqueue(r); |
| 221 |
< |
if (rv < 0) { |
| 222 |
< |
error(WARNING, "ray tracing process(es) died"); |
| 223 |
< |
return false; |
| 224 |
< |
} |
| 225 |
< |
return (rv > 0); |
| 210 |
> |
return ray_pqueue(r); |
| 211 |
|
} |
| 212 |
|
|
| 213 |
|
// Wait for next result (or fail) |
| 234 |
|
return 0; |
| 235 |
|
} |
| 236 |
|
|
| 252 |
– |
// How many threads are currently unoccupied? |
| 253 |
– |
int |
| 254 |
– |
RadSimulManager::ThreadsAvailable() const |
| 255 |
– |
{ |
| 256 |
– |
if (!ray_pnprocs) return 1; |
| 257 |
– |
|
| 258 |
– |
return ray_pnidle; |
| 259 |
– |
} |
| 260 |
– |
|
| 237 |
|
// Global pointer to simulation manager for trace call-back (only one) |
| 238 |
|
static const RtraceSimulManager * ourRTsimMan = NULL; |
| 239 |
|
|
| 264 |
|
|
| 265 |
|
int misMatch = (rtFlags ^ curFlags) & RTmask; |
| 266 |
|
// updates based on toggled flags |
| 267 |
< |
if (misMatch & RTtraceSources) { |
| 267 |
> |
if (((misMatch & RTtraceSources) != 0) & (nsources > 0)) { |
| 268 |
> |
int nt = NThreads(); |
| 269 |
> |
if (nt > 1) { |
| 270 |
> |
if (FlushQueue() < 0) |
| 271 |
> |
return false; |
| 272 |
> |
SetThreadCount(1); |
| 273 |
> |
} |
| 274 |
|
int sn = nsources; |
| 275 |
|
if (rtFlags & RTtraceSources) { |
| 276 |
|
srcFollowed.NewBitMap(nsources); |
| 286 |
|
source[sn].sflags &= ~SFOLLOW; |
| 287 |
|
srcFollowed.NewBitMap(0); |
| 288 |
|
} |
| 289 |
+ |
if (nt > 1) SetThreadCount(nt); |
| 290 |
|
} |
| 291 |
|
if (misMatch & RTdoFIFO && FlushQueue() < 0) |
| 292 |
|
return false; |
| 381 |
|
if (ray_fifo_in(&res) < 0) |
| 382 |
|
return -1; |
| 383 |
|
sendRes = false; |
| 384 |
< |
} else |
| 385 |
< |
sendRes &= ProcessRay(&res); |
| 384 |
> |
} else { |
| 385 |
> |
int rv = ProcessRay(&res); |
| 386 |
> |
if (rv < 0) |
| 387 |
> |
return -1; |
| 388 |
> |
sendRes &= (rv > 0); |
| 389 |
> |
} |
| 390 |
|
} else if (ThreadsAvailable() < NThreads() && |
| 391 |
|
FlushQueue() < 0) |
| 392 |
|
return -1; |