// BEGIN - code running in my custom thread instance // static void th_do(void *data, Ecore_Thread *th) { double t = 0.0; // inside our "do" function for the ecore thread, lets do the real work for (;;) { struct info *inf = malloc(sizeof(struct info)); if (inf) { inf->x = 200 + (200 * sin(t)); inf->y = 200 + (200 * cos(t)); // now we have recorded the timepoint we pass it as feedback // back to the mainloop. it will free it when done ecore_thread_feedback(th, inf); } // and sleep and loop usleep(1000); t += 0.02; // in case someone has asked us to cancel - then cancel this loop // co-operatively (cancelling is co-operative) if (ecore_thread_check(th)) break; } }
static void _eio_ls_xattr_heavy(void *data, Ecore_Thread *thread) { Eio_File_Char_Ls *async = data; Eina_Iterator *it; const char *tmp; it = eina_xattr_ls(async->ls.directory); if (!it) return ; EINA_ITERATOR_FOREACH(it, tmp) { Eina_Bool filter = EINA_TRUE; if (async->filter_cb) { filter = async->filter_cb((void*) async->ls.common.data, &async->ls.common, tmp); } if (filter) ecore_thread_feedback(thread, eina_stringshare_add(tmp)); if (ecore_thread_check(thread)) break; }
Eina_List * eio_pack_send(Ecore_Thread *thread, Eina_List *pack, double *start) { double current; current = ecore_time_get(); if (current - *start > EIO_PACKED_TIME) { *start = current; ecore_thread_feedback(thread, pack); return NULL; } if (memory_pool_limit > 0 && memory_pool_usage > memory_pool_limit) { eina_lock_take(&(memory_pool_mutex)); memory_pool_suspended = EINA_TRUE; eina_condition_wait(&(memory_pool_cond)); memory_pool_suspended = EINA_FALSE; eina_lock_release(&(memory_pool_mutex)); } return pack; }
void eio_progress_send(Ecore_Thread *thread, Eio_File_Progress *op, long long current, long long max) { Eio_Progress *progress; if (op->progress_cb == NULL) return ; progress = eio_progress_malloc(); if (!progress) return ; progress->op = op->op; progress->current = current; progress->max = max; progress->percent = (float) current * 100.0 / (float) max; progress->source = eina_stringshare_ref(op->source); progress->dest = eina_stringshare_ref(op->dest); ecore_thread_feedback(thread, progress); }
static void _eio_file_heavy(void *data, Ecore_Thread *thread) { Eio_File_Char_Ls *async = data; Eina_Iterator *ls; const char *file; Eina_List *pack = NULL; double start, current; ls = eina_file_ls(async->ls.directory); if (!ls) { eio_file_thread_error(&async->ls.common, thread); return ; } eio_file_container_set(&async->ls.common, eina_iterator_container_get(ls)); start = ecore_time_get(); EINA_ITERATOR_FOREACH(ls, file) { Eina_Bool filter = EINA_TRUE; if (async->filter_cb) { filter = async->filter_cb((void*) async->ls.common.data, &async->ls.common, file); } if (filter) { Eio_File_Char *send_fc; send_fc = eio_char_malloc(); if (!send_fc) goto on_error; send_fc->filename = file; send_fc->associated = async->ls.common.worker.associated; async->ls.common.worker.associated = NULL; pack = eina_list_append(pack, send_fc); } else { on_error: eina_stringshare_del(file); if (async->ls.common.worker.associated) { eina_hash_free(async->ls.common.worker.associated); async->ls.common.worker.associated = NULL; } } current = ecore_time_get(); if (current - start > EIO_PACKED_TIME) { start = current; ecore_thread_feedback(thread, pack); pack = NULL; } if (ecore_thread_check(thread)) break; }