* ecore: rename ecore_long_run to ecore_thread_feedback_run.

SVN revision: 52573
This commit is contained in:
Cedric BAIL 2010-09-22 09:47:55 +00:00
parent 08b5fe088a
commit 8036a32918
4 changed files with 67 additions and 67 deletions

View File

@ -412,18 +412,18 @@ extern "C" {
Ecore_Cb,
Ecore_Cb,
const void *data);
EAPI Ecore_Thread *ecore_long_run(Ecore_Thread_Heavy_Cb,
Ecore_Thread_Notify_Cb,
Ecore_Cb,
Ecore_Cb,
const void *data,
Eina_Bool try_no_queue);
EAPI Ecore_Thread *ecore_thread_feedback_run(Ecore_Thread_Heavy_Cb,
Ecore_Thread_Notify_Cb,
Ecore_Cb,
Ecore_Cb,
const void *data,
Eina_Bool try_no_queue);
EAPI Eina_Bool ecore_thread_cancel(Ecore_Thread *thread);
EAPI Eina_Bool ecore_thread_check(Ecore_Thread *thread);
EAPI Eina_Bool ecore_thread_notify(Ecore_Thread *thread, const void *msg_data);
EAPI Eina_Bool ecore_thread_feedback(Ecore_Thread *thread, const void *msg_data);
EAPI int ecore_thread_active_get(void);
EAPI int ecore_thread_pending_get(void);
EAPI int ecore_thread_pending_long_get(void);
EAPI int ecore_thread_pending_feedback_get(void);
EAPI int ecore_thread_pending_total_get(void);
EAPI int ecore_thread_max_get(void);
EAPI void ecore_thread_max_set(int num);

View File

@ -44,7 +44,7 @@ struct _Ecore_Pthread_Worker
Ecore_Thread_Heavy_Cb func_heavy;
Ecore_Thread_Notify_Cb func_notify;
Ecore_Pipe *notify;
} long_run;
} feedback_run;
} u;
Ecore_Cb func_cancel;
@ -59,7 +59,7 @@ struct _Ecore_Pthread_Worker
const void *data;
Eina_Bool cancel : 1;
Eina_Bool long_run : 1;
Eina_Bool feedback_run : 1;
};
#ifdef EFL_HAVE_PTHREAD
@ -81,7 +81,7 @@ static int _ecore_thread_count = 0;
static Eina_List *_ecore_active_job_threads = NULL;
static Eina_List *_ecore_pending_job_threads = NULL;
static Eina_List *_ecore_pending_job_threads_long = NULL;
static Eina_List *_ecore_pending_job_threads_feedback = NULL;
static Ecore_Event_Handler *del_handler = NULL;
static pthread_mutex_t _ecore_pending_job_threads_mutex = PTHREAD_MUTEX_INITIALIZER;
@ -149,8 +149,8 @@ _ecore_thread_handler(void *data __UNUSED__, void *buffer, unsigned int nbyte)
work->func_end((void *) work->data);
}
if (work->long_run)
ecore_pipe_del(work->u.long_run.notify);
if (work->feedback_run)
ecore_pipe_del(work->u.feedback_run.notify);
pthread_cond_destroy(&work->cond);
pthread_mutex_destroy(&work->mutex);
if (work->hash)
@ -168,8 +168,8 @@ _ecore_notify_handler(void *data, void *buffer, unsigned int nbyte)
user_data = *(void **)buffer;
if (work->u.long_run.func_notify)
work->u.long_run.func_notify((Ecore_Thread *) work, user_data, (void *) work->data);
if (work->u.feedback_run.func_notify)
work->u.feedback_run.func_notify((Ecore_Thread *) work, user_data, (void *) work->data);
}
static void
@ -200,28 +200,28 @@ _ecore_short_job(Ecore_Pipe *end_pipe)
}
static void
_ecore_long_job(Ecore_Pipe *end_pipe, pthread_t thread)
_ecore_feedback_job(Ecore_Pipe *end_pipe, pthread_t thread)
{
Ecore_Pthread_Worker *work;
while (_ecore_pending_job_threads_long)
while (_ecore_pending_job_threads_feedback)
{
pthread_mutex_lock(&_ecore_pending_job_threads_mutex);
if (!_ecore_pending_job_threads_long)
if (!_ecore_pending_job_threads_feedback)
{
pthread_mutex_unlock(&_ecore_pending_job_threads_mutex);
break;
}
work = eina_list_data_get(_ecore_pending_job_threads_long);
_ecore_pending_job_threads_long = eina_list_remove_list(_ecore_pending_job_threads_long, _ecore_pending_job_threads_long);
work = eina_list_data_get(_ecore_pending_job_threads_feedback);
_ecore_pending_job_threads_feedback = eina_list_remove_list(_ecore_pending_job_threads_feedback, _ecore_pending_job_threads_feedback);
pthread_mutex_unlock(&_ecore_pending_job_threads_mutex);
work->self = thread;
if (!work->cancel)
work->u.long_run.func_heavy((Ecore_Thread *) work, (void *) work->data);
work->u.feedback_run.func_heavy((Ecore_Thread *) work, (void *) work->data);
ecore_pipe_write(end_pipe, &work, sizeof (Ecore_Pthread_Worker *));
}
@ -298,7 +298,7 @@ _ecore_direct_worker(Ecore_Pthread_Worker *work)
pth->thread = pthread_self();
work->self = pth->thread;
work->u.long_run.func_heavy((Ecore_Thread *) work, (void *) work->data);
work->u.feedback_run.func_heavy((Ecore_Thread *) work, (void *) work->data);
ecore_pipe_write(pth->p, &work, sizeof (Ecore_Pthread_Worker *));
@ -315,7 +315,7 @@ _ecore_direct_worker(Ecore_Pthread_Worker *work)
work->func_end = (void *) _ecore_thread_end;
work->func_cancel = NULL;
work->cancel = EINA_FALSE;
work->long_run = EINA_FALSE;
work->feedback_run = EINA_FALSE;
work->hash = NULL;
pthread_cond_init(&work->cond, NULL);
pthread_mutex_init(&work->mutex, NULL);
@ -340,9 +340,9 @@ _ecore_thread_worker(Ecore_Pthread_Data *pth)
on_error:
if (_ecore_pending_job_threads) _ecore_short_job(pth->p);
if (_ecore_pending_job_threads_long) _ecore_long_job(pth->p, pth->thread);
if (_ecore_pending_job_threads_feedback) _ecore_feedback_job(pth->p, pth->thread);
/* FIXME: Check if there is long running task todo, and switch to long run handler. */
/* FIXME: Check if there is feedback running task todo, and switch to feedback run handler. */
pthread_mutex_lock(&_ecore_pending_job_threads_mutex);
if (_ecore_pending_job_threads)
@ -350,7 +350,7 @@ _ecore_thread_worker(Ecore_Pthread_Data *pth)
pthread_mutex_unlock(&_ecore_pending_job_threads_mutex);
goto on_error;
}
if (_ecore_pending_job_threads_long)
if (_ecore_pending_job_threads_feedback)
{
pthread_mutex_unlock(&_ecore_pending_job_threads_mutex);
goto on_error;
@ -368,7 +368,7 @@ _ecore_thread_worker(Ecore_Pthread_Data *pth)
work->func_end = (void *) _ecore_thread_end;
work->func_cancel = NULL;
work->cancel = EINA_FALSE;
work->long_run = EINA_FALSE;
work->feedback_run = EINA_FALSE;
work->hash = NULL;
pthread_cond_init(&work->cond, NULL);
pthread_mutex_init(&work->mutex, NULL);
@ -482,7 +482,7 @@ ecore_thread_run(Ecore_Cb func_blocking,
work->func_end = func_end;
work->func_cancel = func_cancel;
work->cancel = EINA_FALSE;
work->long_run = EINA_FALSE;
work->feedback_run = EINA_FALSE;
work->data = data;
pthread_mutex_lock(&_ecore_pending_job_threads_mutex);
@ -617,7 +617,7 @@ ecore_thread_check(Ecore_Thread *thread)
* @param try_no_queue If you wan't to run outside of the thread pool.
* @return A reference to the newly created thread instance, or NULL if it failed.
*
* ecore_long_run provide a facility for easily managing heavy task in a
* ecore_thread_feedback_run provide a facility for easily managing heavy task in a
* parallel thread. You should provide four functions. The first one, func_heavy,
* that will do the heavy work in another thread (so you should not use the
* EFL in it except Eina and Eet if you are careful). The second one, func_notify,
@ -628,19 +628,19 @@ ecore_thread_check(Ecore_Thread *thread)
* be called in the main loop also, if the thread is cancelled or could not run at all.
*
* Be aware, that you can't make assumption on the result order of func_end
* after many call to ecore_long_run, as we start as much thread as the
* after many call to ecore_feedback_run, as we start as much thread as the
* host CPU can handle.
*
* If you set try_no_queue, it will try to run outside of the thread pool, this can bring
* the CPU down, so be careful with that. Of course if it can't start a new thread, it will
* try to use one from the pool.
*/
EAPI Ecore_Thread *ecore_long_run(Ecore_Thread_Heavy_Cb func_heavy,
Ecore_Thread_Notify_Cb func_notify,
Ecore_Cb func_end,
Ecore_Cb func_cancel,
const void *data,
Eina_Bool try_no_queue)
EAPI Ecore_Thread *ecore_thread_feedback_run(Ecore_Thread_Heavy_Cb func_heavy,
Ecore_Thread_Notify_Cb func_notify,
Ecore_Cb func_end,
Ecore_Cb func_cancel,
const void *data,
Eina_Bool try_no_queue)
{
#ifdef EFL_HAVE_PTHREAD
@ -652,8 +652,8 @@ EAPI Ecore_Thread *ecore_long_run(Ecore_Thread_Heavy_Cb func_heavy,
worker = malloc(sizeof (Ecore_Pthread_Worker));
if (!worker) goto on_error;
worker->u.long_run.func_heavy = func_heavy;
worker->u.long_run.func_notify = func_notify;
worker->u.feedback_run.func_heavy = func_heavy;
worker->u.feedback_run.func_notify = func_notify;
worker->hash = NULL;
pthread_cond_init(&worker->cond, NULL);
pthread_mutex_init(&worker->mutex, NULL);
@ -661,9 +661,9 @@ EAPI Ecore_Thread *ecore_long_run(Ecore_Thread_Heavy_Cb func_heavy,
worker->func_end = func_end;
worker->data = data;
worker->cancel = EINA_FALSE;
worker->long_run = EINA_TRUE;
worker->feedback_run = EINA_TRUE;
worker->u.long_run.notify = ecore_pipe_add(_ecore_notify_handler, worker);
worker->u.feedback_run.notify = ecore_pipe_add(_ecore_notify_handler, worker);
if (!try_no_queue)
{
@ -674,7 +674,7 @@ EAPI Ecore_Thread *ecore_long_run(Ecore_Thread_Heavy_Cb func_heavy,
}
pthread_mutex_lock(&_ecore_pending_job_threads_mutex);
_ecore_pending_job_threads_long = eina_list_append(_ecore_pending_job_threads_long, worker);
_ecore_pending_job_threads_feedback = eina_list_append(_ecore_pending_job_threads_feedback, worker);
if (_ecore_thread_count == _ecore_thread_count_max)
{
@ -707,7 +707,7 @@ EAPI Ecore_Thread *ecore_long_run(Ecore_Thread_Heavy_Cb func_heavy,
if (worker)
{
ecore_pipe_del(worker->u.long_run.notify);
ecore_pipe_del(worker->u.feedback_run.notify);
free(worker);
worker = NULL;
}
@ -723,14 +723,14 @@ EAPI Ecore_Thread *ecore_long_run(Ecore_Thread_Heavy_Cb func_heavy,
If no thread and as we don't want to break app that rely on this
facility, we will lock the interface until we are done.
*/
worker.u.long_run.func_heavy = func_heavy;
worker.u.long_run.func_notify = func_notify;
worker.u.long_run.notify = NULL;
worker.u.feedback_run.func_heavy = func_heavy;
worker.u.feedback_run.func_notify = func_notify;
worker.u.feedback_run.notify = NULL;
worker.func_cancel = func_cancel;
worker.func_end = func_end;
worker.data = data;
worker.cancel = EINA_FALSE;
worker.long_run = EINA_TRUE;
worker.feedback_run = EINA_TRUE;
func_heavy((Ecore_Thread *) &worker, (void *)data);
@ -759,16 +759,16 @@ ecore_thread_notify(Ecore_Thread *thread, const void *data)
Ecore_Pthread_Worker *worker = (Ecore_Pthread_Worker *) thread;
if (!worker) return EINA_FALSE;
if (!worker->long_run) return EINA_FALSE;
if (!worker->feedback_run) return EINA_FALSE;
#ifdef EFL_HAVE_PTHREAD
if (!pthread_equal(worker->self, pthread_self())) return EINA_FALSE;
ecore_pipe_write(worker->u.long_run.notify, &data, sizeof (void *));
ecore_pipe_write(worker->u.feedback_run.notify, &data, sizeof (void *));
return EINA_TRUE;
#else
worker->u.long_run.func_notify(thread, (void*) data, (void*) worker->data);
worker->u.feedback_run.func_notify(thread, (void*) data, (void*) worker->data);
return EINA_TRUE;
#endif
@ -811,18 +811,18 @@ ecore_thread_pending_get(void)
}
/**
* @brief Get number of pending long thread jobs
* @return Number of pending threads running "long" jobs
* @brief Get number of pending feedback thread jobs
* @return Number of pending threads running "feedback" jobs
* This returns the number of threads currently running jobs through the
* ecore_long_run api call.
* ecore_thread_feedback_run api call.
*/
EAPI int
ecore_thread_pending_long_get(void)
ecore_thread_pending_feedback_get(void)
{
int ret;
#ifdef EFL_HAVE_PTHREAD
pthread_mutex_lock(&_ecore_pending_job_threads_mutex);
ret = eina_list_count(_ecore_pending_job_threads_long);
ret = eina_list_count(_ecore_pending_job_threads_feedback);
pthread_mutex_unlock(&_ecore_pending_job_threads_mutex);
return ret;
#else
@ -834,7 +834,7 @@ ecore_thread_pending_long_get(void)
* @brief Get number of pending thread jobs
* @return Number of pending threads running jobs
* This returns the number of threads currently running jobs through the
* ecore_thread_run and ecore_long_run api calls combined.
* ecore_thread_run and ecore_thread_feedback_run api calls combined.
*/
EAPI int
ecore_thread_pending_total_get(void)
@ -842,7 +842,7 @@ ecore_thread_pending_total_get(void)
int ret;
#ifdef EFL_HAVE_PTHREAD
pthread_mutex_lock(&_ecore_pending_job_threads_mutex);
ret = eina_list_count(_ecore_pending_job_threads) + eina_list_count(_ecore_pending_job_threads_long);
ret = eina_list_count(_ecore_pending_job_threads) + eina_list_count(_ecore_pending_job_threads_feedback);
pthread_mutex_unlock(&_ecore_pending_job_threads_mutex);
return ret;
#else
@ -894,7 +894,7 @@ ecore_thread_max_reset(void)
* @return The number of available threads
* This returns the number of threads slots that ecore has currently available.
* Assuming that you haven't changed the max number of threads with @ref ecore_thread_max_set
* this should be equal to (num_cpus - (active_running + active_long_running))
* this should be equal to (num_cpus - (active_running + active_feedback_running))
*/
EAPI int
ecore_thread_available_get(void)

View File

@ -68,7 +68,7 @@ _eio_file_heavy(Ecore_Thread *thread, void *data)
filter = async->filter_cb((void*) async->ls.common.data, file);
}
if (filter) ecore_thread_notify(thread, file);
if (filter) ecore_thread_feedback(thread, file);
else eina_stringshare_del(file);
if (ecore_thread_check(thread))
@ -121,7 +121,7 @@ _eio_file_direct_heavy(Ecore_Thread *thread, void *data)
if (!send) continue;
memcpy(send, info, sizeof (Eina_File_Direct_Info));
ecore_thread_notify(thread, send);
ecore_thread_feedback(thread, send);
}
if (ecore_thread_check(thread))
@ -177,7 +177,7 @@ _eio_file_error(void *data)
* @param error_cb Callback called from the main loop when the directory could not be opened or listing content has been canceled.
* @return A reference to the IO operation.
*
* eio_file_ls run eina_file_ls in a separated thread using ecore_long_run. This prevent
* eio_file_ls run eina_file_ls in a separated thread using ecore_thread_feedback_run. This prevent
* any lock in your apps.
*/
EAPI Eio_File *
@ -223,7 +223,7 @@ eio_file_ls(const char *dir,
* @return A reference to the IO operation.
*
* eio_file_direct_ls run eina_file_direct_ls in a separated thread using
* ecore_long_run. This prevent any lock in your apps.
* ecore_thread_feedback_run. This prevent any lock in your apps.
*/
EAPI Eio_File *
eio_file_direct_ls(const char *dir,

View File

@ -61,12 +61,12 @@ eio_long_file_set(Eio_File *common,
common->error = 0;
/* Be aware that ecore_thread_run could call cancel_cb if something goes wrong. */
thread = ecore_long_run(heavy_cb,
notify_cb,
end_cb,
cancel_cb,
common,
EINA_TRUE);
thread = ecore_thread_feedback_run(heavy_cb,
notify_cb,
end_cb,
cancel_cb,
common,
EINA_TRUE);
if (!thread) return EINA_FALSE;
common->thread = thread;