Skip to content

Commit a8ff580

Browse files
committed
not user multi thread in windows
1 parent dd12f97 commit a8ff580

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

src/decoder.cpp

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
#include <iostream>
22
#include <fstream>
33
#include <vector>
4+
#ifndef _WIN64
45
#include <thread>
6+
#endif
57
#include <assert.h>
8+
#ifndef _WIN64
69
#include <mutex>
10+
#endif
711
#include <algorithm>
812
#include <boost/filesystem.hpp>
913

14+
#ifndef _WIN64
1015
#define THREAD_NUM 4
11-
16+
#endif
1217
using namespace std;
1318
namespace fs=boost::filesystem;
1419

@@ -59,23 +64,31 @@ class Seed{
5964
int index;
6065
vector<vector<uint8_t> > seedMap;
6166
};
62-
67+
#ifndef _WIN64
6368
std::mutex mtx;
64-
6569
void print_thread_s(const char *str, std::ostream &stm){
6670
std::lock_guard<std::mutex> lock(mtx);
6771
stm<<str<<endl;
6872
}
73+
#endif
6974

7075
void process(string dir)
7176
{
7277
std::string print_str("decode: ");
7378
print_str +=dir;
79+
#ifdef _WIN64
80+
std::cout<<print_str<<endl;
81+
#else
7482
print_thread_s(print_str.c_str(),std::cout);
83+
#endif
7584
std::fstream infile(dir.c_str(),std::ios::in|std::ios::binary);
7685
if(!infile.is_open())
7786
{
87+
#ifdef _WIN64
88+
std::cerr<<"qmc file read error"<<endl;
89+
#else
7890
print_thread_s("qmc file read error",std::cerr);
91+
#endif
7992
return;
8093
}
8194

@@ -123,26 +136,36 @@ void process(string dir)
123136
outfile.close();
124137
}else
125138
{
139+
#ifdef _WIN64
140+
std::cerr<<"open dump file error"<<endl;
141+
#else
126142
print_thread_s("open dump file error",std::cerr);
143+
#endif
127144
}
128145
delete[] buffer;
129146

130147

131148
}
132149

150+
#ifndef _WIN64
133151
void thread_block(const vector<string> * qmc_collection,int id){
134152
for(int i=id;i<qmc_collection->size();i+=THREAD_NUM)
135153
{
136154
process(qmc_collection->operator[](i));
137155
}
138156
}
157+
#endif
139158

140159

141160
int main(int argc,char ** argv){
142161

143162
if(argc>1)
144163
{
145-
print_thread_s("put decoder binary file in your cmq file directory, then run it.",std::cout);
164+
#ifndef _WIN64
165+
print_thread_s("put decoder binary file in your qmc file directory, then run it.",std::cout);
166+
#else
167+
cout<<"put decoder binary file in your qmc file directory, then run it.\n";
168+
#endif
146169
return 1;
147170
}
148171

@@ -161,14 +184,18 @@ int main(int argc,char ** argv){
161184
qmc_collection.emplace_back(fp.string());
162185
}
163186
};
187+
#ifdef _WIN64
188+
for(auto &&qmc_file: qmc_collection)
189+
process(qmc_file);
164190

191+
#else
165192
vector<std::thread> td_group;
166193
for(int i=1;i<THREAD_NUM;++i)
167194
td_group.emplace_back(thread_block,&qmc_collection,i);
168195
thread_block(&qmc_collection,0);
169196
for(auto &&x: td_group)
170197
x.join();
171-
198+
#endif
172199

173200
return 0;
174201
}

0 commit comments

Comments
 (0)