* Performs the work object's specific work function. * Loops calling work function for associated work object. Sleeps when fifo is full. * Monitors work done indicator. * Exits loop when work indicator is set. * @param _w Handle to work object. */
| 2269 | * @param _w Handle to work object. |
| 2270 | */ |
| 2271 | void hb_work_loop( void * _w ) |
| 2272 | { |
| 2273 | hb_work_object_t * w = _w; |
| 2274 | hb_buffer_t * buf_in = NULL, * buf_out = NULL; |
| 2275 | |
| 2276 | while ((w->die == NULL || !*w->die) && !*w->done && |
| 2277 | w->status != HB_WORK_DONE) |
| 2278 | { |
| 2279 | // fifo_in == NULL means this is a data source (e.g. reader) |
| 2280 | if (w->fifo_in != NULL) |
| 2281 | { |
| 2282 | buf_in = hb_fifo_get_wait( w->fifo_in ); |
| 2283 | if ( buf_in == NULL ) |
| 2284 | continue; |
| 2285 | if ( *w->done ) |
| 2286 | { |
| 2287 | if( buf_in ) |
| 2288 | { |
| 2289 | hb_buffer_close( &buf_in ); |
| 2290 | } |
| 2291 | break; |
| 2292 | } |
| 2293 | } |
| 2294 | // Invalidate buf_out so that if there is no output |
| 2295 | // we don't try to pass along junk. |
| 2296 | buf_out = NULL; |
| 2297 | w->status = w->work( w, &buf_in, &buf_out ); |
| 2298 | |
| 2299 | copy_chapter( buf_out, buf_in ); |
| 2300 | |
| 2301 | if( buf_in ) |
| 2302 | { |
| 2303 | hb_buffer_close( &buf_in ); |
| 2304 | } |
| 2305 | if ( buf_out && w->fifo_out == NULL ) |
| 2306 | { |
| 2307 | hb_buffer_close( &buf_out ); |
| 2308 | } |
| 2309 | if( buf_out ) |
| 2310 | { |
| 2311 | while ( !*w->done ) |
| 2312 | { |
| 2313 | if ( hb_fifo_full_wait( w->fifo_out ) ) |
| 2314 | { |
| 2315 | hb_fifo_push( w->fifo_out, buf_out ); |
| 2316 | buf_out = NULL; |
| 2317 | break; |
| 2318 | } |
| 2319 | } |
| 2320 | } |
| 2321 | else if (w->fifo_in == NULL) |
| 2322 | { |
| 2323 | // If this work object is a generator (no input fifo) and it |
| 2324 | // generated no output, it may be waiting for status from |
| 2325 | // another thread. Yield so that we don't spin doing nothing. |
| 2326 | hb_yield(); |
| 2327 | } |
| 2328 | } |
nothing calls this directly
no test coverage detected