| 920 | } |
| 921 | |
| 922 | void cLibsvmLiveSink::classifierThread() |
| 923 | { |
| 924 | //// this thread runs in a loop and waits for data to classify |
| 925 | |
| 926 | // when a new message arrives a thread condition variable is signalled |
| 927 | smileMutexLock(runningMtx); |
| 928 | int running = threadRunning; |
| 929 | smileMutexUnlock(runningMtx); |
| 930 | |
| 931 | // loads the model in the background, if not yet loaded |
| 932 | // note: we don't need to lock the mutex right here, because the variable is set |
| 933 | // before the thread is called and only read from at the moment |
| 934 | if (!modelLoaded_) |
| 935 | loadClassifier(); |
| 936 | |
| 937 | smileMutexLock(dataMtx); |
| 938 | modelLoaded_ = 1; |
| 939 | |
| 940 | //smileMutexLock(dataMtx); |
| 941 | while (running) { |
| 942 | if (!dataFrameQue->empty()) { |
| 943 | classifierThreadBusy = 1; |
| 944 | |
| 945 | lsvmDataFrame *f = dataFrameQue->front(); |
| 946 | dataFrameQue->pop(); |
| 947 | smileMutexUnlock(dataMtx); |
| 948 | |
| 949 | // classify frame... |
| 950 | if (f != NULL) { |
| 951 | if (f->modelchoice >= -1 && f->modelchoice < nModels) { |
| 952 | digestFrame(f, f->modelchoice); |
| 953 | } else { |
| 954 | SMILE_IERR(1,"input frame dropped due to invalid model selection (out of range) [%i] (valid: -1 - %i)",f->modelchoice,nModels-1); |
| 955 | } |
| 956 | } |
| 957 | |
| 958 | } else { |
| 959 | smileMutexUnlock(dataMtx); |
| 960 | } |
| 961 | |
| 962 | smileMutexLock(runningMtx); |
| 963 | running = threadRunning; |
| 964 | smileMutexUnlock(runningMtx); |
| 965 | |
| 966 | smileMutexLock(dataMtx); |
| 967 | if ((running)&&(dataFrameQue->empty())) { |
| 968 | classifierThreadBusy = 0; |
| 969 | smileCondWaitWMtx(dataCond,dataMtx); |
| 970 | } |
| 971 | } |
| 972 | classifierThreadBusy = 0; |
| 973 | smileMutexUnlock(dataMtx); |
| 974 | } |
| 975 | |
| 976 | int cLibsvmLiveSink::queFrameToClassify(lsvmDataFrame *fr) |
| 977 | { |
no test coverage detected