WM Jobs: Add job's own reporting mechanism.
wmJob's shared data (with their worker threads), #wmJobWorkerStatus, now
also contains a #ReportList pointer.
Job worker code is now expected to use `BKE_report` APIs to populate this
new shared reportlist, instead of calling the (absolutely) not
thread-safe `WM_reports` API. This will be tackled in later commits.
Note that since commit 9859622a66, #ReportList and `BKE_report` API
is now thread-safe, so no further handling for this is required in the
wmJob code itself.
The periodic wmJob update handling (done through timers currently)
takes care of moving reports from the job data to the WM data.
Implements #112537.
Pull Request: #113548.
This commit is contained in:
@@ -99,6 +99,7 @@ struct bContext;
|
||||
struct bContextStore;
|
||||
struct GreasePencil;
|
||||
struct GreasePencilLayer;
|
||||
struct ReportList;
|
||||
struct wmDrag;
|
||||
struct wmDropBox;
|
||||
struct wmEvent;
|
||||
@@ -943,6 +944,10 @@ struct wmJobWorkerStatus {
|
||||
|
||||
/** OUTPUT - Progress as reported by the worker, from `0.0f` to `1.0f`. */
|
||||
float progress;
|
||||
|
||||
/** OUTPUT - Storage of reports generated during this job's run. Contains its own locking for
|
||||
* thread-safety. */
|
||||
ReportList *reports;
|
||||
};
|
||||
|
||||
struct wmOperatorType {
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "BKE_context.h"
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_report.h"
|
||||
|
||||
#include "SEQ_prefetch.h"
|
||||
|
||||
@@ -206,6 +207,10 @@ wmJob *WM_jobs_get(wmWindowManager *wm,
|
||||
|
||||
wm_job->main_thread_mutex = BLI_ticket_mutex_alloc();
|
||||
WM_job_main_thread_lock_acquire(wm_job);
|
||||
|
||||
wm_job->worker_status.reports = MEM_new<ReportList>(__func__);
|
||||
BKE_reports_init(wm_job->worker_status.reports, RPT_STORE | RPT_PRINT);
|
||||
BKE_report_print_level_set(wm_job->worker_status.reports, RPT_WARNING);
|
||||
}
|
||||
/* else: a running job, be careful */
|
||||
|
||||
@@ -381,6 +386,11 @@ void WM_jobs_callbacks_ex(wmJob *wm_job,
|
||||
wm_job->canceled = canceled;
|
||||
}
|
||||
|
||||
static void wm_jobs_reports_update(wmWindowManager *wm, wmJob *wm_job)
|
||||
{
|
||||
WM_reports_from_reports_move(wm, wm_job->worker_status.reports);
|
||||
}
|
||||
|
||||
static void *do_job_thread(void *job_v)
|
||||
{
|
||||
wmJob *wm_job = static_cast<wmJob *>(job_v);
|
||||
@@ -496,7 +506,7 @@ void WM_jobs_start(wmWindowManager *wm, wmJob *wm_job)
|
||||
}
|
||||
}
|
||||
|
||||
static void wm_job_end(wmJob *wm_job)
|
||||
static void wm_job_end(wmWindowManager *wm, wmJob *wm_job)
|
||||
{
|
||||
BLI_assert_msg(BLI_thread_is_main(), "wm_job_end should only be called from the main thread");
|
||||
if (wm_job->endjob) {
|
||||
@@ -512,6 +522,9 @@ static void wm_job_end(wmJob *wm_job)
|
||||
if (final_callback) {
|
||||
final_callback(wm_job->run_customdata);
|
||||
}
|
||||
|
||||
/* Ensure all reports have been moved to WM. */
|
||||
wm_jobs_reports_update(wm, wm_job);
|
||||
}
|
||||
|
||||
static void wm_job_free(wmWindowManager *wm, wmJob *wm_job)
|
||||
@@ -519,6 +532,10 @@ static void wm_job_free(wmWindowManager *wm, wmJob *wm_job)
|
||||
BLI_remlink(&wm->jobs, wm_job);
|
||||
WM_job_main_thread_lock_release(wm_job);
|
||||
BLI_ticket_mutex_free(wm_job->main_thread_mutex);
|
||||
|
||||
BLI_assert(BLI_listbase_is_empty(&wm_job->worker_status.reports->list));
|
||||
BKE_reports_free(wm_job->worker_status.reports);
|
||||
MEM_delete(wm_job->worker_status.reports);
|
||||
MEM_freeN(wm_job);
|
||||
}
|
||||
|
||||
@@ -534,7 +551,7 @@ static void wm_jobs_kill_job(wmWindowManager *wm, wmJob *wm_job)
|
||||
WM_job_main_thread_lock_release(wm_job);
|
||||
BLI_threadpool_end(&wm_job->threads);
|
||||
WM_job_main_thread_lock_acquire(wm_job);
|
||||
wm_job_end(wm_job);
|
||||
wm_job_end(wm, wm_job);
|
||||
}
|
||||
|
||||
if (wm_job->wt) {
|
||||
@@ -644,7 +661,7 @@ void wm_jobs_timer(wmWindowManager *wm, wmTimer *wt)
|
||||
}
|
||||
|
||||
if (wm_job->ready) {
|
||||
wm_job_end(wm_job);
|
||||
wm_job_end(wm, wm_job);
|
||||
|
||||
/* free own data */
|
||||
wm_job->run_free(wm_job->run_customdata);
|
||||
@@ -689,12 +706,18 @@ void wm_jobs_timer(wmWindowManager *wm, wmTimer *wt)
|
||||
|
||||
/* remove wm_job */
|
||||
wm_job_free(wm, wm_job);
|
||||
wm_job = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (wm_job->suspended) {
|
||||
WM_jobs_start(wm, wm_job);
|
||||
}
|
||||
|
||||
/* Move pending reports generated by the worker thread to the WM main list. */
|
||||
if (wm_job) {
|
||||
wm_jobs_reports_update(wm, wm_job);
|
||||
}
|
||||
}
|
||||
|
||||
/* Update progress bars in windows. */
|
||||
|
||||
Reference in New Issue
Block a user