Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/intern/wm_jobs.c
| Show All 17 Lines | |||||
| */ | */ | ||||
| /** \file | /** \file | ||||
| * \ingroup wm | * \ingroup wm | ||||
| * | * | ||||
| * Threaded job manager (high level job access). | * Threaded job manager (high level job access). | ||||
| */ | */ | ||||
| #include <CLG_log.h> | |||||
| #include <string.h> | #include <string.h> | ||||
| #include "DNA_windowmanager_types.h" | #include "DNA_windowmanager_types.h" | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "BLI_blenlib.h" | #include "BLI_blenlib.h" | ||||
| #include "BLI_threads.h" | #include "BLI_threads.h" | ||||
| ▲ Show 20 Lines • Show All 397 Lines • ▼ Show 20 Lines | for (wm_job = wm->jobs.first; wm_job; wm_job = wm_job->next) { | ||||
| } | } | ||||
| } | } | ||||
| suspend = true; | suspend = true; | ||||
| /* if this job has higher priority, stop others */ | /* if this job has higher priority, stop others */ | ||||
| if (test->flag & WM_JOB_PRIORITY) { | if (test->flag & WM_JOB_PRIORITY) { | ||||
| wm_job->stop = true; | wm_job->stop = true; | ||||
| // printf("job stopped: %s\n", wm_job->name); | CLOG_INFO(WM_LOG_JOBS, "job stopped: %s\n", wm_job->name); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* Possible suspend ourselves, waiting for other jobs, or de-suspend. */ | /* Possible suspend ourselves, waiting for other jobs, or de-suspend. */ | ||||
| test->suspended = suspend; | test->suspended = suspend; | ||||
| // if (suspend) printf("job suspended: %s\n", test->name); | if (suspend) { | ||||
| CLOG_INFO(WM_LOG_JOBS, "job suspended: %s\n", test->name); | |||||
| } | |||||
| } | } | ||||
| /** | /** | ||||
| * if job running, the same owner gave it a new job. | * if job running, the same owner gave it a new job. | ||||
| * if different owner starts existing startjob, it suspends itself | * if different owner starts existing startjob, it suspends itself | ||||
| */ | */ | ||||
| void WM_jobs_start(wmWindowManager *wm, wmJob *wm_job) | void WM_jobs_start(wmWindowManager *wm, wmJob *wm_job) | ||||
| { | { | ||||
| if (wm_job->running) { | if (wm_job->running) { | ||||
| /* signal job to end and restart */ | /* signal job to end and restart */ | ||||
| wm_job->stop = true; | wm_job->stop = true; | ||||
| // printf("job started a running job, ending... %s\n", wm_job->name); | CLOG_INFO(WM_LOG_JOBS, "job started a running job, ending... %s", wm_job->name); | ||||
| } | } | ||||
| else { | else { | ||||
| if (wm_job->customdata && wm_job->startjob) { | if (wm_job->customdata && wm_job->startjob) { | ||||
| const double timestep = (wm_job->start_delay_time > 0.0) ? wm_job->start_delay_time : | const double timestep = (wm_job->start_delay_time > 0.0) ? wm_job->start_delay_time : | ||||
| wm_job->timestep; | wm_job->timestep; | ||||
| wm_jobs_test_suspend_stop(wm, wm_job); | wm_jobs_test_suspend_stop(wm, wm_job); | ||||
| Show All 9 Lines | if (wm_job->customdata && wm_job->startjob) { | ||||
| if (wm_job->initjob) { | if (wm_job->initjob) { | ||||
| wm_job->initjob(wm_job->run_customdata); | wm_job->initjob(wm_job->run_customdata); | ||||
| } | } | ||||
| wm_job->stop = false; | wm_job->stop = false; | ||||
| wm_job->ready = false; | wm_job->ready = false; | ||||
| wm_job->progress = 0.0; | wm_job->progress = 0.0; | ||||
| // printf("job started: %s\n", wm_job->name); | CLOG_INFO(WM_LOG_JOBS, "job started: %s", wm_job->name); | ||||
| BLI_threadpool_init(&wm_job->threads, do_job_thread, 1); | BLI_threadpool_init(&wm_job->threads, do_job_thread, 1); | ||||
| BLI_threadpool_insert(&wm_job->threads, wm_job); | BLI_threadpool_insert(&wm_job->threads, wm_job); | ||||
| } | } | ||||
| /* restarted job has timer already */ | /* restarted job has timer already */ | ||||
| if (wm_job->wt && (wm_job->wt->timestep > timestep)) { | if (wm_job->wt && (wm_job->wt->timestep > timestep)) { | ||||
| WM_event_remove_timer(wm, wm_job->win, wm_job->wt); | WM_event_remove_timer(wm, wm_job->win, wm_job->wt); | ||||
| wm_job->wt = WM_event_add_timer(wm, wm_job->win, TIMERJOBS, timestep); | wm_job->wt = WM_event_add_timer(wm, wm_job->win, TIMERJOBS, timestep); | ||||
| } | } | ||||
| if (wm_job->wt == NULL) { | if (wm_job->wt == NULL) { | ||||
| wm_job->wt = WM_event_add_timer(wm, wm_job->win, TIMERJOBS, timestep); | wm_job->wt = WM_event_add_timer(wm, wm_job->win, TIMERJOBS, timestep); | ||||
| } | } | ||||
| wm_job->start_time = PIL_check_seconds_timer(); | wm_job->start_time = PIL_check_seconds_timer(); | ||||
| } | } | ||||
| else { | else { | ||||
| printf("job fails, not initialized\n"); | CLOG_WARN(WM_LOG_JOBS, "job %s fails, not initialized", wm_job->name); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void wm_job_free(wmWindowManager *wm, wmJob *wm_job) | static void wm_job_free(wmWindowManager *wm, wmJob *wm_job) | ||||
| { | { | ||||
| BLI_remlink(&wm->jobs, wm_job); | BLI_remlink(&wm->jobs, wm_job); | ||||
| WM_job_main_thread_lock_release(wm_job); | WM_job_main_thread_lock_release(wm_job); | ||||
| ▲ Show 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | if (wm_job->wt == wt) { | ||||
| wm_job->endjob(wm_job->run_customdata); | wm_job->endjob(wm_job->run_customdata); | ||||
| } | } | ||||
| /* free own data */ | /* free own data */ | ||||
| wm_job->run_free(wm_job->run_customdata); | wm_job->run_free(wm_job->run_customdata); | ||||
| wm_job->run_customdata = NULL; | wm_job->run_customdata = NULL; | ||||
| wm_job->run_free = NULL; | wm_job->run_free = NULL; | ||||
| // if (wm_job->stop) printf("job ready but stopped %s\n", wm_job->name); | if (wm_job->stop) { | ||||
| // else printf("job finished %s\n", wm_job->name); | CLOG_INFO(WM_LOG_JOBS, "job ready but stopped: %s", wm_job->name); | ||||
| } | |||||
| else { | |||||
| CLOG_INFO(WM_LOG_JOBS, "job finished: %s", wm_job->name); | |||||
| } | |||||
| if (G.debug & G_DEBUG_JOBS) { | CLOG_VERBOSE(WM_LOG_JOBS, | ||||
| printf("Job '%s' finished in %f seconds\n", | 1, | ||||
| "Job '%s' finished in %f seconds", | |||||
| wm_job->name, | wm_job->name, | ||||
| PIL_check_seconds_timer() - wm_job->start_time); | PIL_check_seconds_timer() - wm_job->start_time); | ||||
| } | |||||
| wm_job->running = false; | wm_job->running = false; | ||||
| WM_job_main_thread_lock_release(wm_job); | WM_job_main_thread_lock_release(wm_job); | ||||
| BLI_threadpool_end(&wm_job->threads); | BLI_threadpool_end(&wm_job->threads); | ||||
| WM_job_main_thread_lock_acquire(wm_job); | WM_job_main_thread_lock_acquire(wm_job); | ||||
| if (wm_job->endnote) { | if (wm_job->endnote) { | ||||
| WM_event_add_notifier_ex(wm, wm_job->win, wm_job->endnote, NULL); | WM_event_add_notifier_ex(wm, wm_job->win, wm_job->endnote, NULL); | ||||
| } | } | ||||
| WM_event_add_notifier_ex(wm, wm_job->win, NC_WM | ND_JOB, NULL); | WM_event_add_notifier_ex(wm, wm_job->win, NC_WM | ND_JOB, NULL); | ||||
| /* new job added for wm_job? */ | /* new job added for wm_job? */ | ||||
| if (wm_job->customdata) { | if (wm_job->customdata) { | ||||
| // printf("job restarted with new data %s\n", wm_job->name); | CLOG_INFO(WM_LOG_JOBS, "job restarted with new data %s", wm_job->name); | ||||
| WM_jobs_start(wm, wm_job); | WM_jobs_start(wm, wm_job); | ||||
| } | } | ||||
| else { | else { | ||||
| WM_event_remove_timer(wm, wm_job->win, wm_job->wt); | WM_event_remove_timer(wm, wm_job->win, wm_job->wt); | ||||
| wm_job->wt = NULL; | wm_job->wt = NULL; | ||||
| /* remove wm_job */ | /* remove wm_job */ | ||||
| wm_job_free(wm, wm_job); | wm_job_free(wm, wm_job); | ||||
| Show All 25 Lines | |||||