typedef struct _Image_Unused_Ids Image_Unused_Ids;
static int pending_threads = 0;
+static int pending_image_threads = 0;
+static Eina_List *running_threads;
static void data_process_string(Edje_Part_Collection *pc, const char *prefix, char *s, void (*func)(Edje_Part_Collection *pc, char *name, char* ptr, int len));
static Eina_Hash *part_dest_lookup = NULL;
static Eina_Hash *part_pc_dest_lookup = NULL;
+static Eet_File *cur_ef;
+static int image_num;
+static Ecore_Evas *buffer_ee;
+static int cur_image_entry;
+
+static void data_write_images(void);
+
void
error_and_abort(Eet_File *ef EINA_UNUSED, const char *fmt, ...)
{
exit(-1);
}
+static void
+thread_end(Eina_Bool img)
+{
+ if (img)
+ pending_image_threads--;
+ else
+ pending_threads--;
+ if (threads)
+ {
+ if ((pending_image_threads + pending_threads) < (int)max_open_files - 2)
+ data_write_images();
+ }
+ if (pending_threads + pending_image_threads <= 0) ecore_main_loop_quit();
+}
+
static unsigned int
_part_lookup_key_length(const void *key EINA_UNUSED)
{
}
static void
-data_thread_head_end(void *data, Ecore_Thread *thread EINA_UNUSED)
+data_thread_head_end(void *data, Ecore_Thread *thread)
{
Head_Write *hw = data;
- pending_threads--;
- if (pending_threads <= 0) ecore_main_loop_quit();
+ running_threads = eina_list_remove(running_threads, thread);
if (hw->errstr)
{
error_and_abort(hw->ef, hw->errstr);
free(hw->errstr);
}
free(hw);
+ thread_end(0);
}
static void
hw->ef = ef;
pending_threads++;
if (threads)
- ecore_thread_run(data_thread_head, data_thread_head_end, NULL, hw);
+ running_threads = eina_list_append(running_threads, ecore_thread_run(data_thread_head, data_thread_head_end, NULL, hw));
else
{
data_thread_head(hw, NULL);
}
static void
-data_thread_fonts_end(void *data, Ecore_Thread *thread EINA_UNUSED)
+data_thread_fonts_end(void *data, Ecore_Thread *thread)
{
Fonts_Write *fc = data;
- pending_threads--;
- if (pending_threads <= 0) ecore_main_loop_quit();
+
+ running_threads = eina_list_remove(running_threads, thread);
if (fc->errstr)
{
error_and_abort(fc->ef, fc->errstr);
free(fc->errstr);
}
free(fc);
+ thread_end(0);
}
static void
fc->fn = fn;
pending_threads++;
if (threads)
- ecore_thread_run(data_thread_fonts, data_thread_fonts_end, NULL, fc);
+ running_threads = eina_list_append(running_threads, ecore_thread_run(data_thread_fonts, data_thread_fonts_end, NULL, fc));
else
{
data_thread_fonts(fc, NULL);
}
static void
-data_thread_image_end(void *data, Ecore_Thread *thread EINA_UNUSED)
+data_thread_image_end(void *data, Ecore_Thread *thread)
{
Image_Write *iw = data;
- pending_threads--;
- if (pending_threads <= 0) ecore_main_loop_quit();
+ running_threads = eina_list_remove(running_threads, thread);
if (iw->errstr)
{
error_and_abort(iw->ef, iw->errstr);
evas_object_del(iw->im);
free(iw);
+ thread_end(1);
}
static void
/************************************************************************************/
if (threads)
- ecore_thread_run(data_thread_image, data_thread_image_end, NULL, iw);
+ running_threads = eina_list_append(running_threads, ecore_thread_run(data_thread_image, data_thread_image_end, NULL, iw));
else
{
data_thread_image(iw, NULL);
}
static void
-tgv_file_thread_end(void *data, Ecore_Thread *thread EINA_UNUSED)
+tgv_file_thread_end(void *data, Ecore_Thread *thread)
{
Image_Write *iw = data;
- pending_threads--;
- if (pending_threads <= 0) ecore_main_loop_quit();
+ running_threads = eina_list_remove(running_threads, thread);
if (iw->errstr)
{
error_and_abort(iw->ef, iw->errstr);
eina_file_map_free(iw->f, iw->data);
eina_file_close(iw->f);
free(iw);
+ thread_end(1);
}
static Eina_Bool
-tgv_file_check_and_add(Eet_File *ef, Edje_Image_Directory_Entry *img, int *image_num)
+tgv_file_check_and_add(Eet_File *ef, Edje_Image_Directory_Entry *img)
{
Emile_Image_Load_Error err;
Emile_Image *emi = NULL;
goto on_error;
}
- *image_num += 1;
+ image_num += 1;
iw->path = strdup(img->entry);
- pending_threads++;
+ pending_image_threads++;
if (threads)
- ecore_thread_run(tgv_file_thread, tgv_file_thread_end, NULL, iw);
+ running_threads = eina_list_append(running_threads, ecore_thread_run(tgv_file_thread, tgv_file_thread_end, NULL, iw));
else
{
tgv_file_thread(iw, NULL);
Edje_Vector_Directory_Entry *vector;
Eina_Strbuf *buf;
Eina_Bool found = EINA_FALSE;
- Ecore_Evas *ee;
Evas *evas;
Evas_Object *vg;
if (!((edje_file) && (edje_file->image_dir))) return;
- ecore_evas_init();
- ee = ecore_evas_buffer_new(1, 1);
- if (!ee)
+ if (!buffer_ee)
+ buffer_ee = ecore_evas_buffer_new(1, 1);
+ if (!buffer_ee)
error_and_abort(ef, "Cannot create buffer engine canvas for image load.");
- evas = ecore_evas_get(ee);
+ evas = ecore_evas_get(buffer_ee);
vg = evas_object_vg_add(evas);
buf = eina_strbuf_new();
for (i = 0; i < edje_file->image_dir->vectors_count; i++)
}
static void
-data_write_images(Eet_File *ef, int *image_num)
+data_image_sets_init(void)
{
int i;
- Ecore_Evas *ee;
+
+ if (!((edje_file) && (edje_file->image_dir))) return;
+ for (i = 0; i < (int)edje_file->image_dir->sets_count; i++)
+ {
+ Edje_Image_Directory_Set *set;
+ Edje_Image_Directory_Set_Entry *set_entry;
+ Edje_Image_Directory_Entry *img;
+ Eina_List *ll = NULL;
+
+ set = edje_file->image_dir->sets + i;
+ if (!set->entries) continue;
+ EINA_LIST_FOREACH(set->entries, ll, set_entry)
+ {
+ img = &edje_file->image_dir->entries[set_entry->id];
+ set_entry->name = img->entry;
+ }
+ }
+}
+
+static void
+data_write_images(void)
+{
Evas *evas;
const char *ext = NULL;
if (!((edje_file) && (edje_file->image_dir))) return;
- ecore_evas_init();
- ee = ecore_evas_buffer_new(1, 1);
- if (!ee)
- error_and_abort(ef, "Cannot create buffer engine canvas for image load.");
- evas = ecore_evas_get(ee);
+ if (!buffer_ee)
+ buffer_ee = ecore_evas_buffer_new(1, 1);
+ if (!buffer_ee)
+ error_and_abort(cur_ef, "Cannot create buffer engine canvas for image load.");
+ evas = ecore_evas_get(buffer_ee);
- for (i = 0; i < (int)edje_file->image_dir->entries_count; i++)
+ for (; cur_image_entry < (int)edje_file->image_dir->entries_count; cur_image_entry++)
{
Edje_Image_Directory_Entry *img;
Evas_Object *im;
Eina_Bool b_ninepatch;
/************************************************************************************/
- img = &edje_file->image_dir->entries[i];
+ img = &edje_file->image_dir->entries[cur_image_entry];
if ((img->source_type == EDJE_IMAGE_SOURCE_TYPE_EXTERNAL) || !img->entry)
continue;
ext = strrchr(img->entry, '.');
if (ext && !strcasecmp(ext, ".tgv"))
{
- if (tgv_file_check_and_add(ef, img, image_num))
+ if (tgv_file_check_and_add(cur_ef, img))
{
DBG("Directly copying data from TGV file into EDJ");
continue;
}
iw = calloc(1, sizeof(Image_Write));
- iw->ef = ef;
+ iw->ef = cur_ef;
iw->img = img;
iw->im = im = evas_object_image_add(evas);
load_err = evas_object_image_load_error_get(im);
if (load_err == EVAS_LOAD_ERROR_NONE)
{
- *image_num += 1;
+ image_num += 1;
iw->path = strdup(buf);
- pending_threads++;
+ pending_image_threads++;
if (threads)
evas_object_image_preload(im, 0);
using_file(buf, 'I');
load_err = evas_object_image_load_error_get(im);
if (load_err == EVAS_LOAD_ERROR_NONE)
{
- *image_num += 1;
+ image_num += 1;
iw->path = strdup(img->entry);
- pending_threads++;
+ pending_image_threads++;
if (threads)
evas_object_image_preload(im, 0);
using_file(img->entry, 'I');
else
{
free(iw);
- error_and_abort_image_load_error(ef, img->entry, load_err);
+ error_and_abort_image_load_error(cur_ef, img->entry, load_err);
exit(1); // ensure static analysis tools know we exit
}
}
+
if (img->source_type != EDJE_IMAGE_SOURCE_TYPE_EXTERNAL)
{
ext = strrchr(img->entry, '.');
img->entry = tmp;
}
}
- }
-
- for (i = 0; i < (int)edje_file->image_dir->sets_count; i++)
- {
- Edje_Image_Directory_Set *set;
- Edje_Image_Directory_Set_Entry *set_entry;
- Edje_Image_Directory_Entry *img;
- Eina_List *ll = NULL;
-
- set = edje_file->image_dir->sets + i;
- if (!set->entries) continue;
- EINA_LIST_FOREACH(set->entries, ll, set_entry)
+ if (threads)
{
- img = &edje_file->image_dir->entries[set_entry->id];
- set_entry->name = img->entry;
+ if (pending_threads + pending_image_threads > (int)max_open_files - 2) break;
}
}
}
}
static void
-data_thread_sounds_end(void *data, Ecore_Thread *thread EINA_UNUSED)
+data_thread_sounds_end(void *data, Ecore_Thread *thread)
{
Sound_Write *sw = data;
- pending_threads--;
- if (pending_threads <= 0) ecore_main_loop_quit();
+ running_threads = eina_list_remove(running_threads, thread);
free(sw);
+ thread_end(0);
}
static void
*sound_num += 1;
pending_threads++;
if (threads)
- ecore_thread_run(data_thread_sounds, data_thread_sounds_end, NULL, sw);
+ running_threads = eina_list_append(running_threads, ecore_thread_run(data_thread_sounds, data_thread_sounds_end, NULL, sw));
else
{
data_thread_sounds(sw, NULL);
}
static void
-data_thread_mo_end(void *data, Ecore_Thread *thread EINA_UNUSED)
+data_thread_mo_end(void *data, Ecore_Thread *thread)
{
Mo_Write *mw = data;
- pending_threads--;
- if (pending_threads <= 0) ecore_main_loop_quit();
+ running_threads = eina_list_remove(running_threads, thread);
if (mw->errstr)
{
error_and_abort(mw->ef, mw->errstr);
if (mw->mo_path)
free(mw->mo_path);
free(mw);
+ thread_end(0);
}
Eina_Bool
if (ecore_file_exists(mw->mo_path))
{
if (threads)
- ecore_thread_run(data_thread_mo, data_thread_mo_end, NULL, mw);
+ running_threads = eina_list_append(running_threads, ecore_thread_run(data_thread_mo, data_thread_mo_end, NULL, mw));
else
{
data_thread_mo(mw, NULL);
}
else
return ECORE_CALLBACK_RENEW;
- if (pending_threads <= 0) ecore_main_loop_quit();
+ if (pending_threads + pending_image_threads <= 0) ecore_main_loop_quit();
return ECORE_CALLBACK_CANCEL;
}
else
{
if (threads)
- ecore_thread_run(data_thread_mo, data_thread_mo_end, NULL, mw);
+ running_threads = eina_list_append(running_threads, ecore_thread_run(data_thread_mo, data_thread_mo_end, NULL, mw));
else
{
data_thread_mo(mw, NULL);
}
static void
-data_thread_vibrations_end(void *data, Ecore_Thread *thread EINA_UNUSED)
+data_thread_vibrations_end(void *data, Ecore_Thread *thread)
{
Vibration_Write *sw = data;
- pending_threads--;
- if (pending_threads <= 0) ecore_main_loop_quit();
+ running_threads = eina_list_remove(running_threads, thread);
free(sw);
+ thread_end(0);
}
static void
*num += 1;
pending_threads++;
if (threads)
- ecore_thread_run(data_thread_vibrations, data_thread_vibrations_end, NULL, vw);
+ running_threads = eina_list_append(running_threads, ecore_thread_run(data_thread_vibrations, data_thread_vibrations_end, NULL, vw));
else
{
data_thread_vibrations(vw, NULL);
}
static void
-data_thread_group_end(void *data, Ecore_Thread *thread EINA_UNUSED)
+data_thread_group_end(void *data, Ecore_Thread *thread)
{
Group_Write *gw = data;
- pending_threads--;
- if (pending_threads <= 0) ecore_main_loop_quit();
+ running_threads = eina_list_remove(running_threads, thread);
if (gw->errstr)
{
error_and_abort(gw->ef, gw->errstr);
free(gw->errstr);
}
free(gw);
+ thread_end(0);
}
static void
gw->pc = pc;
pending_threads++;
if (threads)
- ecore_thread_run(data_thread_group, data_thread_group_end, NULL, gw);
+ running_threads = eina_list_append(running_threads, ecore_thread_run(data_thread_group, data_thread_group_end, NULL, gw));
else
{
data_thread_group(gw, NULL);
static void data_write_script_queue(Script_Write *sc, const char *exeline);
static void
-data_thread_script_end(void *data, Ecore_Thread *thread EINA_UNUSED)
+data_thread_script_end(void *data, Ecore_Thread *thread)
{
Script_Write *sc = data;
- pending_threads--;
- if (pending_threads <= 0) ecore_main_loop_quit();
+ running_threads = eina_list_remove(running_threads, thread);
if (sc->errstr)
{
error_and_abort(sc->ef, sc->errstr);
free(sc->errstr);
}
free(sc);
+ thread_end(0);
}
static Eina_Bool
}
if (threads)
{
- ecore_thread_run(data_thread_script, data_thread_script_end, NULL, sc);
+ running_threads = eina_list_append(running_threads, ecore_thread_run(data_thread_script, data_thread_script_end, NULL, sc));
}
else
{
data_thread_script(sc, NULL);
data_thread_script_end(sc, NULL);
}
- if (pending_threads <= 0) ecore_main_loop_quit();
+ if (pending_threads + pending_image_threads <= 0) ecore_main_loop_quit();
return ECORE_CALLBACK_CANCEL;
}
}
static void
-data_thread_lua_script_end(void *data, Ecore_Thread *thread EINA_UNUSED)
+data_thread_lua_script_end(void *data, Ecore_Thread *thread)
{
Script_Write *sc = data;
- pending_threads--;
- if (pending_threads <= 0) ecore_main_loop_quit();
+ running_threads = eina_list_remove(running_threads, thread);
if (sc->errstr)
{
error_and_abort(sc->ef, sc->errstr);
free(sc->errstr);
}
free(sc);
+ thread_end(0);
}
static void
sc->i = i;
pending_threads++;
if (threads)
- ecore_thread_run(data_thread_lua_script, data_thread_lua_script_end, NULL, sc);
+ running_threads = eina_list_append(running_threads, ecore_thread_run(data_thread_lua_script, data_thread_lua_script_end, NULL, sc));
else
{
data_thread_lua_script(sc, NULL);
}
static void
-data_thread_source_end(void *data EINA_UNUSED, Ecore_Thread *thread EINA_UNUSED)
+data_thread_source_end(void *data EINA_UNUSED, Ecore_Thread *thread)
{
- pending_threads--;
- if (pending_threads <= 0) ecore_main_loop_quit();
+ running_threads = eina_list_remove(running_threads, thread);
+ thread_end(0);
}
static void
}
static void
-data_thread_license_end(void *data, Ecore_Thread *thread EINA_UNUSED)
+data_thread_license_end(void *data, Ecore_Thread *thread)
{
- pending_threads--;
- if (pending_threads <= 0) ecore_main_loop_quit();
free(data);
+ running_threads = eina_list_remove(running_threads, thread);
+ thread_end(0);
}
static void
pending_threads++;
if (threads)
- ecore_thread_run(data_thread_license, data_thread_license_end, NULL, lw);
+ running_threads = eina_list_append(running_threads, ecore_thread_run(data_thread_license, data_thread_license_end, NULL, lw));
else
{
data_thread_license(lw, NULL);
pending_threads++;
if (threads)
- ecore_thread_run(data_thread_license, data_thread_license_end, NULL, lw);
+ running_threads = eina_list_append(running_threads, ecore_thread_run(data_thread_license, data_thread_license_end, NULL, lw));
else
{
data_thread_license(lw, NULL);
}
static void
-data_thread_authors_end(void *data EINA_UNUSED, Ecore_Thread *thread EINA_UNUSED)
+data_thread_authors_end(void *data EINA_UNUSED, Ecore_Thread *thread)
{
- pending_threads--;
- if (pending_threads <= 0) ecore_main_loop_quit();
+ running_threads = eina_list_remove(running_threads, thread);
+ thread_end(0);
}
static void
}
static void
-data_thread_fontmap_end(void *data EINA_UNUSED, Ecore_Thread *thread EINA_UNUSED)
+data_thread_fontmap_end(void *data EINA_UNUSED, Ecore_Thread *thread)
{
- pending_threads--;
- if (pending_threads <= 0) ecore_main_loop_quit();
+ running_threads = eina_list_remove(running_threads, thread);
+ thread_end(0);
}
void
{
Eet_File *ef;
Eet_Error err;
- int image_num = 0;
int model_num = 0;
int sound_num = 0;
int mo_num = 0;
exit(-1);
}
- ef = eet_open(file_out, EET_FILE_MODE_WRITE);
+ cur_ef = ef = eet_open(file_out, EET_FILE_MODE_WRITE);
if (!ef)
{
ERR("Unable to open \"%s\" for writing output", file_out);
{
pending_threads++;
if (threads)
- ecore_thread_run(data_thread_source, data_thread_source_end, NULL, ef);
+ running_threads = eina_list_append(running_threads, ecore_thread_run(data_thread_source, data_thread_source_end, NULL, ef));
else
{
data_thread_source(ef, NULL);
INF("source: %3.5f", ecore_time_get() - t); t = ecore_time_get();
pending_threads++;
if (threads)
- ecore_thread_run(data_thread_fontmap, data_thread_fontmap_end, NULL, ef);
+ running_threads = eina_list_append(running_threads, ecore_thread_run(data_thread_fontmap, data_thread_fontmap_end, NULL, ef));
else
{
data_thread_fontmap(ef, NULL);
data_thread_fontmap_end(ef, NULL);
}
INF("fontmap: %3.5f", ecore_time_get() - t); t = ecore_time_get();
- data_write_images(ef, &image_num);
- INF("images: %3.5f", ecore_time_get() - t); t = ecore_time_get();
data_write_vectors(ef, &vector_num);
INF("vectors: %3.5f", ecore_time_get() - t); t = ecore_time_get();
data_check_models(ef, &model_num);
{
pending_threads++;
if (threads)
- ecore_thread_run(data_thread_authors, data_thread_authors_end, NULL, ef);
+ running_threads = eina_list_append(running_threads, ecore_thread_run(data_thread_authors, data_thread_authors_end, NULL, ef));
else
{
data_thread_authors(ef, NULL);
data_thread_authors_end(ef, NULL);
}
}
+ data_write_images();
+ data_image_sets_init();
+ INF("images: %3.5f", ecore_time_get() - t); t = ecore_time_get();
pending_threads--;
if (pending_threads > 0) ecore_main_loop_begin();
INF("THREADS: %3.5f", ecore_time_get() - t);
data_write_header(ef);
+ if (pending_threads > 0) ecore_main_loop_begin();
+ INF("THREADS: %3.5f", ecore_time_get() - t);
+
+ if (threads)
+ {
+ /* probably caught signal, exit immediately to avoid crash */
+ if (running_threads) exit(-1);
+ }
err = eet_close(ef);
if (err)
_data_image_sets_size_set()
{
Evas *evas;
- Ecore_Evas *ee;
Edje_Image_Directory_Set *set;
Edje_Image_Directory_Set_Entry *simg, *preimg;
Eina_List *l, *entries;
unsigned int i;
- ecore_evas_init();
- ee = ecore_evas_buffer_new(1, 1);
- if (!ee)
+ if (!buffer_ee)
+ buffer_ee = ecore_evas_buffer_new(1, 1);
+ if (!buffer_ee)
{
ERR("Cannot create buffer engine canvas for image load.");
exit(-1);
}
- evas = ecore_evas_get(ee);
+ evas = ecore_evas_get(buffer_ee);
for (i = 0; i < edje_file->image_dir->sets_count; i++)
{