11 #ifndef __INPUTPARSER_H__
12 #define __INPUTPARSER_H__
20 #define PARSER_DEFAULT_BUFFSIZE 100
287 static void* parse_loop_entry_point(
void* params);
359 read_vector=func_ptr;
366 read_vector_and_label=func_ptr;
380 pthread_mutex_destroy(&examples_state_lock);
381 pthread_cond_destroy(&examples_state_changed);
383 delete examples_ring;
389 input_source = input_file;
391 if (is_labelled ==
true)
398 parsing_done =
false;
399 reading_done =
false;
400 number_of_vectors_parsed = 0;
401 number_of_vectors_read = 0;
405 current_feature_vector = NULL;
407 free_after_release=
true;
410 pthread_mutex_init(&examples_state_lock, NULL);
411 pthread_cond_init(&examples_state_changed, NULL);
417 free_after_release=free_vec;
423 examples_ring->set_free_vectors_on_destruct(destroy);
431 SG_SERROR(
"Parser thread is already running! Multiple parse threads not supported.\n");
434 pthread_create(&parse_thread, NULL, parse_loop_entry_point,
this);
450 pthread_mutex_lock(&examples_state_lock);
460 pthread_mutex_unlock(&examples_state_lock);
469 (input_source->*read_vector_and_label)(feature_vector, length, label);
484 (input_source->*read_vector)(feature_vector, length);
498 examples_ring->copy_example(ex);
511 pthread_mutex_lock(&examples_state_lock);
514 pthread_mutex_unlock(&examples_state_lock);
517 pthread_mutex_unlock(&examples_state_lock);
519 pthread_testcancel();
521 current_example = examples_ring->get_free_example();
522 current_feature_vector = current_example->fv.vector;
523 current_len = current_example->fv.vlen;
524 current_label = current_example->label;
527 get_vector_and_label(current_feature_vector, current_len, current_label);
529 get_vector_only(current_feature_vector, current_len);
533 pthread_mutex_lock(&examples_state_lock);
535 pthread_cond_signal(&examples_state_changed);
536 pthread_mutex_unlock(&examples_state_lock);
540 current_example->label = current_label;
541 current_example->fv.vector = current_feature_vector;
542 current_example->fv.vlen = current_len;
544 examples_ring->copy_example(current_example);
546 pthread_mutex_lock(&examples_state_lock);
547 number_of_vectors_parsed++;
548 pthread_cond_signal(&examples_state_changed);
549 pthread_mutex_unlock(&examples_state_lock);
562 if (number_of_vectors_read == number_of_vectors_parsed)
566 pthread_cond_signal(&examples_state_changed);
571 if (number_of_vectors_parsed <= 0)
574 if (number_of_vectors_read == number_of_vectors_parsed)
579 ex = examples_ring->get_unused_example();
580 number_of_vectors_read++;
600 pthread_mutex_lock(&examples_state_lock);
601 ex = retrieve_example();
608 pthread_mutex_unlock(&examples_state_lock);
614 pthread_cond_wait(&examples_state_changed, &examples_state_lock);
615 pthread_mutex_unlock(&examples_state_lock);
622 pthread_mutex_unlock(&examples_state_lock);
628 length = ex->
fv.vlen;
639 return get_next_example(fv, length, label_dummy);
645 examples_ring->finalize_example(free_after_release);
650 pthread_join(parse_thread, NULL);
655 pthread_cancel(parse_thread);
658 #endif // __INPUTPARSER_H__