zhangmeng
2022-12-27 cf0a3209b51babf72469d962914db0dac2e5f52c
fixed_q.h
@@ -46,6 +46,17 @@
        cond_node.notify();
        return q.size();
    }
    int pop(T& m, const size_t ms){
        std::unique_lock<std::mutex> l{mtx_q};
        auto d = std::chrono::milliseconds{ms};
        if(!cond_node.wait_for(l, d, [this]{ return !q.empty(); })){
            return -1;
        }
        m = q.front();
        q.pop_front();
        cond_spare.notify();
        return q.size();
    }
    int pop(T& m){
        std::unique_lock<std::mutex> l{mtx_q};
        auto d = std::chrono::milliseconds{du};
@@ -57,16 +68,29 @@
        cond_spare.notify();
        return q.size();
    }
    T pop(const size_t ms){
        std::unique_lock<std::mutex> l{mtx_q};
        auto d = std::chrono::milliseconds{ms};
        T t{};
        if(!cond_node.wait_for(l, d, [this]{ return !q.empty(); })){
            return t;
        }
        t = q.front();
        q.pop_front();
        cond_spare.notify();
        return t;
    }
    T pop(){
        std::unique_lock<std::mutex> l{mtx_q};
        auto d = std::chrono::milliseconds{du};
        T t{};
        while(!cond_node.wait_for(l, d, [this]{ return !q.empty(); })){
            if (pred()) return T{};
            if (pred()) return t;
        }
        auto m(move(q.front()));
        t = q.front();
        q.pop_front();
        cond_spare.notify();
        return m;
        return t;
    }
    template<typename F> void clear(F&& f){