diff options
author | Toni Uhlig <Toni.Uhlig@tq-group.com> | 2017-12-04 11:05:50 +0100 |
---|---|---|
committer | Toni Uhlig <Toni.Uhlig@tq-group.com> | 2017-12-04 11:05:50 +0100 |
commit | 712457fab6a7caad1ab245460c0170026ab91b10 (patch) | |
tree | 87737f06ea5df06a538f212b28ca647beabdde64 /src | |
parent | 4eb5a237a33be363e8adf02f63651fc4b1dd8a4b (diff) |
JobQ: added BusyWorker counter and TotalJobsDone counter
Diffstat (limited to 'src')
-rw-r--r-- | src/JobQueue.cpp | 7 | ||||
-rw-r--r-- | src/JobQueue.hpp | 36 |
2 files changed, 38 insertions, 5 deletions
diff --git a/src/JobQueue.cpp b/src/JobQueue.cpp index af9a7e1..eb6320c 100644 --- a/src/JobQueue.cpp +++ b/src/JobQueue.cpp @@ -45,11 +45,17 @@ void WorkerThread::doJob() UpdateFactory uf; Job job = m_pQueue->Pop(); + m_pQueue->incBusyWorker(); + + /* process the job which was started by the GUI */ switch(job.m_cmd) { case Job::eID_THREAD_EXIT: + m_pQueue->decBusyWorker(); throw Job::eID_THREAD_EXIT; case Job::eID_THREAD_JOB: + Sleep(1000); /* give the UI some time to handle a lot of new Jobs */ + m_pQueue->Report(Job::eID_THREAD_MSG, wxString::Format(wxT("Job #%d: Connecting to %s:%i"), job.m_Arg.jobid, job.m_Arg.hostname, job.m_Arg.port), m_ID); @@ -122,4 +128,5 @@ void WorkerThread::doJob() default: break; } + m_pQueue->decBusyWorker(); } diff --git a/src/JobQueue.hpp b/src/JobQueue.hpp index 9b356f3..46be586 100644 --- a/src/JobQueue.hpp +++ b/src/JobQueue.hpp @@ -20,7 +20,8 @@ public: update_file(""), password("") {} JobArgs(int jobid, UpdateFactory& uf) : jobid(jobid), hostname(uf.getHostname()), - port(uf.getPort()), update_file(uf.getUpdateFile()), password(uf.getPassword()) {} + port(uf.getPort()), update_file(uf.getUpdateFile()), + password(uf.getPassword()) {} JobArgs(int jobid, const char *hostname, int port, const char *update_file, const char *password) : jobid(jobid), hostname(hostname), port(port), @@ -29,8 +30,10 @@ public: std::string& update_file, std::string& password) : jobid(jobid), hostname(hostname), port(port), update_file(update_file), password(password) {} - + + /** randomized (not unique) Job ID */ int jobid; + /* minimum required data for our UpdateFactory */ std::string hostname; int port; std::string update_file; @@ -67,7 +70,7 @@ class Queue { public: enum JobPriority { eHIGHEST, eHIGHER, eNORMAL, eBELOW_NORMAL, eLOW, eIDLE }; - Queue(wxEvtHandler *pParent) : m_pParent(pParent) {} + Queue(wxEvtHandler *pParent) : m_pParent(pParent), m_busyWorker(0), m_totalJobsDone(0) {} /* push a job with given priority class onto the FIFO */ void AddJob(const Job& job, const JobPriority& priority = eNORMAL); Job Pop(); @@ -78,12 +81,35 @@ public: wxMutexLocker lock(m_MutexQueue); return m_Jobs.size(); } + size_t getBusyWorker() { + wxMutexLocker lock(m_MutexBusyWorker); + return m_busyWorker; + } + size_t getTotalJobsDone() { + wxMutexLocker lock(m_MutexBusyWorker); + return m_totalJobsDone; + } + void resetTotalJobsDone() { + wxMutexLocker lock(m_MutexBusyWorker); + m_totalJobsDone = 0; + } + void incBusyWorker() { + wxMutexLocker lock(m_MutexBusyWorker); + m_busyWorker++; + } + void decBusyWorker() { + wxMutexLocker lock(m_MutexBusyWorker); + if (m_busyWorker > 0) m_busyWorker--; + m_totalJobsDone++; + } private: + /** main GUI EventHandler */ wxEvtHandler *m_pParent; - /* a priority Queue using std::multimap */ + /** a priority Queue using std::multimap */ std::multimap<JobPriority, Job> m_Jobs; - wxMutex m_MutexQueue; + wxMutex m_MutexQueue, m_MutexBusyWorker; wxSemaphore m_QueueCount; + size_t m_busyWorker, m_totalJobsDone; }; class WorkerThread : public wxThread |