<commit_before>//
//  AsynExec.h
//  SwiftSnails
//
//  Created by Chunwei on 12/24/14.
//  Copyright (c) 2014 Chunwei. All rights reserved.
//
#ifndef SwiftSnails_SwiftSnails_AsynExec_h_
#define SwiftSnails_SwiftSnails_AsynExec_h_
#include "../utils/common.h"
#include "BasicChannel.h"
#include "common.h"

namespace swift_snails {

class AsynExec : public VirtualObject {
public:
    typedef std::function<void()> task_t;
    typedef BasicChannel<task_t> channel_t;

    explicit AsynExec() {}

    shared_ptr<channel_t> open() {
        for(int i = 0; i < thread_num(); i++) {
            shared_ptr<MultiWorker> workder = make_shared<MultiWorker>();
            for(int i = 0; i < thread_num(); i++) {
                workder->threads.emplace_back(
                    std::thread([worker]() {
                        worker->run();
                    }))
            } // for
        }
        return {&worker->channel, [worker](channel_t*) {
            worker->channel.close();
            for (auto& t : worker->threads) {
                t.join();
            }
        }};
    }

    void set_thread_num(int x) {
        CHECK(x > 0);
        _thread_num = x;
    }
    int thread_num() const {
        return _thread_num;
    }
private:
    int _thread_num = 0;
    std::vector<thread_guard> _threads;

    struct MultiWorker {
        std::vector<thread_guard> threads;
        channel_t channel;
        void start() {
            task_t func;
            while (channel.pop(func)) {
                func();
            }
        }
    }; // end struct MultiWorker
}; // class AsynExec

}; // end namespace swift_snails

#endif<commit_msg>fix closed check in AsynExec.h<commit_after>//
//  AsynExec.h
//  SwiftSnails
//
//  Created by Chunwei on 12/24/14.
//  Copyright (c) 2014 Chunwei. All rights reserved.
//
#ifndef SwiftSnails_SwiftSnails_AsynExec_h_
#define SwiftSnails_SwiftSnails_AsynExec_h_
#include "../utils/common.h"
#include "BasicChannel.h"
#include "common.h"

namespace swift_snails {

class AsynExec : public VirtualObject {
public:
    typedef std::function<void()> task_t;
    typedef BasicChannel<task_t> channel_t;

    explicit AsynExec() {}

    shared_ptr<channel_t> open() {

        for(int i = 0; i < thread_num(); i++) {
            shared_ptr<MultiWorker> workder = make_shared<MultiWorker>();

            for(int i = 0; i < thread_num(); i++) {
                workder->threads.emplace_back(
                    std::thread([worker]() {
                        worker->start();
                    }))
            } // for
        }
        return { &worker->channel, 
            [worker](channel_t*) {
                worker->channel.close();
                for (auto& t : worker->threads) {
                    t.join();
                }
            }};
    }

    void set_thread_num(int x) {
        CHECK(x > 0);
        _thread_num = x;
    }
    int thread_num() const {
        return _thread_num;
    }
private:
    int _thread_num = 0;
    std::vector<thread_guard> _threads;

    struct MultiWorker {
        std::vector<thread_guard> threads;
        channel_t channel;
        void start() {
            task_t func;
            bool valid;

            while (valid = channel.pop(func)) {
                if(!valid) {
                    LOG(INFO) << "AsynExec thread exit";
                    break; // to exit thread
                }
                func();
            }
        }
    }; // end struct MultiWorker
}; // class AsynExec

}; // end namespace swift_snails

#endif
{'fraction_non_alphanumeric': 0.12418854078464578, 'fraction_numerical': 0.007902907140841095, 'mean_word_length': 1.7472868217054263, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1751294', 'n_tokens_mistral': 1127, 'n_tokens_neox': 1061, 'n_words': 235}