Ignore:
Timestamp:
May 31, 2017, 1:48:49 PM (2 years ago)
Author:
cameron
Message:

Handle non-existent files, directories=read mode, -s

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/icgrep.cpp

    r5480 r5484  
    2424#include <re/re_toolchain.h>
    2525#include <pablo/pablo_toolchain.h>
    26 #include <mutex>
    2726#include <boost/filesystem.hpp>
    2827#include <iostream> // MEEE
     
    108107
    109108    return REs;
    110 }
    111 
    112 std::vector<size_t> total_Count;
    113 std::mutex count_mutex;
    114 size_t fileCount;
    115 void *DoGrep(void *args)
    116 {
    117     size_t fileIdx;
    118     grep::GrepEngine * grepEngine = (grep::GrepEngine *)args;
    119 
    120     count_mutex.lock();
    121     fileIdx = fileCount;
    122     fileCount++;
    123     count_mutex.unlock();
    124 
    125     while (fileIdx < allFiles.size()) {
    126         total_Count[fileIdx] = grepEngine->doGrep(allFiles[fileIdx], fileIdx);
    127        
    128         count_mutex.lock();
    129         fileIdx = fileCount;
    130         fileCount++;
    131         count_mutex.unlock();
    132     }
    133 
    134     pthread_exit(nullptr);
    135109}
    136110
     
    212186        allFiles = { "-" };
    213187        grep::initFileResult(allFiles);
    214         total_Count.resize(1);
    215         total_Count[0] = grepEngine.doGrep(STDIN_FILENO, 0);
     188        grepEngine.doGrep(STDIN_FILENO, 0);
    216189
    217190    } else {
     
    230203
    231204        grep::initFileResult(allFiles);
    232         total_Count.resize(allFiles.size());
    233205
    234206        if (Threads <= 1) {
    235207            for (unsigned i = 0; i != allFiles.size(); ++i) {
    236                 total_Count[i] = grepEngine.doGrep(allFiles[i], i);
     208                grepEngine.doGrep(allFiles[i], i);
    237209            }
    238210        } else if (Threads > 1) {
     
    241213
    242214            for(unsigned long i = 0; i < numOfThreads; ++i){
    243                 const int rc = pthread_create(&threads[i], nullptr, DoGrep, (void *)&grepEngine);
     215                const int rc = pthread_create(&threads[i], nullptr, grep::DoGrepThreadFunction, (void *)&grepEngine);
    244216                if (rc) {
    245217                    llvm::report_fatal_error("Failed to create thread: code " + std::to_string(rc));
     
    257229    }
    258230   
    259     grep::PrintResult(grep::Mode, total_Count);
     231    grep::PrintResults();
    260232   
    261233    return 0;
Note: See TracChangeset for help on using the changeset viewer.