Commit d301c5e3 authored by Simon Spannagel's avatar Simon Spannagel
Browse files

ThreadPool: remove lock_guard requirement for bufferedQueueSize()

parent 17d85106
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -854,7 +854,7 @@ void ModuleManager::run(RandomNumberGenerator& seeder) {
                    auto event_function = std::bind(self_func, event, module_iter, event_time, self_func);
                    auto future = thread_pool_->submit(event->number, event_function, false);
                    assert(future.valid() || !thread_pool_->valid());
                    auto buffered_events = 0; // thread_pool_->bufferedQueueSize();
                    auto buffered_events = thread_pool_->bufferedQueueSize();
                    LOG_PROGRESS(STATUS, "EVENT_LOOP") << "Buffered " << buffered_events << ", finished " << finished_events
                                                       << " of " << number_of_events << " events";
                    return;
@@ -868,7 +868,7 @@ void ModuleManager::run(RandomNumberGenerator& seeder) {
            thread_pool_->markComplete(event->number);
            LOG(INFO) << "Finished event " << event_num << " with seed " << event_seed;

            auto buffered_events = 0; // thread_pool_->bufferedQueueSize();
            auto buffered_events = thread_pool_->bufferedQueueSize();
            if(plot) {
                this->buffer_fill_level_->Fill(static_cast<double>(buffered_events));
                event_time_->Fill(static_cast<double>(event_time));
+1 −0
Original line number Diff line number Diff line
@@ -127,6 +127,7 @@ namespace allpix {
            uint64_t current_id_{0};
            using PQValue = std::pair<uint64_t, T>;
            std::priority_queue<PQValue, std::vector<PQValue>, std::greater<>> priority_queue_;
            std::atomic_size_t priority_queue_size_{0};
            std::condition_variable push_condition_;
            std::condition_variable pop_condition_;
            const size_t max_standard_size_;
+4 −4
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ namespace allpix {
            // Priority queue is missing a pop returning a non-const reference, so need to apply a const_cast
            out = std::move(const_cast<PQValue&>(priority_queue_.top())).second; // NOLINT
            priority_queue_.pop();
            priority_queue_size_--;
        } else { // pop_standard
            out = std::move(queue_.front());
            queue_.pop();
@@ -111,6 +112,7 @@ namespace allpix {

        // Push a new element to the queue and notify possible consumer
        priority_queue_.emplace(n, std::move(value));
        priority_queue_size_++;
        lock.unlock();
        pop_condition_.notify_one();
        return true;
@@ -153,10 +155,7 @@ namespace allpix {
        return queue_.size() + priority_queue_.size();
    }

    template <typename T> size_t ThreadPool::SafeQueue<T>::prioritySize() const {
        std::lock_guard<std::mutex> lock{mutex_};
        return priority_queue_.size();
    }
    template <typename T> size_t ThreadPool::SafeQueue<T>::prioritySize() const { return priority_queue_size_; }

    /*
     * Used to ensure no conditions are being waited for in pop when a thread or the application is trying to exit. The queue
@@ -165,6 +164,7 @@ namespace allpix {
    template <typename T> void ThreadPool::SafeQueue<T>::invalidate() {
        std::unique_lock<std::mutex> lock{mutex_};
        std::priority_queue<PQValue, std::vector<PQValue>, std::greater<>>().swap(priority_queue_);
        priority_queue_size_ = 0;
        std::queue<T>().swap(queue_);
        valid_ = false;
        lock.unlock();