Skip to content

Commit 1b7f1ad

Browse files
committed
make a better way to use
1 parent cfc7656 commit 1b7f1ad

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
cmake_minimum_required(VERSION 2.9)
22
project(qmc-decoder)
3-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -std=c++11")
3+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Og -std=c++11")
4+
if(NOT APPLE)
5+
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
6+
endif()
7+
8+
set(Boost_USE_STATIC_LIBS ON)
9+
find_package(Boost 1.56 REQUIRED COMPONENTS filesystem)
10+
include_directories(${Boost_INCLUDE_DIRS})
411
aux_source_directory(src SRC)
512
add_executable(decoder ${SRC})
13+
target_link_libraries(decoder ${Boost_LIBRARIES})
14+
615

716

src/decoder.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
#include <assert.h>
66
#include <mutex>
77
#include <algorithm>
8+
#include <boost/filesystem.hpp>
89

910
#define THREAD_NUM 4
1011

1112
using namespace std;
13+
namespace fs=boost::filesystem;
14+
1215
class Seed{
1316
public:
1417
Seed():x(-1),y(8),dx(1),index(-1){
@@ -127,26 +130,42 @@ void process(string dir)
127130

128131
}
129132

130-
void thread_block(int argc,char ** argv,int id,int td_n){
131-
for(int i=id;i<argc-1;i=i+td_n)
133+
void thread_block(const vector<string> * qmc_collection,int id){
134+
for(int i=id;i<qmc_collection->size();i+=THREAD_NUM)
132135
{
133-
process(std::string(argv[i+1]));
136+
process(qmc_collection->operator[](i));
134137
}
135138
}
136139

137140

138141
int main(int argc,char ** argv){
139142

140-
if(argc<2)
143+
if(argc>1)
141144
{
142-
print_thread_s("./decoder <qmcfile1> <qmcfile2> ...",std::cout);
145+
print_thread_s("put decoder binary file in your cmq file directory, then run it.",std::cout);
143146
return 1;
144147
}
145148

146-
std::vector<std::thread> td_group;
149+
fs::path qmc_dir(".");
150+
151+
fs::recursive_directory_iterator eod;
152+
153+
vector<string> qmc_collection;
154+
155+
for (fs::recursive_directory_iterator i(qmc_dir); i != eod; ++i){
156+
fs::path fp = *i;
157+
if (fs::is_regular_file(fp)){
158+
if(fp.string().find(".qmc3")!=string::npos||
159+
fp.string().find(".qmc0")!=string::npos||
160+
fp.string().find(".qmcflac")!=string::npos)
161+
qmc_collection.emplace_back(fp.string());
162+
}
163+
};
164+
165+
vector<std::thread> td_group;
147166
for(int i=1;i<THREAD_NUM;++i)
148-
td_group.emplace_back(thread_block,argc,argv,i,THREAD_NUM);
149-
thread_block(argc,argv,0,THREAD_NUM);
167+
td_group.emplace_back(thread_block,&qmc_collection,i);
168+
thread_block(&qmc_collection,0);
150169
for(auto &&x: td_group)
151170
x.join();
152171

0 commit comments

Comments
 (0)