void dt_control_shutdown(dt_control_t *s) { dt_pthread_mutex_lock(&s->cond_mutex); dt_pthread_mutex_lock(&s->run_mutex); s->running = 0; dt_pthread_mutex_unlock(&s->run_mutex); dt_pthread_mutex_unlock(&s->cond_mutex); pthread_cond_broadcast(&s->cond); /* cancel background job if any */ dt_control_job_cancel(&s->job_res[DT_CTL_WORKER_7]); /* first wait for kick_on_workers_thread */ pthread_join(s->kick_on_workers_thread, NULL); gdk_threads_leave(); int k; for(k=0; k<s->num_threads; k++) // pthread_kill(s->thread[k], 9); pthread_join(s->thread[k], NULL); for(k=0; k<DT_CTL_WORKER_RESERVED; k++) // pthread_kill(s->thread_res[k], 9); pthread_join(s->thread_res[k], NULL); gdk_threads_enter(); }
static gboolean _dialog_close(GtkWidget *window, GdkEvent *event,gpointer user_data ) { _camera_import_dialog_t *data=(_camera_import_dialog_t*)user_data; if (data->preview_job) { /* cancel preview fetching job */ dt_control_job_cancel (data->preview_job); /* wait for job execution to signal finished */ dt_control_job_wait (data->preview_job); } return FALSE; }
static void _lib_backgroundjobs_cancel_callback(GtkWidget *w, gpointer user_data) { dt_job_t *job=(dt_job_t *)user_data; dt_control_job_cancel(job); }
static void dt_control_progress_cancel_callback(dt_progress_t *progress, void *data) { dt_control_job_cancel((dt_job_t *)data); }
static int32_t dt_control_export_job_run(dt_job_t *job) { int imgid = -1; dt_control_image_enumerator_t *t1 = (dt_control_image_enumerator_t *)job->param; dt_control_export_t *settings = (dt_control_export_t*)t1->data; GList *t = t1->index; dt_imageio_module_format_t *mformat = dt_imageio_get_format_by_index(settings->format_index); g_assert(mformat); dt_imageio_module_storage_t *mstorage = dt_imageio_get_storage_by_index(settings->storage_index); g_assert(mstorage); // Get max dimensions... uint32_t w,h,fw,fh,sw,sh; fw=fh=sw=sh=0; mstorage->dimension(mstorage, &sw,&sh); mformat->dimension(mformat, &fw,&fh); if( sw==0 || fw==0) w=sw>fw?sw:fw; else w=sw<fw?sw:fw; if( sh==0 || fh==0) h=sh>fh?sh:fh; else h=sh<fh?sh:fh; // get shared storage param struct (global sequence counter, one picasa connection etc) dt_imageio_module_data_t *sdata = mstorage->get_params(mstorage); if(sdata == NULL) { dt_control_log(_("failed to get parameters from storage module `%s', aborting export.."), mstorage->name(mstorage)); g_free(t1->data); return 1; } if(mstorage->initialize_store) { /* get temporary format params */ dt_imageio_module_data_t *fdata = mformat->get_params(mformat); mstorage->initialize_store(mstorage, sdata, mformat, fdata, &t, settings->high_quality); mformat->set_params(mformat,fdata,mformat->params_size(mformat)); mformat->free_params(mformat,fdata); } const int total = g_list_length(t); dt_control_log(ngettext ("exporting %d image..", "exporting %d images..", total), total); char message[512]= {0}; snprintf(message, 512, ngettext ("exporting %d image to %s", "exporting %d images to %s", total), total, mstorage->name(mstorage) ); /* create a cancellable bgjob ui template */ const guint *jid = dt_control_backgroundjobs_create(darktable.control, 0, message ); dt_control_backgroundjobs_set_cancellable(darktable.control, jid, job); const dt_control_t *control = darktable.control; double fraction=0; #ifdef _OPENMP // limit this to num threads = num full buffers - 1 (keep one for darkroom mode) // use min of user request and mipmap cache entries const int full_entries = dt_conf_get_int ("parallel_export"); // GCC won't accept that this variable is used in a macro, considers // it set but not used, which makes for instance Fedora break. const __attribute__((__unused__)) int num_threads = MAX(1, MIN(full_entries, 8)); #if !defined(__SUNOS__) && !defined(__NetBSD__) && !defined(__WIN32__) #pragma omp parallel default(none) private(imgid) shared(control, fraction, w, h, stderr, mformat, mstorage, t, sdata, job, jid, darktable, settings) num_threads(num_threads) if(num_threads > 1) #else #pragma omp parallel private(imgid) shared(control, fraction, w, h, mformat, mstorage, t, sdata, job, jid, darktable, settings) num_threads(num_threads) if(num_threads > 1) #endif { #endif // get a thread-safe fdata struct (one jpeg struct per thread etc): dt_imageio_module_data_t *fdata = mformat->get_params(mformat); fdata->max_width = settings->max_width; fdata->max_height = settings->max_height; fdata->max_width = (w!=0 && fdata->max_width >w)?w:fdata->max_width; fdata->max_height = (h!=0 && fdata->max_height >h)?h:fdata->max_height; strcpy(fdata->style,settings->style); int num = 0; // Invariant: the tagid for 'darktable|changed' will not change while this function runs. Is this a sensible assumption? guint tagid = 0, etagid = 0; dt_tag_new("darktable|changed",&tagid); dt_tag_new("darktable|exported",&etagid); while(t && dt_control_job_get_state(job) != DT_JOB_STATE_CANCELLED) { #ifdef _OPENMP #pragma omp critical #endif { if(!t) imgid = 0; else { imgid = GPOINTER_TO_INT(t->data); t = g_list_delete_link(t, t); num = total - g_list_length(t); } } // remove 'changed' tag from image dt_tag_detach(tagid, imgid); // make sure the 'exported' tag is set on the image dt_tag_attach(etagid, imgid); // check if image still exists: char imgfilename[DT_MAX_PATH_LEN]; const dt_image_t *image = dt_image_cache_read_get(darktable.image_cache, (int32_t)imgid); if(image) { gboolean from_cache = TRUE; dt_image_full_path(image->id, imgfilename, DT_MAX_PATH_LEN, &from_cache); if(!g_file_test(imgfilename, G_FILE_TEST_IS_REGULAR)) { dt_control_log(_("image `%s' is currently unavailable"), image->filename); fprintf(stderr, "image `%s' is currently unavailable", imgfilename); // dt_image_remove(imgid); dt_image_cache_read_release(darktable.image_cache, image); } else { dt_image_cache_read_release(darktable.image_cache, image); if(mstorage->store(mstorage,sdata, imgid, mformat, fdata, num, total, settings->high_quality) != 0) dt_control_job_cancel(job); } } #ifdef _OPENMP #pragma omp critical #endif { fraction+=1.0/total; if(fraction > 1.0) fraction = 1.0; dt_control_backgroundjobs_progress(control, jid, fraction); } } #ifdef _OPENMP #pragma omp barrier #pragma omp master #endif { dt_control_backgroundjobs_destroy(control, jid); if(mstorage->finalize_store) mstorage->finalize_store(mstorage, sdata); mstorage->free_params(mstorage, sdata); } // all threads free their fdata mformat->free_params (mformat, fdata); #ifdef _OPENMP } #endif g_free(t1->data); return 0; }