@@ -139,6 +139,17 @@ class JobPool {
139139 // / @return The ID of the added lock job.
140140 uint32_t addLockJob (JobCallback callback, void *extra, uint32_t listenerId = 0 );
141141
142+ // / @brief Returns whether all jobs in the JobPool have been processed by the worker threads.
143+ // / This is a very accurate way to check if there are pending jobs in the JobPool, as it counts
144+ // / the number of jobs that have been added but not yet passed by processCompletedJobs. Must
145+ // / not be used for the masterConn's jobPool due to the special behavior of the lock jobs.
146+ bool allJobsProcessed () const ;
147+
148+ // / @brief Checks if the JobPool has no jobs and no status to be sent.
149+ // / This function is a lighter version of allJobsProcessed that can be used for the masterConn's
150+ // / jobPool to check if it is idle.
151+ bool isEmpty ();
152+
142153 // / @brief Gets the number of jobs in the JobPool.
143154 uint32_t getJobCount () const ;
144155
@@ -303,6 +314,10 @@ class JobPool {
303314 uint8_t workers; // / Number of worker threads in the pool.
304315 std::vector<std::thread> workerThreads; // / Vector of worker threads.
305316 std::unique_ptr<ProducerConsumerQueue> jobsQueue; // / Queue for jobs.
317+ // / Counter for unprocessed jobs, i.e jobs that have been added to the JobPool but have not yet
318+ // / been passed by processCompletedJobs and had their callbacks called. This is used to make
319+ // / sure the JobPool is truly empty when stopping the chunkserver.
320+ std::atomic<uint32_t > unprocessedJobs_{0 };
306321};
307322
308323// / @brief Adds an open job to the JobPool.
0 commit comments