| 1 | #cxx . . $ `<file>/seatac/thr-loader.C`/include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <new> |
| 4 | |
| 5 | #include "seatac.H"cxx . . $ `<file>/seatac/seatac.H`/ |
| 6 | |
| 7 | // Define this to print a message whenever a sequence is loaded. |
| 8 | // Useful for testing the loader with large sequences (scaffolds, |
| 9 | // chromosomes). |
| 10 | // |
| 11 | //#define VERBOSE_LOADER |
| 12 | |
| 13 | #ifdef TRUE64BITcxx . . $ `libutil/util.h:39:9`! |
| 14 | char const *loadDesccxx . . $ loadDesc. = "WARNING: Loader ran dry. Increasing limit to %u sequences, decreasing sleep to %f.\n"; |
| 15 | #else |
| 16 | char const *loadDesc = "WARNING: Loader ran dry. Increasing limit to %lu sequences, decreasing sleep to %f.\n"; |
| 17 | #endif |
| 18 | |
| 19 | void* |
| 20 | loaderThreadcxx . . $ loaderThread(9f162e79bfc6c74).(void *) { |
| 21 | uint32cxx . . $ uint32# waterLevel = 0; |
| 22 | seqInCorecxx . . $ seqInCore# *B = 0L; |
| 23 | bool slept = false; |
| 24 | |
| 25 | while (inputHeadcxx . . $ inputHead. < numberOfQueriescxx . . $ numberOfQueries.) { |
| 26 | |
| 27 | // We fill the input as fast as we can, up to the high water |
| 28 | // mark, then we take a little snooze to let the workers catch up. |
| 29 | // |
| 30 | pthread_mutex_lock(&inputTailMutexcxx . . $ inputTailMutex.); |
| 31 | waterLevel = inputHeadcxx . . $ inputHead. - inputTailcxx . . $ inputTail.; |
| 32 | pthread_mutex_unlock(&inputTailMutexcxx . . $ inputTailMutex.); |
| 33 | |
| 34 | // Warn if we're too small. |
| 35 | // |
| 36 | if ((slept) && (waterLevel <= 1)) { |
| 37 | |
| 38 | uint32cxx . . $ uint32# i = (uint32cxx . . $ uint32#) (0.1 * configcxx . . $ config.._loaderHighWaterMarkcxx . . $ configuration#_loaderHighWaterMark.); |
| 39 | if (i == 0) |
| 40 | i = 1; |
| 41 | configcxx . . $ config.._loaderHighWaterMarkcxx . . $ configuration#_loaderHighWaterMark. += i; |
| 42 | |
| 43 | configcxx . . $ config..setTimecxx . . $ configuration#setTime(ac28bcc6049edbea).(&configcxx . . $ config.._loaderSleepcxx . . $ configuration#_loaderSleep., |
| 44 | 0.9 * ((double)configcxx . . $ config.._loaderSleepcxx . . $ configuration#_loaderSleep..tv_sec + (double)configcxx . . $ config.._loaderSleepcxx . . $ configuration#_loaderSleep..tv_nsec * 1e-9)); |
| 45 | |
| 46 | if (configcxx . . $ config.._loaderWarningscxx . . $ configuration#_loaderWarnings.) |
| 47 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, loadDesccxx . . $ loadDesc., |
| 48 | configcxx . . $ config.._loaderHighWaterMarkcxx . . $ configuration#_loaderHighWaterMark., |
| 49 | ((double)configcxx . . $ config.._loaderSleepcxx . . $ configuration#_loaderSleep..tv_sec + (double)configcxx . . $ config.._loaderSleepcxx . . $ configuration#_loaderSleep..tv_nsec * 1e-9)); |
| 50 | } |
| 51 | |
| 52 | // Sleep, if we need to, otherwise, get the next sequence and |
| 53 | // push it onto the input list at inputHead. This alloc is |
| 54 | // deleted by the output thread. |
| 55 | // |
| 56 | if (waterLevel >= configcxx . . $ config.._loaderHighWaterMarkcxx . . $ configuration#_loaderHighWaterMark.) { |
| 57 | slept = true; |
| 58 | nanosleep(&configcxx . . $ config.._loaderSleepcxx . . $ configuration#_loaderSleep., 0L); |
| 59 | } else { |
| 60 | slept = false; |
| 61 | |
| 62 | #ifdef VERBOSE_LOADER |
| 63 | fprintf(stderr, "Loading sequence %u (tail = %u)\n", inputHead, inputTail); |
| 64 | #endif |
| 65 | |
| 66 | try { |
| 67 | B = qsFASTAcxx . . $ qsFASTA.->getSequenceInCorecxx . . $ seqCache#getSequenceInCore(3b3b07432ed6dd5c).(); |
| 68 | } catch (stdcxx . . $ std/::bad_alloccxx . . $ std/bad_alloc#)cxx . . $ std/bad_alloc#bad_alloc(f0898f11383ce75e). { |
| 69 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "loaderThread()-- Failed to load next query sequence\ncaught bad_alloc in %s at line %d\n", __FILE__, __LINE__); |
| 70 | exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 71 | } |
| 72 | |
| 73 | pthread_mutex_lock(&inputTailMutexcxx . . $ inputTailMutex.); |
| 74 | inputcxx . . $ input.[inputHeadcxx . . $ inputHead.] = B; |
| 75 | inputHeadcxx . . $ inputHead.++; |
| 76 | pthread_mutex_unlock(&inputTailMutexcxx . . $ inputTailMutex.); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | return(0L); |
| 81 | } |