diff options
| author | Dan Engelbrecht <[email protected]> | 2023-09-20 17:22:49 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-09-20 23:22:49 +0200 |
| commit | 73b86bbbd15e22893f05261dee036b81bfff91cf (patch) | |
| tree | 45c36ed9f8c7e340bd1ba292ec11cab5186b6965 /src/zencore/include | |
| parent | controlled zenserver shutdown (#413) (diff) | |
| download | zen-73b86bbbd15e22893f05261dee036b81bfff91cf.tar.xz zen-73b86bbbd15e22893f05261dee036b81bfff91cf.zip | |
Improvement: Add names to background jobs for easier debugging (#412)
Improvement: Background jobs now temporarily sets thread name to background job name while executing
Improvement: Background jobs tracks worker thread id used while executing
Diffstat (limited to 'src/zencore/include')
| -rw-r--r-- | src/zencore/include/zencore/jobqueue.h | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/zencore/include/zencore/jobqueue.h b/src/zencore/include/zencore/jobqueue.h index 41a3288e1..91ca24b34 100644 --- a/src/zencore/include/zencore/jobqueue.h +++ b/src/zencore/include/zencore/jobqueue.h @@ -14,16 +14,17 @@ namespace zen { struct JobId { - uint64_t Id; + uint64_t Id = 0; }; class JobQueue; -struct JobContext +class JobContext { - JobQueue& Queue; - const JobId Id; - std::atomic_bool& CancelFlag; +public: + virtual bool IsCancelled() const = 0; + virtual void ReportMessage(std::string_view Message) = 0; + virtual void ReportProgress(std::string_view CurrentOp, uint32_t CurrentOpPercentComplete) = 0; }; class JobQueue @@ -32,12 +33,9 @@ public: typedef std::function<void(JobContext& Context)> JobFunction; virtual ~JobQueue() = default; - virtual JobId QueueJob(JobFunction&& JobFunc) = 0; - virtual bool CancelJob(JobId Id) = 0; - virtual void Stop() = 0; - - virtual void ReportMessage(JobId Id, std::string_view Message) = 0; - virtual void ReportProgress(JobId Id, std::string_view CurrentOp, uint32_t CurrentOpPercentComplete) = 0; + virtual JobId QueueJob(std::string_view Name, JobFunction&& JobFunc) = 0; + virtual bool CancelJob(JobId Id) = 0; + virtual void Stop() = 0; enum class Status : uint32_t { @@ -64,11 +62,13 @@ public: struct JobDetails { + std::string Name; Status Status; State State; std::chrono::system_clock::time_point CreateTime; std::chrono::system_clock::time_point StartTime; std::chrono::system_clock::time_point EndTime; + int WorkerThreadId; }; // Will only respond once when status is Complete or Aborted |