-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy paththreaded_batch_tagger.h
68 lines (56 loc) · 1.99 KB
/
threaded_batch_tagger.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef __REFLECT_THREADED_BATCH_TAGGER_HEADER__
#define __REFLECT_THREADED_BATCH_TAGGER_HEADER__
#include "batch_tagger.h"
#include "thread.h"
#include <vector>
class TaggerThread : public Thread
{
private:
IDocumentReader* document_reader;
DocumentTagger* document_tagger;
const GetMatchesParams* params;
IDocumentHandler* document_handler;
public:
TaggerThread(IDocumentReader* document_reader, DocumentTagger* document_tagger, const GetMatchesParams* params, IDocumentHandler* document_handler);
public:
void run();
};
class ThreadedBatchTagger : public BatchTagger
{
public:
void process(int threads, IDocumentReader* document_reader, const GetMatchesParams& params, IBatchHandler* batch_handler);
};
////////////////////////////////////////////////////////////////////////////////
TaggerThread::TaggerThread(IDocumentReader* document_reader, DocumentTagger* document_tagger, const GetMatchesParams* params, IDocumentHandler* document_handler)
: Thread()
{
this->document_reader = document_reader;
this->document_tagger = document_tagger;
this->params = params;
this->document_handler = document_handler;
}
void TaggerThread::run()
{
this->document_handler->on_batch_begin();
this->document_tagger->process(this->document_reader, *this->params, this->document_handler);
this->document_handler->on_batch_end();
pthread_exit(NULL);
}
////////////////////////////////////////////////////////////////////////////////
void ThreadedBatchTagger::process(int threads, IDocumentReader* document_reader, const GetMatchesParams& params, IBatchHandler* batch_handler)
{
vector<TaggerThread*> thread_vector;
for (int i = 0; i < threads; i++) {
thread_vector.push_back(new TaggerThread(document_reader, this, ¶ms, batch_handler->create_document_handler()));
}
batch_handler->on_batch_begin();
for (int i = 0; i < threads; i++) {
thread_vector[i]->start();
}
for (int i = 0; i < threads; i++) {
thread_vector[i]->join();
delete thread_vector[i];
}
batch_handler->on_batch_end();
}
#endif