From: Enlightenment S. <no-...@en...> - 2010-05-19 09:16:44
|
Log: added functions for changing/getting a poller's poll interval: ecore_poller_poller_interval_(set|get) along with dox for them surprisingly enough they seem to work! Author: discomfitor Date: 2010-05-19 02:16:37 -0700 (Wed, 19 May 2010) New Revision: 49002 Modified: trunk/ecore/src/lib/ecore/Ecore.h trunk/ecore/src/lib/ecore/ecore_poll.c Modified: trunk/ecore/src/lib/ecore/Ecore.h =================================================================== --- trunk/ecore/src/lib/ecore/Ecore.h 2010-05-19 09:07:37 UTC (rev 49001) +++ trunk/ecore/src/lib/ecore/Ecore.h 2010-05-19 09:16:37 UTC (rev 49002) @@ -345,6 +345,8 @@ EAPI void ecore_poller_poll_interval_set(Ecore_Poller_Type type, double poll_time); EAPI double ecore_poller_poll_interval_get(Ecore_Poller_Type type); + EAPI Eina_Bool ecore_poller_poller_interval_set(Ecore_Poller *poller, int interval); + EAPI int ecore_poller_poller_interval_get(Ecore_Poller *poller); EAPI Ecore_Poller *ecore_poller_add(Ecore_Poller_Type type, int interval, int (*func) (void *data), const void *data); EAPI void *ecore_poller_del(Ecore_Poller *poller); Modified: trunk/ecore/src/lib/ecore/ecore_poll.c =================================================================== --- trunk/ecore/src/lib/ecore/ecore_poll.c 2010-05-19 09:07:37 UTC (rev 49001) +++ trunk/ecore/src/lib/ecore/ecore_poll.c 2010-05-19 09:16:37 UTC (rev 49002) @@ -316,6 +316,82 @@ } /** + * Changes the polling interval rate of @p poller. + * + * @param poller The Ecore_Poller to change the interval of + * @param interval The tick interval to set; must be a power of 2 but <= 32768 + * @return Returns true on success, false on failure + * + * This allows the changing of a poller's polling interval. It is useful when you want to alter + * a poll rate without deleting and re-creating a poller. + * @ingroup Ecore_Poller_Group + */ +EAPI Eina_Bool +ecore_poller_poller_interval_set(Ecore_Poller *poller, int interval) +{ + int ibit; + + if (!ECORE_MAGIC_CHECK(poller, ECORE_MAGIC_POLLER)) + { + ECORE_MAGIC_FAIL(poller, ECORE_MAGIC_POLLER, + "ecore_poller_poller_interval_set"); + return 0; + } + + /* interval MUST be a power of 2, so enforce it */ + if (interval < 1) interval = 1; + ibit = -1; + while (interval != 0) + { + ibit++; + interval >>= 1; + } + /* only allow up to 32768 - i.e. ibit == 15, so limit it */ + if (ibit > 15) ibit = 15; + /* if interval specified is the same as interval set, return true without wasting time */ + if (poller->ibit == ibit) + return 1; + pollers[poller->ibit] = (Ecore_Poller *) eina_inlist_remove(EINA_INLIST_GET(pollers[poller->ibit]), EINA_INLIST_GET(poller)); + poller->ibit = ibit; + pollers[poller->ibit] = (Ecore_Poller *) eina_inlist_prepend(EINA_INLIST_GET(pollers[poller->ibit]), EINA_INLIST_GET(poller)); + if (poller_walking) + just_added_poller++; + else + _ecore_poller_next_tick_eval(); + return 1; +} + +/** + * Gets the polling interval rate of @p poller. + * + * @param poller The Ecore_Poller to change the interval of + * @return Returns the interval, in ticks, that @p poller polls at + * + * This returns a poller's polling interval, or 0 on error. + * @ingroup Ecore_Poller_Group + */ +EAPI int +ecore_poller_poller_interval_get(Ecore_Poller *poller) +{ + int ibit, interval = 1; + + if (!ECORE_MAGIC_CHECK(poller, ECORE_MAGIC_POLLER)) + { + ECORE_MAGIC_FAIL(poller, ECORE_MAGIC_POLLER, + "ecore_poller_poller_interval_get"); + return 0; + } + + ibit = poller->ibit; + while (ibit != 0) + { + ibit--; + interval <<= 1; + } + return interval; +} + +/** * Delete the specified poller from the timer list. * @param poller The poller to delete. * @return The data pointer set for the timer when @ref ecore_poller_add was @@ -332,18 +408,18 @@ if (!ECORE_MAGIC_CHECK(poller, ECORE_MAGIC_POLLER)) { - ECORE_MAGIC_FAIL(poller, ECORE_MAGIC_POLLER, - "ecore_poller_del"); - return NULL; + ECORE_MAGIC_FAIL(poller, ECORE_MAGIC_POLLER, + "ecore_poller_del"); + return NULL; } /* we are walking the poller list - a bad idea to remove from it while * walking it, so just flag it as delete_me and come back to it after * the loop has finished */ if (poller_walking > 0) { - poller_delete_count++; - poller->delete_me = 1; - return poller->data; + poller_delete_count++; + poller->delete_me = 1; + return poller->data; } /* not in loop so safe - delete immediately */ data = poller->data; |
From: Enlightenment S. <no-...@en...> - 2010-07-20 05:25:11
|
Log: note: '/*' is not how you begin a doxygen code block Author: discomfitor Date: 2010-07-19 22:25:02 -0700 (Mon, 19 Jul 2010) New Revision: 50372 Modified: trunk/ecore/src/lib/ecore/ecore_thread.c Modified: trunk/ecore/src/lib/ecore/ecore_thread.c =================================================================== --- trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-19 20:21:57 UTC (rev 50371) +++ trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-20 05:25:02 UTC (rev 50372) @@ -327,7 +327,7 @@ #endif } -/* +/** * @brief Run some blocking code in a parrallel thread to avoid locking the main loop. * @param func_blocking The function that should run in another thread. * @param func_end The function that will be called in the main loop if the thread terminate correctly. @@ -421,7 +421,7 @@ #endif } -/* +/** * @brief Cancel a running thread. * @param thread The thread to cancel. * @return Will return EINA_TRUE if the thread has been cancelled, @@ -469,7 +469,7 @@ #endif } -/* +/** * @brief Tell if a thread was canceled or not. * @param thread The thread to test. * @return EINA_TRUE if the thread is cancelled, @@ -486,7 +486,7 @@ return worker->cancel; } -/* +/** * @brief Run some heavy code in a parrallel thread to avoid locking the main loop. * @param func_heavy The function that should run in another thread. * @param func_notify The function that will receive the data send by func_heavy in the main loop. @@ -618,7 +618,7 @@ #endif } -/* +/** * @brief Send data to main loop from worker thread. * @param thread The current Ecore_Thread context to send data from * @param data Data to be transmitted to the main loop |
From: Enlightenment S. <no-...@en...> - 2010-07-20 09:40:24
|
Log: +ecore_thread_active_get, ecore_thread_pending_get, ecore_thread_pending_long_get to retrieve number of threads present with given status Author: discomfitor Date: 2010-07-20 02:40:18 -0700 (Tue, 20 Jul 2010) New Revision: 50375 Modified: trunk/ecore/src/lib/ecore/Ecore.h trunk/ecore/src/lib/ecore/ecore_thread.c Modified: trunk/ecore/src/lib/ecore/Ecore.h =================================================================== --- trunk/ecore/src/lib/ecore/Ecore.h 2010-07-20 09:32:28 UTC (rev 50374) +++ trunk/ecore/src/lib/ecore/Ecore.h 2010-07-20 09:40:18 UTC (rev 50375) @@ -350,7 +350,11 @@ 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 int ecore_thread_active_get(void); + EAPI int ecore_thread_pending_get(void); + EAPI int ecore_thread_pending_long_get(void); + EAPI double ecore_time_get(void); EAPI double ecore_loop_time_get(void); Modified: trunk/ecore/src/lib/ecore/ecore_thread.c =================================================================== --- trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-20 09:32:28 UTC (rev 50374) +++ trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-20 09:40:18 UTC (rev 50375) @@ -651,3 +651,50 @@ #endif } +/** + * @brief Get number of active thread jobs + * @return Number of active threads running jobs + * This returns the number of threads currently running jobs through the + * ecore_thread api. + */ +EAPI int +ecore_thread_active_get(void) +{ +#ifdef EFL_HAVE_PTHREAD + return eina_list_count(_ecore_thread); +#else + return 0; +#endif +} + +/** + * @brief Get number of pending (short) thread jobs + * @return Number of pending threads running "short" jobs + * This returns the number of threads currently running jobs through the + * ecore_thread_run api call. + */ +EAPI int +ecore_thread_pending_get(void) +{ +#ifdef EFL_HAVE_PTHREAD + return eina_list_count(_ecore_thread_data); +#else + return 0; +#endif +} + +/** + * @brief Get number of pending long thread jobs + * @return Number of pending threads running "long" jobs + * This returns the number of threads currently running jobs through the + * ecore_long_run api call. + */ +EAPI int +ecore_thread_pending_long_get(void) +{ +#ifdef EFL_HAVE_PTHREAD + return eina_list_count(_ecore_long_thread_data); +#else + return 0; +#endif +} |
From: Enlightenment S. <no-...@en...> - 2010-07-20 09:40:59
|
Log: some variable renames to make this easier to understand Author: discomfitor Date: 2010-07-20 02:40:53 -0700 (Tue, 20 Jul 2010) New Revision: 50376 Modified: trunk/ecore/src/lib/ecore/ecore_thread.c Modified: trunk/ecore/src/lib/ecore/ecore_thread.c =================================================================== --- trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-20 09:40:18 UTC (rev 50375) +++ trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-20 09:40:53 UTC (rev 50376) @@ -59,9 +59,9 @@ #ifdef EFL_HAVE_PTHREAD static int _ecore_thread_count = 0; -static Eina_List *_ecore_thread = NULL; -static Eina_List *_ecore_thread_data = NULL; -static Eina_List *_ecore_long_thread_data = NULL; +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 Ecore_Event_Handler *del_handler = NULL; static pthread_mutex_t _mutex = PTHREAD_MUTEX_INITIALIZER; @@ -89,7 +89,7 @@ if (pthread_join(pth->thread, (void **) &p) != 0) return ; - _ecore_thread = eina_list_remove(_ecore_thread, pth); + _ecore_active_job_threads = eina_list_remove(_ecore_active_job_threads, pth); ecore_event_add(ECORE_THREAD_PIPE_DEL, pth->p, _ecore_thread_pipe_free, NULL); } @@ -137,18 +137,18 @@ { Ecore_Pthread_Worker *work; - while (_ecore_thread_data) + while (_ecore_pending_job_threads) { pthread_mutex_lock(&_mutex); - if (!_ecore_thread_data) + if (!_ecore_pending_job_threads) { pthread_mutex_unlock(&_mutex); break; } - work = eina_list_data_get(_ecore_thread_data); - _ecore_thread_data = eina_list_remove_list(_ecore_thread_data, _ecore_thread_data); + work = eina_list_data_get(_ecore_pending_job_threads); + _ecore_pending_job_threads = eina_list_remove_list(_ecore_pending_job_threads, _ecore_pending_job_threads); pthread_mutex_unlock(&_mutex); @@ -163,18 +163,18 @@ { Ecore_Pthread_Worker *work; - while (_ecore_long_thread_data) + while (_ecore_pending_job_threads_long) { pthread_mutex_lock(&_mutex); - if (!_ecore_long_thread_data) + if (!_ecore_pending_job_threads_long) { pthread_mutex_unlock(&_mutex); break; } - work = eina_list_data_get(_ecore_long_thread_data); - _ecore_long_thread_data = eina_list_remove_list(_ecore_long_thread_data, _ecore_long_thread_data); + 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); pthread_mutex_unlock(&_mutex); @@ -242,18 +242,18 @@ pthread_mutex_unlock(&_mutex); on_error: - if (_ecore_thread_data) _ecore_short_job(pth->p); - if (_ecore_long_thread_data) _ecore_long_job(pth->p, pth->thread); + if (_ecore_pending_job_threads) _ecore_short_job(pth->p); + if (_ecore_pending_job_threads_long) _ecore_long_job(pth->p, pth->thread); /* FIXME: Check if there is long running task todo, and switch to long run handler. */ pthread_mutex_lock(&_mutex); - if (_ecore_thread_data) + if (_ecore_pending_job_threads) { pthread_mutex_unlock(&_mutex); goto on_error; } - if (_ecore_long_thread_data) + if (_ecore_pending_job_threads_long) { pthread_mutex_unlock(&_mutex); goto on_error; @@ -303,7 +303,7 @@ pthread_mutex_lock(&_mutex); - EINA_LIST_FREE(_ecore_thread_data, work) + EINA_LIST_FREE(_ecore_pending_job_threads, work) { if (work->func_cancel) work->func_cancel((void *)work->data); @@ -312,7 +312,7 @@ pthread_mutex_unlock(&_mutex); - EINA_LIST_FREE(_ecore_thread, pth) + EINA_LIST_FREE(_ecore_active_job_threads, pth) { Ecore_Pipe *p; @@ -374,7 +374,7 @@ work->data = data; pthread_mutex_lock(&_mutex); - _ecore_thread_data = eina_list_append(_ecore_thread_data, work); + _ecore_pending_job_threads = eina_list_append(_ecore_pending_job_threads, work); if (_ecore_thread_count == _ecore_thread_count_max) { @@ -445,10 +445,10 @@ pthread_mutex_lock(&_mutex); - EINA_LIST_FOREACH(_ecore_thread_data, l, work) + EINA_LIST_FOREACH(_ecore_pending_job_threads, l, work) if ((void *) work == (void *) thread) { - _ecore_thread_data = eina_list_remove_list(_ecore_thread_data, l); + _ecore_pending_job_threads = eina_list_remove_list(_ecore_pending_job_threads, l); pthread_mutex_unlock(&_mutex); @@ -551,7 +551,7 @@ } pthread_mutex_lock(&_mutex); - _ecore_long_thread_data = eina_list_append(_ecore_long_thread_data, worker); + _ecore_pending_job_threads_long = eina_list_append(_ecore_pending_job_threads_long, worker); if (_ecore_thread_count == _ecore_thread_count_max) { @@ -661,7 +661,7 @@ ecore_thread_active_get(void) { #ifdef EFL_HAVE_PTHREAD - return eina_list_count(_ecore_thread); + return eina_list_count(_ecore_active_job_threads); #else return 0; #endif @@ -677,7 +677,7 @@ ecore_thread_pending_get(void) { #ifdef EFL_HAVE_PTHREAD - return eina_list_count(_ecore_thread_data); + return eina_list_count(_ecore_pending_job_threads); #else return 0; #endif @@ -693,7 +693,7 @@ ecore_thread_pending_long_get(void) { #ifdef EFL_HAVE_PTHREAD - return eina_list_count(_ecore_long_thread_data); + return eina_list_count(_ecore_pending_job_threads_long); #else return 0; #endif |
From: Enlightenment S. <no-...@en...> - 2010-07-21 01:04:35
|
Log: +ecore_thread_max_{set,get} to return/set the max number of threads ecore will attempt to run simultaneously Author: discomfitor Date: 2010-07-20 18:04:28 -0700 (Tue, 20 Jul 2010) New Revision: 50397 Modified: trunk/ecore/src/lib/ecore/Ecore.h trunk/ecore/src/lib/ecore/ecore_thread.c Modified: trunk/ecore/src/lib/ecore/Ecore.h =================================================================== --- trunk/ecore/src/lib/ecore/Ecore.h 2010-07-20 22:09:35 UTC (rev 50396) +++ trunk/ecore/src/lib/ecore/Ecore.h 2010-07-21 01:04:28 UTC (rev 50397) @@ -353,6 +353,8 @@ 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_max_get(void); + EAPI void ecore_thread_max_set(int num); EAPI double ecore_time_get(void); Modified: trunk/ecore/src/lib/ecore/ecore_thread.c =================================================================== --- trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-20 22:09:35 UTC (rev 50396) +++ trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-21 01:04:28 UTC (rev 50397) @@ -326,6 +326,10 @@ del_handler = NULL; #endif } +/** + * @defgroup Ecore_Thread Ecore Thread Functions + * These functions allow for ecore-managed threads which integrate with ecore's main loop. + */ /** * @brief Run some blocking code in a parrallel thread to avoid locking the main loop. @@ -698,3 +702,32 @@ return 0; #endif } + + +/** + * @brief Get the max number of threads that can run simultaneously + * @return Max number of threads ecore will run + * This returns the total number of threads that ecore will attempt to run + * simultaneously. + */ +EAPI int +ecore_thread_max_get(void) +{ + return _ecore_thread_count_max; +} + +/** + * @brief Set the max number of threads that can run simultaneously + * @param num The new maximum + * This sets the maximum number of threads that ecore will try to run + * simultaneously. This number cannot be < 1 or >= 2x the number of active cpus. + */ +EAPI void +ecore_thread_max_set(int num) +{ + if (num < 1) return; + /* avoid doing something hilarious by blocking dumb users */ + if (num >= (2 * eina_cpu_count())) return; + + _ecore_thread_count_max = num; +} |
From: Enlightenment S. <no-...@en...> - 2010-07-21 02:12:17
|
Log: +ecore_thread_max_reset, ecore_thread_avail_get for more thread functionality, also fix formatting Author: discomfitor Date: 2010-07-20 19:12:10 -0700 (Tue, 20 Jul 2010) New Revision: 50399 Modified: trunk/ecore/src/lib/ecore/Ecore.h trunk/ecore/src/lib/ecore/ecore_thread.c Modified: trunk/ecore/src/lib/ecore/Ecore.h =================================================================== --- trunk/ecore/src/lib/ecore/Ecore.h 2010-07-21 01:37:07 UTC (rev 50398) +++ trunk/ecore/src/lib/ecore/Ecore.h 2010-07-21 02:12:10 UTC (rev 50399) @@ -355,6 +355,8 @@ EAPI int ecore_thread_pending_long_get(void); EAPI int ecore_thread_max_get(void); EAPI void ecore_thread_max_set(int num); + EAPI void ecore_thread_max_reset(void); + EAPI int ecore_thread_avail_get(void); EAPI double ecore_time_get(void); Modified: trunk/ecore/src/lib/ecore/ecore_thread.c =================================================================== --- trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-21 01:37:07 UTC (rev 50398) +++ trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-21 02:12:10 UTC (rev 50399) @@ -105,13 +105,13 @@ if (work->cancel) { - if (work->func_cancel) - work->func_cancel((void *) work->data); + if (work->func_cancel) + work->func_cancel((void *) work->data); } else { - if (work->func_end) - work->func_end((void *) work->data); + if (work->func_end) + work->func_end((void *) work->data); } if (work->long_run) ecore_pipe_del(work->u.long_run.notify); @@ -139,22 +139,22 @@ while (_ecore_pending_job_threads) { - pthread_mutex_lock(&_mutex); + pthread_mutex_lock(&_mutex); - if (!_ecore_pending_job_threads) - { - pthread_mutex_unlock(&_mutex); - break; - } + if (!_ecore_pending_job_threads) + { + pthread_mutex_unlock(&_mutex); + break; + } - work = eina_list_data_get(_ecore_pending_job_threads); - _ecore_pending_job_threads = eina_list_remove_list(_ecore_pending_job_threads, _ecore_pending_job_threads); + work = eina_list_data_get(_ecore_pending_job_threads); + _ecore_pending_job_threads = eina_list_remove_list(_ecore_pending_job_threads, _ecore_pending_job_threads); - pthread_mutex_unlock(&_mutex); + pthread_mutex_unlock(&_mutex); - work->u.short_run.func_blocking((void *) work->data); + work->u.short_run.func_blocking((void *) work->data); - ecore_pipe_write(end_pipe, &work, sizeof (Ecore_Pthread_Worker *)); + ecore_pipe_write(end_pipe, &work, sizeof (Ecore_Pthread_Worker *)); } } @@ -165,23 +165,23 @@ while (_ecore_pending_job_threads_long) { - pthread_mutex_lock(&_mutex); + pthread_mutex_lock(&_mutex); - if (!_ecore_pending_job_threads_long) - { - pthread_mutex_unlock(&_mutex); - break; - } + if (!_ecore_pending_job_threads_long) + { + pthread_mutex_unlock(&_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_long); + _ecore_pending_job_threads_long = eina_list_remove_list(_ecore_pending_job_threads_long, _ecore_pending_job_threads_long); - pthread_mutex_unlock(&_mutex); + pthread_mutex_unlock(&_mutex); - work->u.long_run.self = thread; - work->u.long_run.func_heavy((Ecore_Thread *) work, (void *) work->data); + work->u.long_run.self = thread; + work->u.long_run.func_heavy((Ecore_Thread *) work, (void *) work->data); - ecore_pipe_write(end_pipe, &work, sizeof (Ecore_Pthread_Worker *)); + ecore_pipe_write(end_pipe, &work, sizeof (Ecore_Pthread_Worker *)); } } @@ -199,8 +199,8 @@ pth->p = ecore_pipe_add(_ecore_thread_handler, NULL); if (!pth->p) { - free(pth); - return NULL; + free(pth); + return NULL; } pth->thread = pthread_self(); @@ -212,9 +212,9 @@ work = malloc(sizeof (Ecore_Pthread_Worker)); if (!work) { - ecore_pipe_del(pth->p); - free(pth); - return NULL; + ecore_pipe_del(pth->p); + free(pth); + return NULL; } work->data = pth; @@ -250,13 +250,13 @@ pthread_mutex_lock(&_mutex); if (_ecore_pending_job_threads) { - pthread_mutex_unlock(&_mutex); - goto on_error; + pthread_mutex_unlock(&_mutex); + goto on_error; } if (_ecore_pending_job_threads_long) { - pthread_mutex_unlock(&_mutex); - goto on_error; + pthread_mutex_unlock(&_mutex); + goto on_error; } _ecore_thread_count--; @@ -305,21 +305,21 @@ EINA_LIST_FREE(_ecore_pending_job_threads, work) { - if (work->func_cancel) - work->func_cancel((void *)work->data); - free(work); + if (work->func_cancel) + work->func_cancel((void *)work->data); + free(work); } pthread_mutex_unlock(&_mutex); EINA_LIST_FREE(_ecore_active_job_threads, pth) { - Ecore_Pipe *p; + Ecore_Pipe *p; - pthread_cancel(pth->thread); - pthread_join(pth->thread, (void **) &p); + pthread_cancel(pth->thread); + pthread_join(pth->thread, (void **) &p); - ecore_pipe_del(pth->p); + ecore_pipe_del(pth->p); } ecore_event_handler_del(del_handler); @@ -367,7 +367,7 @@ if (!work) { func_cancel((void *) data); - return NULL; + return NULL; } work->u.short_run.func_blocking = func_blocking; @@ -382,8 +382,8 @@ if (_ecore_thread_count == _ecore_thread_count_max) { - pthread_mutex_unlock(&_mutex); - return (Ecore_Thread *) work; + pthread_mutex_unlock(&_mutex); + return (Ecore_Thread *) work; } pthread_mutex_unlock(&_mutex); @@ -401,16 +401,16 @@ on_error: if (pth) { - if (pth->p) ecore_pipe_del(pth->p); - free(pth); + if (pth->p) ecore_pipe_del(pth->p); + free(pth); } if (_ecore_thread_count == 0) { - if (work->func_cancel) - work->func_cancel((void *) work->data); - free(work); - work = NULL; + if (work->func_cancel) + work->func_cancel((void *) work->data); + free(work); + work = NULL; } return (Ecore_Thread *) work; #else @@ -452,15 +452,15 @@ EINA_LIST_FOREACH(_ecore_pending_job_threads, l, work) if ((void *) work == (void *) thread) { - _ecore_pending_job_threads = eina_list_remove_list(_ecore_pending_job_threads, l); + _ecore_pending_job_threads = eina_list_remove_list(_ecore_pending_job_threads, l); - pthread_mutex_unlock(&_mutex); + pthread_mutex_unlock(&_mutex); - if (work->func_cancel) - work->func_cancel((void *) work->data); - free(work); + if (work->func_cancel) + work->func_cancel((void *) work->data); + free(work); - return EINA_TRUE; + return EINA_TRUE; } pthread_mutex_unlock(&_mutex); @@ -548,10 +548,10 @@ if (!try_no_queue) { - pthread_t t; + pthread_t t; - if (pthread_create(&t, NULL, (void *) _ecore_direct_worker, worker) == 0) - return (Ecore_Thread *) worker; + if (pthread_create(&t, NULL, (void *) _ecore_direct_worker, worker) == 0) + return (Ecore_Thread *) worker; } pthread_mutex_lock(&_mutex); @@ -559,8 +559,8 @@ if (_ecore_thread_count == _ecore_thread_count_max) { - pthread_mutex_unlock(&_mutex); - return (Ecore_Thread *) worker; + pthread_mutex_unlock(&_mutex); + return (Ecore_Thread *) worker; } pthread_mutex_unlock(&_mutex); @@ -578,20 +578,20 @@ on_error: if (pth) { - if (pth->p) ecore_pipe_del(pth->p); - free(pth); + if (pth->p) ecore_pipe_del(pth->p); + free(pth); } if (_ecore_thread_count == 0) { - if (func_cancel) func_cancel((void *) data); + if (func_cancel) func_cancel((void *) data); - if (worker) - { - ecore_pipe_del(worker->u.long_run.notify); - free(worker); - worker = NULL; - } + if (worker) + { + ecore_pipe_del(worker->u.long_run.notify); + free(worker); + worker = NULL; + } } return (Ecore_Thread *) worker; @@ -731,3 +731,31 @@ _ecore_thread_count_max = num; } + +/** + * @brief Reset the max number of threads that can run simultaneously + * This resets the maximum number of threads that ecore will try to run + * simultaneously to the number of active cpus. + */ +EAPI void +ecore_thread_max_reset(void) +{ + _ecore_thread_count_max = eina_cpu_count(); +} + +/** + * @brief Get the number of threads which are available to be used + * @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)) + */ +EAPI int +ecore_thread_avail_get(void) +{ +#ifdef EFL_HAVE_PTHREAD + return _ecore_thread_count_max - (eina_list_count(_ecore_pending_job_threads_long) + eina_list_count(_ecore_pending_job_threads)); +#else + return 0; +#endif +} |
From: Enlightenment S. <no-...@en...> - 2010-07-21 04:03:47
|
Log: +ecore_thread_total_get to return total number of pending jobs Author: discomfitor Date: 2010-07-20 21:03:40 -0700 (Tue, 20 Jul 2010) New Revision: 50405 Modified: trunk/ecore/src/lib/ecore/Ecore.h trunk/ecore/src/lib/ecore/ecore_thread.c Modified: trunk/ecore/src/lib/ecore/Ecore.h =================================================================== --- trunk/ecore/src/lib/ecore/Ecore.h 2010-07-21 03:59:37 UTC (rev 50404) +++ trunk/ecore/src/lib/ecore/Ecore.h 2010-07-21 04:03:40 UTC (rev 50405) @@ -353,6 +353,7 @@ 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_total_get(void); EAPI int ecore_thread_max_get(void); EAPI void ecore_thread_max_set(int num); EAPI void ecore_thread_max_reset(void); Modified: trunk/ecore/src/lib/ecore/ecore_thread.c =================================================================== --- trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-21 03:59:37 UTC (rev 50404) +++ trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-21 04:03:40 UTC (rev 50405) @@ -703,6 +703,21 @@ #endif } +/** + * @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. + */ +EAPI int +ecore_thread_pending_total_get(void) +{ +#ifdef EFL_HAVE_PTHREAD + return eina_list_count(_ecore_pending_job_threads) + eina_list_count(_ecore_pending_job_threads_long); +#else + return 0; +#endif +} /** * @brief Get the max number of threads that can run simultaneously |
From: Enlightenment S. <no-...@en...> - 2010-07-21 04:27:04
|
Log: man I fail at formatting Author: discomfitor Date: 2010-07-20 21:26:57 -0700 (Tue, 20 Jul 2010) New Revision: 50406 Modified: trunk/ecore/src/lib/ecore/ecore_thread.c Modified: trunk/ecore/src/lib/ecore/ecore_thread.c =================================================================== --- trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-21 04:03:40 UTC (rev 50405) +++ trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-21 04:26:57 UTC (rev 50406) @@ -20,16 +20,16 @@ { union { struct { - void (*func_blocking)(void *data); + void (*func_blocking)(void *data); } short_run; struct { - void (*func_heavy)(Ecore_Thread *thread, void *data); - void (*func_notify)(Ecore_Thread *thread, void *msg_data, void *data); + void (*func_heavy)(Ecore_Thread *thread, void *data); + void (*func_notify)(Ecore_Thread *thread, void *msg_data, void *data); - Ecore_Pipe *notify; + Ecore_Pipe *notify; #ifdef EFL_HAVE_PTHREAD - pthread_t self; + pthread_t self; #endif } long_run; } u; @@ -105,13 +105,13 @@ if (work->cancel) { - if (work->func_cancel) - work->func_cancel((void *) work->data); + if (work->func_cancel) + work->func_cancel((void *) work->data); } else { - if (work->func_end) - work->func_end((void *) work->data); + if (work->func_end) + work->func_end((void *) work->data); } if (work->long_run) ecore_pipe_del(work->u.long_run.notify); @@ -139,22 +139,22 @@ while (_ecore_pending_job_threads) { - pthread_mutex_lock(&_mutex); + pthread_mutex_lock(&_mutex); - if (!_ecore_pending_job_threads) - { - pthread_mutex_unlock(&_mutex); - break; - } + if (!_ecore_pending_job_threads) + { + pthread_mutex_unlock(&_mutex); + break; + } - work = eina_list_data_get(_ecore_pending_job_threads); - _ecore_pending_job_threads = eina_list_remove_list(_ecore_pending_job_threads, _ecore_pending_job_threads); + work = eina_list_data_get(_ecore_pending_job_threads); + _ecore_pending_job_threads = eina_list_remove_list(_ecore_pending_job_threads, _ecore_pending_job_threads); - pthread_mutex_unlock(&_mutex); + pthread_mutex_unlock(&_mutex); - work->u.short_run.func_blocking((void *) work->data); + work->u.short_run.func_blocking((void *) work->data); - ecore_pipe_write(end_pipe, &work, sizeof (Ecore_Pthread_Worker *)); + ecore_pipe_write(end_pipe, &work, sizeof (Ecore_Pthread_Worker *)); } } @@ -165,23 +165,23 @@ while (_ecore_pending_job_threads_long) { - pthread_mutex_lock(&_mutex); + pthread_mutex_lock(&_mutex); - if (!_ecore_pending_job_threads_long) - { - pthread_mutex_unlock(&_mutex); - break; - } + if (!_ecore_pending_job_threads_long) + { + pthread_mutex_unlock(&_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_long); + _ecore_pending_job_threads_long = eina_list_remove_list(_ecore_pending_job_threads_long, _ecore_pending_job_threads_long); - pthread_mutex_unlock(&_mutex); + pthread_mutex_unlock(&_mutex); - work->u.long_run.self = thread; - work->u.long_run.func_heavy((Ecore_Thread *) work, (void *) work->data); + work->u.long_run.self = thread; + work->u.long_run.func_heavy((Ecore_Thread *) work, (void *) work->data); - ecore_pipe_write(end_pipe, &work, sizeof (Ecore_Pthread_Worker *)); + ecore_pipe_write(end_pipe, &work, sizeof (Ecore_Pthread_Worker *)); } } @@ -199,8 +199,8 @@ pth->p = ecore_pipe_add(_ecore_thread_handler, NULL); if (!pth->p) { - free(pth); - return NULL; + free(pth); + return NULL; } pth->thread = pthread_self(); @@ -212,9 +212,9 @@ work = malloc(sizeof (Ecore_Pthread_Worker)); if (!work) { - ecore_pipe_del(pth->p); - free(pth); - return NULL; + ecore_pipe_del(pth->p); + free(pth); + return NULL; } work->data = pth; @@ -250,13 +250,13 @@ pthread_mutex_lock(&_mutex); if (_ecore_pending_job_threads) { - pthread_mutex_unlock(&_mutex); - goto on_error; + pthread_mutex_unlock(&_mutex); + goto on_error; } if (_ecore_pending_job_threads_long) { - pthread_mutex_unlock(&_mutex); - goto on_error; + pthread_mutex_unlock(&_mutex); + goto on_error; } _ecore_thread_count--; @@ -305,21 +305,21 @@ EINA_LIST_FREE(_ecore_pending_job_threads, work) { - if (work->func_cancel) - work->func_cancel((void *)work->data); - free(work); + if (work->func_cancel) + work->func_cancel((void *)work->data); + free(work); } pthread_mutex_unlock(&_mutex); EINA_LIST_FREE(_ecore_active_job_threads, pth) { - Ecore_Pipe *p; + Ecore_Pipe *p; - pthread_cancel(pth->thread); - pthread_join(pth->thread, (void **) &p); + pthread_cancel(pth->thread); + pthread_join(pth->thread, (void **) &p); - ecore_pipe_del(pth->p); + ecore_pipe_del(pth->p); } ecore_event_handler_del(del_handler); @@ -329,7 +329,7 @@ /** * @defgroup Ecore_Thread Ecore Thread Functions * These functions allow for ecore-managed threads which integrate with ecore's main loop. - */ + */ /** * @brief Run some blocking code in a parrallel thread to avoid locking the main loop. @@ -353,9 +353,9 @@ */ EAPI Ecore_Thread * ecore_thread_run(void (*func_blocking)(void *data), - void (*func_end)(void *data), - void (*func_cancel)(void *data), - const void *data) + void (*func_end)(void *data), + void (*func_cancel)(void *data), + const void *data) { #ifdef EFL_HAVE_PTHREAD Ecore_Pthread_Worker *work; @@ -367,7 +367,7 @@ if (!work) { func_cancel((void *) data); - return NULL; + return NULL; } work->u.short_run.func_blocking = func_blocking; @@ -382,8 +382,8 @@ if (_ecore_thread_count == _ecore_thread_count_max) { - pthread_mutex_unlock(&_mutex); - return (Ecore_Thread *) work; + pthread_mutex_unlock(&_mutex); + return (Ecore_Thread *) work; } pthread_mutex_unlock(&_mutex); @@ -401,16 +401,16 @@ on_error: if (pth) { - if (pth->p) ecore_pipe_del(pth->p); - free(pth); + if (pth->p) ecore_pipe_del(pth->p); + free(pth); } if (_ecore_thread_count == 0) { - if (work->func_cancel) - work->func_cancel((void *) work->data); - free(work); - work = NULL; + if (work->func_cancel) + work->func_cancel((void *) work->data); + free(work); + work = NULL; } return (Ecore_Thread *) work; #else @@ -452,15 +452,15 @@ EINA_LIST_FOREACH(_ecore_pending_job_threads, l, work) if ((void *) work == (void *) thread) { - _ecore_pending_job_threads = eina_list_remove_list(_ecore_pending_job_threads, l); + _ecore_pending_job_threads = eina_list_remove_list(_ecore_pending_job_threads, l); - pthread_mutex_unlock(&_mutex); + pthread_mutex_unlock(&_mutex); - if (work->func_cancel) - work->func_cancel((void *) work->data); - free(work); + if (work->func_cancel) + work->func_cancel((void *) work->data); + free(work); - return EINA_TRUE; + return EINA_TRUE; } pthread_mutex_unlock(&_mutex); @@ -520,11 +520,11 @@ */ EAPI Ecore_Thread * ecore_long_run(void (*func_heavy)(Ecore_Thread *thread, void *data), - void (*func_notify)(Ecore_Thread *thread, void *msg_data, void *data), - void (*func_end)(void *data), - void (*func_cancel)(void *data), - const void *data, - Eina_Bool try_no_queue) + void (*func_notify)(Ecore_Thread *thread, void *msg_data, void *data), + void (*func_end)(void *data), + void (*func_cancel)(void *data), + const void *data, + Eina_Bool try_no_queue) { #ifdef EFL_HAVE_PTHREAD @@ -548,10 +548,10 @@ if (!try_no_queue) { - pthread_t t; + pthread_t t; - if (pthread_create(&t, NULL, (void *) _ecore_direct_worker, worker) == 0) - return (Ecore_Thread *) worker; + if (pthread_create(&t, NULL, (void *) _ecore_direct_worker, worker) == 0) + return (Ecore_Thread *) worker; } pthread_mutex_lock(&_mutex); @@ -559,8 +559,8 @@ if (_ecore_thread_count == _ecore_thread_count_max) { - pthread_mutex_unlock(&_mutex); - return (Ecore_Thread *) worker; + pthread_mutex_unlock(&_mutex); + return (Ecore_Thread *) worker; } pthread_mutex_unlock(&_mutex); @@ -578,20 +578,20 @@ on_error: if (pth) { - if (pth->p) ecore_pipe_del(pth->p); - free(pth); + if (pth->p) ecore_pipe_del(pth->p); + free(pth); } if (_ecore_thread_count == 0) { - if (func_cancel) func_cancel((void *) data); + if (func_cancel) func_cancel((void *) data); - if (worker) - { - ecore_pipe_del(worker->u.long_run.notify); - free(worker); - worker = NULL; - } + if (worker) + { + ecore_pipe_del(worker->u.long_run.notify); + free(worker); + worker = NULL; + } } return (Ecore_Thread *) worker; @@ -728,7 +728,7 @@ EAPI int ecore_thread_max_get(void) { - return _ecore_thread_count_max; + return _ecore_thread_count_max; } /** |
From: Enlightenment S. <no-...@en...> - 2010-07-21 07:09:59
|
Log: fix some function variables and a cedric-requested rename Author: discomfitor Date: 2010-07-21 00:09:51 -0700 (Wed, 21 Jul 2010) New Revision: 50409 Modified: trunk/ecore/src/lib/ecore/Ecore.h trunk/ecore/src/lib/ecore/ecore_thread.c Modified: trunk/ecore/src/lib/ecore/Ecore.h =================================================================== --- trunk/ecore/src/lib/ecore/Ecore.h 2010-07-21 06:43:47 UTC (rev 50408) +++ trunk/ecore/src/lib/ecore/Ecore.h 2010-07-21 07:09:51 UTC (rev 50409) @@ -357,7 +357,7 @@ EAPI int ecore_thread_max_get(void); EAPI void ecore_thread_max_set(int num); EAPI void ecore_thread_max_reset(void); - EAPI int ecore_thread_avail_get(void); + EAPI int ecore_thread_available_get(void); EAPI double ecore_time_get(void); Modified: trunk/ecore/src/lib/ecore/ecore_thread.c =================================================================== --- trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-21 06:43:47 UTC (rev 50408) +++ trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-21 07:09:51 UTC (rev 50409) @@ -665,7 +665,7 @@ ecore_thread_active_get(void) { #ifdef EFL_HAVE_PTHREAD - return eina_list_count(_ecore_active_job_threads); + return _ecore_thread_count; #else return 0; #endif @@ -766,10 +766,10 @@ * this should be equal to (num_cpus - (active_running + active_long_running)) */ EAPI int -ecore_thread_avail_get(void) +ecore_thread_available_get(void) { #ifdef EFL_HAVE_PTHREAD - return _ecore_thread_count_max - (eina_list_count(_ecore_pending_job_threads_long) + eina_list_count(_ecore_pending_job_threads)); + return _ecore_thread_count_max - _ecore_thread_count); #else return 0; #endif |
From: Enlightenment S. <no-...@en...> - 2010-07-21 08:33:31
|
Log: should probably make thread functions threadsafe. and compile. Author: discomfitor Date: 2010-07-21 01:33:25 -0700 (Wed, 21 Jul 2010) New Revision: 50411 Modified: trunk/ecore/src/lib/ecore/ecore_thread.c Modified: trunk/ecore/src/lib/ecore/ecore_thread.c =================================================================== --- trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-21 08:09:41 UTC (rev 50410) +++ trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-21 08:33:25 UTC (rev 50411) @@ -664,8 +664,12 @@ EAPI int ecore_thread_active_get(void) { + int ret; #ifdef EFL_HAVE_PTHREAD - return _ecore_thread_count; + pthread_mutex_lock(&_mutex); + ret = _ecore_thread_count; + pthread_mutex_unlock(&_mutex); + return ret; #else return 0; #endif @@ -680,8 +684,12 @@ EAPI int ecore_thread_pending_get(void) { + int ret; #ifdef EFL_HAVE_PTHREAD - return eina_list_count(_ecore_pending_job_threads); + pthread_mutex_lock(&_mutex); + ret = eina_list_count(_ecore_pending_job_threads); + pthread_mutex_unlock(&_mutex); + return ret; #else return 0; #endif @@ -696,8 +704,12 @@ EAPI int ecore_thread_pending_long_get(void) { + int ret; #ifdef EFL_HAVE_PTHREAD - return eina_list_count(_ecore_pending_job_threads_long); + pthread_mutex_lock(&_mutex); + ret = eina_list_count(_ecore_pending_job_threads_long); + pthread_mutex_unlock(&_mutex); + return ret; #else return 0; #endif @@ -712,8 +724,12 @@ EAPI int ecore_thread_pending_total_get(void) { + int ret; #ifdef EFL_HAVE_PTHREAD - return eina_list_count(_ecore_pending_job_threads) + eina_list_count(_ecore_pending_job_threads_long); + pthread_mutex_lock(&_mutex); + ret = eina_list_count(_ecore_pending_job_threads) + eina_list_count(_ecore_pending_job_threads_long); + pthread_mutex_unlock(&_mutex); + return ret; #else return 0; #endif @@ -728,6 +744,11 @@ EAPI int ecore_thread_max_get(void) { + int ret; + pthread_mutex_lock(&_mutex); + ret = _ecore_thread_count_max; + pthread_mutex_unlock(&_mutex); + return _ecore_thread_count_max; } @@ -744,7 +765,9 @@ /* avoid doing something hilarious by blocking dumb users */ if (num >= (2 * eina_cpu_count())) return; + pthread_mutex_lock(&_mutex); _ecore_thread_count_max = num; + pthread_mutex_unlock(&_mutex); } /** @@ -755,7 +778,9 @@ EAPI void ecore_thread_max_reset(void) { + pthread_mutex_lock(&_mutex); _ecore_thread_count_max = eina_cpu_count(); + pthread_mutex_unlock(&_mutex); } /** @@ -768,8 +793,12 @@ EAPI int ecore_thread_available_get(void) { + int ret; #ifdef EFL_HAVE_PTHREAD - return _ecore_thread_count_max - _ecore_thread_count); + pthread_mutex_lock(&_mutex); + ret = _ecore_thread_count_max - _ecore_thread_count; + pthread_mutex_unlock(&_mutex); + return ret; #else return 0; #endif |
From: Enlightenment S. <no-...@en...> - 2010-07-22 20:28:42
|
Log: +ecore_thread_pool_data_{add,find,del}: start of ecore_thread_pool api. these calls are used from heavy_run to manage data within a thread pool. more to come Author: discomfitor Date: 2010-07-22 13:28:34 -0700 (Thu, 22 Jul 2010) New Revision: 50438 Modified: trunk/ecore/src/lib/ecore/Ecore.h trunk/ecore/src/lib/ecore/ecore_thread.c Modified: trunk/ecore/src/lib/ecore/Ecore.h =================================================================== --- trunk/ecore/src/lib/ecore/Ecore.h 2010-07-22 18:42:44 UTC (rev 50437) +++ trunk/ecore/src/lib/ecore/Ecore.h 2010-07-22 20:28:34 UTC (rev 50438) @@ -340,13 +340,17 @@ void (*func_cancel)(void *data), const void *data); EAPI Ecore_Thread *ecore_long_run(void (*func_heavy)(Ecore_Thread *thread, - void *data), - void (*func_notify)(Ecore_Thread *thread, - void *msg_data, void *data), - void (*func_end)(void *data), - void (*func_cancel)(void *data), - const void *data, - Eina_Bool try_no_queue); + void *data), + void (*func_notify)(Ecore_Thread *thread, + void *msg_data, void *data), + void (*func_end)(void *data), + void (*func_cancel)(void *data), + const void *data, + Eina_Bool try_no_queue); + EAPI Eina_Bool ecore_thread_pool_data_add(Ecore_Thread *thread, const char *key, + const void *value); + EAPI void *ecore_thread_pool_data_find(Ecore_Thread *thread, const char *key); + EAPI Eina_Bool ecore_thread_pool_data_del(Ecore_Thread *thread, const char *key); 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); Modified: trunk/ecore/src/lib/ecore/ecore_thread.c =================================================================== --- trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-22 18:42:44 UTC (rev 50437) +++ trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-22 20:28:34 UTC (rev 50438) @@ -18,29 +18,32 @@ struct _Ecore_Pthread_Worker { - union { - struct { - void (*func_blocking)(void *data); - } short_run; - struct { - void (*func_heavy)(Ecore_Thread *thread, void *data); - void (*func_notify)(Ecore_Thread *thread, void *msg_data, void *data); + union + { + struct + { + void (*func_blocking)(void *data); + } short_run; + struct + { + void (*func_heavy)(Ecore_Thread *thread, void *data); + void (*func_notify)(Ecore_Thread *thread, void *msg_data, void *data); - Ecore_Pipe *notify; + Ecore_Pipe *notify; + Eina_Hash *hash; + #ifdef EFL_HAVE_PTHREAD + pthread_t self; + #endif + } long_run; + } u; -#ifdef EFL_HAVE_PTHREAD - pthread_t self; -#endif - } long_run; - } u; + void (*func_cancel)(void *data); + void (*func_end)(void *data); - void (*func_cancel)(void *data); - void (*func_end)(void *data); + const void *data; - const void *data; - - Eina_Bool cancel : 1; - Eina_Bool long_run : 1; + Eina_Bool cancel : 1; + Eina_Bool long_run : 1; }; #ifdef EFL_HAVE_PTHREAD @@ -59,6 +62,7 @@ #ifdef EFL_HAVE_PTHREAD static int _ecore_thread_count = 0; +static Eina_Hash *_ecore_thread_global_hash = NULL; 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; @@ -114,7 +118,11 @@ work->func_end((void *) work->data); } - if (work->long_run) ecore_pipe_del(work->u.long_run.notify); + if (work->long_run) + { + ecore_pipe_del(work->u.long_run.notify); + eina_hash_free(work->u.long_run.hash); + } free(work); } @@ -538,6 +546,7 @@ worker->u.long_run.func_heavy = func_heavy; worker->u.long_run.func_notify = func_notify; + worker->u.long_run.hash = NULL; worker->func_cancel = func_cancel; worker->func_end = func_end; worker->data = data; @@ -606,6 +615,7 @@ */ worker.u.long_run.func_heavy = func_heavy; worker.u.long_run.func_notify = func_notify; + worker->u.long_run.hash = NULL; worker.u.long_run.notify = NULL; worker.func_cancel = func_cancel; worker.func_end = func_end; @@ -803,3 +813,91 @@ return 0; #endif } + +/** + * @brief Add data to the pool for subsequent uses + * @param thread The thread context to add to + * @param key The name string to add the data with + * @param value The data to add + * @return EINA_TRUE on success, EINA_FALSE on failure + * This adds data to the thread context, allowing for subsequent users of the thread's pool + * to retrieve and use it without complicated mutexing. This function can only be called by a + * heavy_run thread INSIDE the thread and will return EINA_FALSE in any case but success. + * All data added to the thread pool must be freed in the thread's func_end/func_cancel + * functions to avoid leaks. + */ +EAPI Eina_Bool +ecore_thread_pool_data_add(Ecore_Thread *thread, const char *key, const void *value) +{ + Ecore_Pthread_Worker *worker = (Ecore_Pthread_Worker *) thread; + if ((!thread) || (!key) || (!value)) + return EINA_FALSE; +#ifdef EFL_HAVE_PTHREAD + if (worker->u.long_run.self != pthread_self()) return EINA_FALSE; + + if (!worker->u.long_run.hash) + worker->u.long_run.hash = eina_hash_string_small_new(NULL); + + if (!worker->u.long_run.hash) + return EINA_FALSE; + + return eina_hash_add(worker->u.long_run.hash, key, value); +#else + return EINA_TRUE; +#endif +} + +/** + * @brief Find data in the pool's data + * @param thread The thread context + * @param key The name string the data is associated with + * @return The value, or NULL on error + * This finds data in the thread context that has been previously added with @ref ecore_thread_pool_data_add + * This function can only be called by a heavy_run thread INSIDE the thread, and will return NULL + * in any case but success. + */ + +EAPI void * +ecore_thread_pool_data_find(Ecore_Thread *thread, const char *key) +{ + Ecore_Pthread_Worker *worker = (Ecore_Pthread_Worker *) thread; + if ((!thread) || (!key)) + return NULL; +#ifdef EFL_HAVE_PTHREAD + if (worker->u.long_run.self != pthread_self()) return NULL; + + if (!worker->u.long_run.hash) + return NULL; + + return eina_hash_find(worker->u.long_run.hash, key); +#else + return NULL; +#endif +} + +/** + * @brief Delete data from the pool's data + * @param thread The thread context + * @param key The name string the data is associated with + * @return EINA_TRUE on success, EINA_FALSE on failure + * This deletes the data pointer from the thread context which was previously added with @ref ecore_thread_pool_data_add + * This function can only be called by a heavy_run thread INSIDE the thread, and will return EINA_FALSE + * in any case but success. Note that this WILL NOT free the data, it merely removes it from the thread pool. + */ +EAPI Eina_Bool +ecore_thread_pool_data_del(Ecore_Thread *thread, const char *key) +{ + Ecore_Pthread_Worker *worker = (Ecore_Pthread_Worker *) thread; + if ((!thread) || (!key)) + return EINA_FALSE; +#ifdef EFL_HAVE_PTHREAD + if (worker->u.long_run.self != pthread_self()) return EINA_FALSE; + + if (!worker->u.long_run.hash) + return EINA_FALSE; + + return eina_hash_del_by_key(worker->u.long_run.hash, key); +#else + return EINA_TRUE; +#endif +} |
From: Enlightenment S. <no-...@en...> - 2010-07-23 03:39:58
|
Log: api change to ecore_thread_pool_data_add, now has 4th argument "direct" to avoid copying key value if desired Author: discomfitor Date: 2010-07-22 20:39:52 -0700 (Thu, 22 Jul 2010) New Revision: 50442 Modified: trunk/ecore/src/lib/ecore/Ecore.h trunk/ecore/src/lib/ecore/ecore_thread.c Modified: trunk/ecore/src/lib/ecore/Ecore.h =================================================================== --- trunk/ecore/src/lib/ecore/Ecore.h 2010-07-23 03:14:21 UTC (rev 50441) +++ trunk/ecore/src/lib/ecore/Ecore.h 2010-07-23 03:39:52 UTC (rev 50442) @@ -348,7 +348,7 @@ const void *data, Eina_Bool try_no_queue); EAPI Eina_Bool ecore_thread_pool_data_add(Ecore_Thread *thread, const char *key, - const void *value); + const void *value, Eina_Bool direct); EAPI void *ecore_thread_pool_data_find(Ecore_Thread *thread, const char *key); EAPI Eina_Bool ecore_thread_pool_data_del(Ecore_Thread *thread, const char *key); EAPI Eina_Bool ecore_thread_cancel(Ecore_Thread *thread); Modified: trunk/ecore/src/lib/ecore/ecore_thread.c =================================================================== --- trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-23 03:14:21 UTC (rev 50441) +++ trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-23 03:39:52 UTC (rev 50442) @@ -819,6 +819,7 @@ * @param thread The thread context to add to * @param key The name string to add the data with * @param value The data to add + * @param direct If true, this will not copy the key string (like eina_hash_direct_add) * @return EINA_TRUE on success, EINA_FALSE on failure * This adds data to the thread context, allowing for subsequent users of the thread's pool * to retrieve and use it without complicated mutexing. This function can only be called by a @@ -827,7 +828,7 @@ * functions to avoid leaks. */ EAPI Eina_Bool -ecore_thread_pool_data_add(Ecore_Thread *thread, const char *key, const void *value) +ecore_thread_pool_data_add(Ecore_Thread *thread, const char *key, const void *value, Eina_Bool direct) { Ecore_Pthread_Worker *worker = (Ecore_Pthread_Worker *) thread; if ((!thread) || (!key) || (!value)) @@ -840,13 +841,15 @@ if (!worker->u.long_run.hash) return EINA_FALSE; - + if (direct) + return eina_hash_direct_add(worker->u.long_run.hash, key, value); return eina_hash_add(worker->u.long_run.hash, key, value); #else return EINA_TRUE; #endif } + /** * @brief Find data in the pool's data * @param thread The thread context |
From: Enlightenment S. <no-...@en...> - 2010-07-23 04:17:48
|
Log: +ecore_thread_pool_data_modify_or_add Author: discomfitor Date: 2010-07-22 21:17:41 -0700 (Thu, 22 Jul 2010) New Revision: 50443 Modified: trunk/ecore/src/lib/ecore/Ecore.h trunk/ecore/src/lib/ecore/ecore_thread.c Modified: trunk/ecore/src/lib/ecore/Ecore.h =================================================================== --- trunk/ecore/src/lib/ecore/Ecore.h 2010-07-23 03:39:52 UTC (rev 50442) +++ trunk/ecore/src/lib/ecore/Ecore.h 2010-07-23 04:17:41 UTC (rev 50443) @@ -349,6 +349,8 @@ Eina_Bool try_no_queue); EAPI Eina_Bool ecore_thread_pool_data_add(Ecore_Thread *thread, const char *key, const void *value, Eina_Bool direct); + EAPI void *ecore_thread_pool_data_modify_or_add(Ecore_Thread *thread, const char *key, + const void *value); EAPI void *ecore_thread_pool_data_find(Ecore_Thread *thread, const char *key); EAPI Eina_Bool ecore_thread_pool_data_del(Ecore_Thread *thread, const char *key); EAPI Eina_Bool ecore_thread_cancel(Ecore_Thread *thread); Modified: trunk/ecore/src/lib/ecore/ecore_thread.c =================================================================== --- trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-23 03:39:52 UTC (rev 50442) +++ trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-23 04:17:41 UTC (rev 50443) @@ -849,7 +849,39 @@ #endif } +/** + * @brief Modify data in the pool, or add if not found + * @param thread The thread context + * @param key The name string to add the data with + * @param value The data to add + * @param direct If true, this will not copy the key string (like eina_hash_direct_add) + * @return The old data associated with @p key on success if modified, NULL if added + * This adds/modifies data in the thread context, adding only if modify fails. + * This function can only be called by a heavy_run thread INSIDE the thread. + * All data added to the thread pool must be freed in the thread's func_end/func_cancel + * functions to avoid leaks. + */ +EAPI void * +ecore_thread_pool_data_modify_or_add(Ecore_Thread *thread, const char *key, const void *value) +{ + Ecore_Pthread_Worker *worker = (Ecore_Pthread_Worker *) thread; + if ((!thread) || (!key) || (!value)) + return NULL; +#ifdef EFL_HAVE_PTHREAD + if (worker->u.long_run.self != pthread_self()) return NULL; + if (!worker->u.long_run.hash) + worker->u.long_run.hash = eina_hash_string_small_new(NULL); + + if (!worker->u.long_run.hash) + return NULL; + + return eina_hash_modify_or_add(worker->u.long_run.hash, key, value); +#else + return NULL; +#endif +} + /** * @brief Find data in the pool's data * @param thread The thread context |
From: Enlightenment S. <no-...@en...> - 2010-07-23 13:08:45
|
Log: remove unnecessary mutexes, expand pthread self member to short_run threads, make thread pool data work on short_run threads, ecore_thread_pool_data_modify_or_add -> ecore_thread_pool_data_set Author: discomfitor Date: 2010-07-23 06:08:38 -0700 (Fri, 23 Jul 2010) New Revision: 50449 Modified: trunk/ecore/src/lib/ecore/Ecore.h trunk/ecore/src/lib/ecore/ecore_thread.c Modified: trunk/ecore/src/lib/ecore/Ecore.h =================================================================== --- trunk/ecore/src/lib/ecore/Ecore.h 2010-07-23 13:04:21 UTC (rev 50448) +++ trunk/ecore/src/lib/ecore/Ecore.h 2010-07-23 13:08:38 UTC (rev 50449) @@ -349,7 +349,7 @@ Eina_Bool try_no_queue); EAPI Eina_Bool ecore_thread_pool_data_add(Ecore_Thread *thread, const char *key, const void *value, Eina_Bool direct); - EAPI void *ecore_thread_pool_data_modify_or_add(Ecore_Thread *thread, const char *key, + EAPI void *ecore_thread_pool_data_set(Ecore_Thread *thread, const char *key, const void *value); EAPI void *ecore_thread_pool_data_find(Ecore_Thread *thread, const char *key); EAPI Eina_Bool ecore_thread_pool_data_del(Ecore_Thread *thread, const char *key); Modified: trunk/ecore/src/lib/ecore/ecore_thread.c =================================================================== --- trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-23 13:04:21 UTC (rev 50448) +++ trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-23 13:08:38 UTC (rev 50449) @@ -20,25 +20,24 @@ { union { - struct - { - void (*func_blocking)(void *data); - } short_run; struct { + void (*func_blocking)(void *data); + } short_run; + struct + { void (*func_heavy)(Ecore_Thread *thread, void *data); void (*func_notify)(Ecore_Thread *thread, void *msg_data, void *data); - Ecore_Pipe *notify; - Eina_Hash *hash; - #ifdef EFL_HAVE_PTHREAD - pthread_t self; - #endif } long_run; } u; void (*func_cancel)(void *data); void (*func_end)(void *data); + #ifdef EFL_HAVE_PTHREAD + pthread_t self; + Eina_Hash *hash; + #endif const void *data; @@ -119,10 +118,9 @@ } if (work->long_run) - { ecore_pipe_del(work->u.long_run.notify); - eina_hash_free(work->u.long_run.hash); - } + + eina_hash_free(work->hash); free(work); } @@ -186,7 +184,7 @@ pthread_mutex_unlock(&_mutex); - work->u.long_run.self = thread; + work->self = thread; work->u.long_run.func_heavy((Ecore_Thread *) work, (void *) work->data); ecore_pipe_write(end_pipe, &work, sizeof (Ecore_Pthread_Worker *)); @@ -212,7 +210,7 @@ } pth->thread = pthread_self(); - work->u.long_run.self = pth->thread; + work->self = pth->thread; work->u.long_run.func_heavy((Ecore_Thread *) work, (void *) work->data); ecore_pipe_write(pth->p, &work, sizeof (Ecore_Pthread_Worker *)); @@ -546,7 +544,7 @@ worker->u.long_run.func_heavy = func_heavy; worker->u.long_run.func_notify = func_notify; - worker->u.long_run.hash = NULL; + worker->hash = NULL; worker->func_cancel = func_cancel; worker->func_end = func_end; worker->data = data; @@ -615,7 +613,7 @@ */ worker.u.long_run.func_heavy = func_heavy; worker.u.long_run.func_notify = func_notify; - worker->u.long_run.hash = NULL; + worker->hash = NULL; worker.u.long_run.notify = NULL; worker.func_cancel = func_cancel; worker.func_end = func_end; @@ -653,7 +651,7 @@ if (!worker->long_run) return EINA_FALSE; #ifdef EFL_HAVE_PTHREAD - if (worker->u.long_run.self != pthread_self()) return EINA_FALSE; + if (worker->self != pthread_self()) return EINA_FALSE; ecore_pipe_write(worker->u.long_run.notify, &data, sizeof (void *)); @@ -674,12 +672,8 @@ EAPI int ecore_thread_active_get(void) { - int ret; #ifdef EFL_HAVE_PTHREAD - pthread_mutex_lock(&_mutex); - ret = _ecore_thread_count; - pthread_mutex_unlock(&_mutex); - return ret; + return _ecore_thread_count; #else return 0; #endif @@ -754,11 +748,6 @@ EAPI int ecore_thread_max_get(void) { - int ret; - pthread_mutex_lock(&_mutex); - ret = _ecore_thread_count_max; - pthread_mutex_unlock(&_mutex); - return _ecore_thread_count_max; } @@ -775,9 +764,7 @@ /* avoid doing something hilarious by blocking dumb users */ if (num >= (2 * eina_cpu_count())) return; - pthread_mutex_lock(&_mutex); _ecore_thread_count_max = num; - pthread_mutex_unlock(&_mutex); } /** @@ -788,9 +775,7 @@ EAPI void ecore_thread_max_reset(void) { - pthread_mutex_lock(&_mutex); _ecore_thread_count_max = eina_cpu_count(); - pthread_mutex_unlock(&_mutex); } /** @@ -823,7 +808,7 @@ * @return EINA_TRUE on success, EINA_FALSE on failure * This adds data to the thread context, allowing for subsequent users of the thread's pool * to retrieve and use it without complicated mutexing. This function can only be called by a - * heavy_run thread INSIDE the thread and will return EINA_FALSE in any case but success. + * *_run thread INSIDE the thread and will return EINA_FALSE in any case but success. * All data added to the thread pool must be freed in the thread's func_end/func_cancel * functions to avoid leaks. */ @@ -834,16 +819,16 @@ if ((!thread) || (!key) || (!value)) return EINA_FALSE; #ifdef EFL_HAVE_PTHREAD - if (worker->u.long_run.self != pthread_self()) return EINA_FALSE; + if (worker->self != pthread_self()) return EINA_FALSE; - if (!worker->u.long_run.hash) - worker->u.long_run.hash = eina_hash_string_small_new(NULL); + if (!worker->hash) + worker->hash = eina_hash_string_small_new(NULL); - if (!worker->u.long_run.hash) + if (!worker->hash) return EINA_FALSE; if (direct) - return eina_hash_direct_add(worker->u.long_run.hash, key, value); - return eina_hash_add(worker->u.long_run.hash, key, value); + return eina_hash_direct_add(worker->hash, key, value); + return eina_hash_add(worker->hash, key, value); #else return EINA_TRUE; #endif @@ -857,26 +842,26 @@ * @param direct If true, this will not copy the key string (like eina_hash_direct_add) * @return The old data associated with @p key on success if modified, NULL if added * This adds/modifies data in the thread context, adding only if modify fails. - * This function can only be called by a heavy_run thread INSIDE the thread. + * This function can only be called by a *_run thread INSIDE the thread. * All data added to the thread pool must be freed in the thread's func_end/func_cancel * functions to avoid leaks. */ EAPI void * -ecore_thread_pool_data_modify_or_add(Ecore_Thread *thread, const char *key, const void *value) +ecore_thread_pool_data_set(Ecore_Thread *thread, const char *key, const void *value) { Ecore_Pthread_Worker *worker = (Ecore_Pthread_Worker *) thread; if ((!thread) || (!key) || (!value)) return NULL; #ifdef EFL_HAVE_PTHREAD - if (worker->u.long_run.self != pthread_self()) return NULL; + if (worker->self != pthread_self()) return NULL; - if (!worker->u.long_run.hash) - worker->u.long_run.hash = eina_hash_string_small_new(NULL); + if (!worker->hash) + worker->hash = eina_hash_string_small_new(NULL); - if (!worker->u.long_run.hash) + if (!worker->hash) return NULL; - return eina_hash_modify_or_add(worker->u.long_run.hash, key, value); + return eina_hash_set(worker->hash, key, value); #else return NULL; #endif @@ -888,7 +873,7 @@ * @param key The name string the data is associated with * @return The value, or NULL on error * This finds data in the thread context that has been previously added with @ref ecore_thread_pool_data_add - * This function can only be called by a heavy_run thread INSIDE the thread, and will return NULL + * This function can only be called by a *_run thread INSIDE the thread, and will return NULL * in any case but success. */ @@ -899,12 +884,12 @@ if ((!thread) || (!key)) return NULL; #ifdef EFL_HAVE_PTHREAD - if (worker->u.long_run.self != pthread_self()) return NULL; + if (worker->self != pthread_self()) return NULL; - if (!worker->u.long_run.hash) + if (!worker->hash) return NULL; - return eina_hash_find(worker->u.long_run.hash, key); + return eina_hash_find(worker->hash, key); #else return NULL; #endif @@ -916,7 +901,7 @@ * @param key The name string the data is associated with * @return EINA_TRUE on success, EINA_FALSE on failure * This deletes the data pointer from the thread context which was previously added with @ref ecore_thread_pool_data_add - * This function can only be called by a heavy_run thread INSIDE the thread, and will return EINA_FALSE + * This function can only be called by a *_run thread INSIDE the thread, and will return EINA_FALSE * in any case but success. Note that this WILL NOT free the data, it merely removes it from the thread pool. */ EAPI Eina_Bool @@ -926,12 +911,12 @@ if ((!thread) || (!key)) return EINA_FALSE; #ifdef EFL_HAVE_PTHREAD - if (worker->u.long_run.self != pthread_self()) return EINA_FALSE; + if (worker->self != pthread_self()) return EINA_FALSE; - if (!worker->u.long_run.hash) + if (!worker->hash) return EINA_FALSE; - return eina_hash_del_by_key(worker->u.long_run.hash, key); + return eina_hash_del_by_key(worker->hash, key); #else return EINA_TRUE; #endif |
From: Enlightenment S. <no-...@en...> - 2010-07-23 13:23:54
|
Log: fix doxy Author: discomfitor Date: 2010-07-23 06:12:42 -0700 (Fri, 23 Jul 2010) New Revision: 50450 Modified: trunk/ecore/src/lib/ecore/ecore_thread.c Modified: trunk/ecore/src/lib/ecore/ecore_thread.c =================================================================== --- trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-23 13:08:38 UTC (rev 50449) +++ trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-23 13:12:42 UTC (rev 50450) @@ -333,8 +333,9 @@ #endif } /** - * @defgroup Ecore_Thread Ecore Thread Functions + * @addtogroup Ecore_Thread Ecore Thread Functions * These functions allow for ecore-managed threads which integrate with ecore's main loop. + * @{ */ /** @@ -921,3 +922,7 @@ return EINA_TRUE; #endif } + +/** + * @} + */ |
From: Enlightenment S. <no-...@en...> - 2010-07-23 15:52:30
|
Log: add threadsafe global data to threads, allowing for communication between threads and other threads and threads and main loop Author: discomfitor Date: 2010-07-23 08:33:22 -0700 (Fri, 23 Jul 2010) New Revision: 50453 Modified: trunk/ecore/src/lib/ecore/Ecore.h trunk/ecore/src/lib/ecore/ecore_thread.c Modified: trunk/ecore/src/lib/ecore/Ecore.h =================================================================== --- trunk/ecore/src/lib/ecore/Ecore.h 2010-07-23 15:31:43 UTC (rev 50452) +++ trunk/ecore/src/lib/ecore/Ecore.h 2010-07-23 15:33:22 UTC (rev 50453) @@ -347,12 +347,6 @@ void (*func_cancel)(void *data), const void *data, Eina_Bool try_no_queue); - EAPI Eina_Bool ecore_thread_pool_data_add(Ecore_Thread *thread, const char *key, - const void *value, Eina_Bool direct); - EAPI void *ecore_thread_pool_data_set(Ecore_Thread *thread, const char *key, - const void *value); - EAPI void *ecore_thread_pool_data_find(Ecore_Thread *thread, const char *key); - EAPI Eina_Bool ecore_thread_pool_data_del(Ecore_Thread *thread, const char *key); 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); @@ -365,7 +359,20 @@ EAPI void ecore_thread_max_reset(void); EAPI int ecore_thread_available_get(void); + EAPI Eina_Bool ecore_thread_pool_data_add(Ecore_Thread *thread, const char *key, + const void *value, Eina_Bool direct); + EAPI void *ecore_thread_pool_data_set(Ecore_Thread *thread, const char *key, + const void *value); + EAPI void *ecore_thread_pool_data_find(Ecore_Thread *thread, const char *key); + EAPI Eina_Bool ecore_thread_pool_data_del(Ecore_Thread *thread, const char *key); + EAPI Eina_Bool ecore_thread_global_data_add(const char *key, const void *value, + Eina_Bool direct); + EAPI void *ecore_thread_global_data_set(const char *key, const void *value); + EAPI void *ecore_thread_global_data_find(const char *key); + EAPI Eina_Bool ecore_thread_global_data_del(const char *key); + + EAPI double ecore_time_get(void); EAPI double ecore_loop_time_get(void); Modified: trunk/ecore/src/lib/ecore/ecore_thread.c =================================================================== --- trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-23 15:31:43 UTC (rev 50452) +++ trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-23 15:33:22 UTC (rev 50453) @@ -61,14 +61,15 @@ #ifdef EFL_HAVE_PTHREAD static int _ecore_thread_count = 0; -static Eina_Hash *_ecore_thread_global_hash = NULL; + 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 Ecore_Event_Handler *del_handler = NULL; - static pthread_mutex_t _ecore_pending_job_threads_mutex = PTHREAD_MUTEX_INITIALIZER; +static Eina_Hash *_ecore_thread_global_hash = NULL; +static pthread_rwlock_t _ecore_thread_global_hash_lock = PTHREAD_RWLOCK_INITIALIZER; static void _ecore_thread_pipe_free(void *data __UNUSED__, void *event) { @@ -924,5 +925,128 @@ } /** + * @brief Add data to the global data + * @param key The name string to add the data with + * @param value The data to add + * @param direct If true, this will not copy the key string (like eina_hash_direct_add) + * @return EINA_TRUE on success, EINA_FALSE on failure + * This adds data to the global thread data, and will return EINA_FALSE in any case but success. + * All data added to global should be manually freed to avoid stale pointers in the global thread data. + */ +EAPI Eina_Bool +ecore_thread_global_data_add(const char *key, const void *value, Eina_Bool direct) +{ + Eina_Bool ret; + if ((!key) || (!value)) + return EINA_FALSE; +#ifdef EFL_HAVE_PTHREAD + pthread_rwlock_wrlock(&_ecore_thread_global_hash_lock); + if (!_ecore_thread_global_hash) + _ecore_thread_global_hash = eina_hash_string_small_new(NULL); + pthread_rwlock_unlock(&_ecore_thread_global_hash_lock); + + if (!_ecore_thread_global_hash) + return EINA_FALSE; + pthread_rwlock_wrlock(&_ecore_thread_global_hash_lock); + if (direct) + ret = eina_hash_direct_add(_ecore_thread_global_hash, key, value); + else + ret = eina_hash_add(_ecore_thread_global_hash, key, value); + pthread_rwlock_unlock(&_ecore_thread_global_hash_lock); + return ret; +#else + return EINA_TRUE; +#endif +} + +/** + * @brief Add data to the global data + * @param key The name string to add the data with + * @param value The data to add + * @return EINA_TRUE on success, EINA_FALSE on failure + * This adds data to the global thread data and returns NULL, or replaces the previous data + * associated with @p key and returning the previous data if it existed. To see if an error occurred, + * one must use eina_error_get. + * All data added to global should be manually freed to avoid stale pointers in the global thread data. + */ +EAPI void * +ecore_thread_global_data_set(const char *key, const void *value) +{ + void *ret; + if ((!key) || (!value)) + return NULL; +#ifdef EFL_HAVE_PTHREAD + pthread_rwlock_wrlock(&_ecore_thread_global_hash_lock); + if (!_ecore_thread_global_hash) + _ecore_thread_global_hash = eina_hash_string_small_new(NULL); + pthread_rwlock_unlock(&_ecore_thread_global_hash_lock); + + if (!_ecore_thread_global_hash) + return NULL; + + pthread_rwlock_wrlock(&_ecore_thread_global_hash_lock); + ret = eina_hash_set(_ecore_thread_global_hash, key, value); + pthread_rwlock_unlock(&_ecore_thread_global_hash_lock); + return ret; +#else + return NULL; +#endif +} + +/** + * @brief Find data in the global data + * @param key The name string the data is associated with + * @return The value, or NULL on error + * This finds data in the global data that has been previously added with @ref ecore_thread_global_data_add + * This function will return NULL in any case but success. + */ + +EAPI void * +ecore_thread_global_data_find(const char *key) +{ + void *ret; + if (!key) + return NULL; +#ifdef EFL_HAVE_PTHREAD + if (!_ecore_thread_global_hash) return NULL; + + pthread_rwlock_rdlock(&_ecore_thread_global_hash_lock); + ret = eina_hash_find(_ecore_thread_global_hash, key); + pthread_rwlock_unlock(&_ecore_thread_global_hash_lock); + return ret; +#else + return NULL; +#endif +} + +/** + * @brief Delete data from the global data + * @param key The name string the data is associated with + * @return EINA_TRUE on success, EINA_FALSE on failure + * This deletes the data pointer from the global data which was previously added with @ref ecore_thread_global_data_add + * This function will return EINA_FALSE in any case but success. + * Note that this WILL NOT free the data, it merely removes it from the global set. + */ +EAPI Eina_Bool +ecore_thread_global_data_del(const char *key) +{ + Eina_Bool ret; + if (!key) + return EINA_FALSE; +#ifdef EFL_HAVE_PTHREAD + if (!_ecore_thread_global_hash) + return EINA_FALSE; + + pthread_rwlock_wrlock(&_ecore_thread_global_hash_lock); + ret = eina_hash_del_by_key(_ecore_thread_global_hash, key); + pthread_rwlock_unlock(&_ecore_thread_global_hash_lock); + return ret; +#else + return EINA_TRUE; +#endif +} + + +/** * @} */ |
From: Enlightenment S. <no-...@en...> - 2010-07-23 16:02:30
|
Log: rename mutex Author: discomfitor Date: 2010-07-23 06:35:14 -0700 (Fri, 23 Jul 2010) New Revision: 50451 Modified: trunk/ecore/src/lib/ecore/ecore_thread.c Modified: trunk/ecore/src/lib/ecore/ecore_thread.c =================================================================== --- trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-23 13:12:42 UTC (rev 50450) +++ trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-23 13:35:14 UTC (rev 50451) @@ -67,7 +67,7 @@ static Eina_List *_ecore_pending_job_threads_long = NULL; static Ecore_Event_Handler *del_handler = NULL; -static pthread_mutex_t _mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t _ecore_pending_job_threads_mutex = PTHREAD_MUTEX_INITIALIZER; static void _ecore_thread_pipe_free(void *data __UNUSED__, void *event) @@ -145,18 +145,18 @@ while (_ecore_pending_job_threads) { - pthread_mutex_lock(&_mutex); + pthread_mutex_lock(&_ecore_pending_job_threads_mutex); if (!_ecore_pending_job_threads) { - pthread_mutex_unlock(&_mutex); + pthread_mutex_unlock(&_ecore_pending_job_threads_mutex); break; } work = eina_list_data_get(_ecore_pending_job_threads); _ecore_pending_job_threads = eina_list_remove_list(_ecore_pending_job_threads, _ecore_pending_job_threads); - pthread_mutex_unlock(&_mutex); + pthread_mutex_unlock(&_ecore_pending_job_threads_mutex); work->u.short_run.func_blocking((void *) work->data); @@ -171,18 +171,18 @@ while (_ecore_pending_job_threads_long) { - pthread_mutex_lock(&_mutex); + pthread_mutex_lock(&_ecore_pending_job_threads_mutex); if (!_ecore_pending_job_threads_long) { - pthread_mutex_unlock(&_mutex); + 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); - pthread_mutex_unlock(&_mutex); + pthread_mutex_unlock(&_ecore_pending_job_threads_mutex); work->self = thread; work->u.long_run.func_heavy((Ecore_Thread *) work, (void *) work->data); @@ -243,9 +243,9 @@ pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); - pthread_mutex_lock(&_mutex); + pthread_mutex_lock(&_ecore_pending_job_threads_mutex); _ecore_thread_count++; - pthread_mutex_unlock(&_mutex); + pthread_mutex_unlock(&_ecore_pending_job_threads_mutex); on_error: if (_ecore_pending_job_threads) _ecore_short_job(pth->p); @@ -253,21 +253,21 @@ /* FIXME: Check if there is long running task todo, and switch to long run handler. */ - pthread_mutex_lock(&_mutex); + pthread_mutex_lock(&_ecore_pending_job_threads_mutex); if (_ecore_pending_job_threads) { - pthread_mutex_unlock(&_mutex); + pthread_mutex_unlock(&_ecore_pending_job_threads_mutex); goto on_error; } if (_ecore_pending_job_threads_long) { - pthread_mutex_unlock(&_mutex); + pthread_mutex_unlock(&_ecore_pending_job_threads_mutex); goto on_error; } _ecore_thread_count--; - pthread_mutex_unlock(&_mutex); + pthread_mutex_unlock(&_ecore_pending_job_threads_mutex); work = malloc(sizeof (Ecore_Pthread_Worker)); if (!work) return NULL; @@ -307,7 +307,7 @@ Ecore_Pthread_Worker *work; Ecore_Pthread_Data *pth; - pthread_mutex_lock(&_mutex); + pthread_mutex_lock(&_ecore_pending_job_threads_mutex); EINA_LIST_FREE(_ecore_pending_job_threads, work) { @@ -316,7 +316,7 @@ free(work); } - pthread_mutex_unlock(&_mutex); + pthread_mutex_unlock(&_ecore_pending_job_threads_mutex); EINA_LIST_FREE(_ecore_active_job_threads, pth) { @@ -384,16 +384,16 @@ work->long_run = EINA_FALSE; work->data = data; - pthread_mutex_lock(&_mutex); + pthread_mutex_lock(&_ecore_pending_job_threads_mutex); _ecore_pending_job_threads = eina_list_append(_ecore_pending_job_threads, work); if (_ecore_thread_count == _ecore_thread_count_max) { - pthread_mutex_unlock(&_mutex); + pthread_mutex_unlock(&_ecore_pending_job_threads_mutex); return (Ecore_Thread *) work; } - pthread_mutex_unlock(&_mutex); + pthread_mutex_unlock(&_ecore_pending_job_threads_mutex); /* One more thread could be created. */ pth = malloc(sizeof (Ecore_Pthread_Data)); @@ -454,14 +454,14 @@ Ecore_Pthread_Worker *work; Eina_List *l; - pthread_mutex_lock(&_mutex); + pthread_mutex_lock(&_ecore_pending_job_threads_mutex); EINA_LIST_FOREACH(_ecore_pending_job_threads, l, work) if ((void *) work == (void *) thread) { _ecore_pending_job_threads = eina_list_remove_list(_ecore_pending_job_threads, l); - pthread_mutex_unlock(&_mutex); + pthread_mutex_unlock(&_ecore_pending_job_threads_mutex); if (work->func_cancel) work->func_cancel((void *) work->data); @@ -470,7 +470,7 @@ return EINA_TRUE; } - pthread_mutex_unlock(&_mutex); + pthread_mutex_unlock(&_ecore_pending_job_threads_mutex); /* Delay the destruction */ ((Ecore_Pthread_Worker *)thread)->cancel = EINA_TRUE; @@ -562,16 +562,16 @@ return (Ecore_Thread *) worker; } - pthread_mutex_lock(&_mutex); + pthread_mutex_lock(&_ecore_pending_job_threads_mutex); _ecore_pending_job_threads_long = eina_list_append(_ecore_pending_job_threads_long, worker); if (_ecore_thread_count == _ecore_thread_count_max) { - pthread_mutex_unlock(&_mutex); + pthread_mutex_unlock(&_ecore_pending_job_threads_mutex); return (Ecore_Thread *) worker; } - pthread_mutex_unlock(&_mutex); + pthread_mutex_unlock(&_ecore_pending_job_threads_mutex); /* One more thread could be created. */ pth = malloc(sizeof (Ecore_Pthread_Data)); @@ -691,9 +691,9 @@ { int ret; #ifdef EFL_HAVE_PTHREAD - pthread_mutex_lock(&_mutex); + pthread_mutex_lock(&_ecore_pending_job_threads_mutex); ret = eina_list_count(_ecore_pending_job_threads); - pthread_mutex_unlock(&_mutex); + pthread_mutex_unlock(&_ecore_pending_job_threads_mutex); return ret; #else return 0; @@ -711,9 +711,9 @@ { int ret; #ifdef EFL_HAVE_PTHREAD - pthread_mutex_lock(&_mutex); + pthread_mutex_lock(&_ecore_pending_job_threads_mutex); ret = eina_list_count(_ecore_pending_job_threads_long); - pthread_mutex_unlock(&_mutex); + pthread_mutex_unlock(&_ecore_pending_job_threads_mutex); return ret; #else return 0; @@ -731,9 +731,9 @@ { int ret; #ifdef EFL_HAVE_PTHREAD - pthread_mutex_lock(&_mutex); + pthread_mutex_lock(&_ecore_pending_job_threads_mutex); ret = eina_list_count(_ecore_pending_job_threads) + eina_list_count(_ecore_pending_job_threads_long); - pthread_mutex_unlock(&_mutex); + pthread_mutex_unlock(&_ecore_pending_job_threads_mutex); return ret; #else return 0; @@ -791,9 +791,9 @@ { int ret; #ifdef EFL_HAVE_PTHREAD - pthread_mutex_lock(&_mutex); + pthread_mutex_lock(&_ecore_pending_job_threads_mutex); ret = _ecore_thread_count_max - _ecore_thread_count; - pthread_mutex_unlock(&_mutex); + pthread_mutex_unlock(&_ecore_pending_job_threads_mutex); return ret; #else return 0; |
From: Enlightenment S. <no-...@en...> - 2010-07-23 16:24:42
|
Log: +ecore_thread_{global,pool}_data_wait, to allow waiting for data in the global or pool data contexts and simulate g_async_queue in a less mutexy fashion Author: discomfitor Date: 2010-07-23 09:24:35 -0700 (Fri, 23 Jul 2010) New Revision: 50454 Modified: trunk/ecore/src/lib/ecore/Ecore.h trunk/ecore/src/lib/ecore/ecore_thread.c Modified: trunk/ecore/src/lib/ecore/Ecore.h =================================================================== --- trunk/ecore/src/lib/ecore/Ecore.h 2010-07-23 15:33:22 UTC (rev 50453) +++ trunk/ecore/src/lib/ecore/Ecore.h 2010-07-23 16:24:35 UTC (rev 50454) @@ -371,6 +371,7 @@ EAPI void *ecore_thread_global_data_set(const char *key, const void *value); EAPI void *ecore_thread_global_data_find(const char *key); EAPI Eina_Bool ecore_thread_global_data_del(const char *key); + EAPI void *ecore_thread_global_data_wait(const char *key, double seconds); EAPI double ecore_time_get(void); Modified: trunk/ecore/src/lib/ecore/ecore_thread.c =================================================================== --- trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-23 15:33:22 UTC (rev 50453) +++ trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-23 16:24:35 UTC (rev 50454) @@ -925,6 +925,47 @@ } /** + * @brief Find data in the pool data and optionally wait for the data if not found + * @param key The name string the data is associated with + * @param seconds The amount of time in seconds to wait for the data. If 0, the call will be async and not wait for data. + * If < 0 the call will wait indefinitely for the data. + * @return The value, or NULL on failure + * This finds data in the pool data that has been previously added with @ref ecore_thread_pool_data_add + * This function will return NULL in any case but success. + * Use @p seconds to specify the amount of time to wait. Use > 0 for an actual wait time, 0 to not wait, and < 0 to wait indefinitely. + */ +EAPI void * +ecore_thread_pool_data_wait(const char *key, double seconds) +{ + double time = 0; + void *ret; + Ecore_Pthread_Worker *worker = (Ecore_Pthread_Worker *) thread; + if ((!thread) || (!key)) + return NULL; +#ifdef EFL_HAVE_PTHREAD + if (worker->self != pthread_self()) return NULL; + if (seconds > 0) + time = ecore_time_get() + seconds; + + while (1) + { + ret = eina_hash_find(thread->hash, key); + if ((ret) || (!seconds) || ((seconds > 0) && (time <= ecore_time_get()))) + break; + //try to sleep for a reasonable amount of time + if (time) + usleep((seconds * 1000000) / 2); + else + usleep(1000000); + } + return ret; +#else + return NULL; +#endif +} + + +/** * @brief Add data to the global data * @param key The name string to add the data with * @param value The data to add @@ -1046,7 +1087,48 @@ #endif } +/** + * @brief Find data in the global data and optionally wait for the data if not found + * @param key The name string the data is associated with + * @param seconds The amount of time in seconds to wait for the data. If 0, the call will be async and not wait for data. + * If < 0 the call will wait indefinitely for the data. + * @return The value, or NULL on failure + * This finds data in the global data that has been previously added with @ref ecore_thread_global_data_add + * This function will return NULL in any case but success. + * Use @p seconds to specify the amount of time to wait. Use > 0 for an actual wait time, 0 to not wait, and < 0 to wait indefinitely. + */ +EAPI void * +ecore_thread_global_data_wait(const char *key, double seconds) +{ + double time = 0; + void *ret = NULL; + if (!key) + return NULL; +#ifdef EFL_HAVE_PTHREAD + if (!_ecore_thread_global_hash) + return NULL; + if (seconds > 0) + time = ecore_time_get() + seconds; + while (1) + { + pthread_rwlock_rdlock(&_ecore_thread_global_hash_lock); + ret = eina_hash_find(_ecore_thread_global_hash, key); + pthread_rwlock_unlock(&_ecore_thread_global_hash_lock); + if ((ret) || (!seconds) || ((seconds > 0) && (time <= ecore_time_get()))) + break; + //try to sleep for a reasonable amount of time + if (time) + usleep((seconds * 1000000) / 2); + else + usleep(1000000); + } + return ret; +#else + return NULL; +#endif +} + /** * @} */ |
From: Enlightenment S. <no-...@en...> - 2010-07-23 16:40:46
|
Log: whoops Author: discomfitor Date: 2010-07-23 09:40:40 -0700 (Fri, 23 Jul 2010) New Revision: 50455 Modified: trunk/ecore/src/lib/ecore/Ecore.h trunk/ecore/src/lib/ecore/ecore_thread.c Modified: trunk/ecore/src/lib/ecore/Ecore.h =================================================================== --- trunk/ecore/src/lib/ecore/Ecore.h 2010-07-23 16:24:35 UTC (rev 50454) +++ trunk/ecore/src/lib/ecore/Ecore.h 2010-07-23 16:40:40 UTC (rev 50455) @@ -365,6 +365,7 @@ const void *value); EAPI void *ecore_thread_pool_data_find(Ecore_Thread *thread, const char *key); EAPI Eina_Bool ecore_thread_pool_data_del(Ecore_Thread *thread, const char *key); + EAPI void *ecore_thread_pool_data_wait(Ecore_Thread *thread, const char *key, double seconds); EAPI Eina_Bool ecore_thread_global_data_add(const char *key, const void *value, Eina_Bool direct); Modified: trunk/ecore/src/lib/ecore/ecore_thread.c =================================================================== --- trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-23 16:24:35 UTC (rev 50454) +++ trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-23 16:40:40 UTC (rev 50455) @@ -935,7 +935,7 @@ * Use @p seconds to specify the amount of time to wait. Use > 0 for an actual wait time, 0 to not wait, and < 0 to wait indefinitely. */ EAPI void * -ecore_thread_pool_data_wait(const char *key, double seconds) +ecore_thread_pool_data_wait(Ecore_Thread *thread, const char *key, double seconds) { double time = 0; void *ret; @@ -949,7 +949,7 @@ while (1) { - ret = eina_hash_find(thread->hash, key); + ret = eina_hash_find(worker->hash, key); if ((ret) || (!seconds) || ((seconds > 0) && (time <= ecore_time_get()))) break; //try to sleep for a reasonable amount of time |
From: Enlightenment S. <no-...@en...> - 2010-07-23 17:30:29
|
Log: fix leak in thread_shutdown, use lots of mutexes and conditionals instead of sleeps to wait in data_wait functions Author: discomfitor Date: 2010-07-23 10:30:21 -0700 (Fri, 23 Jul 2010) New Revision: 50459 Modified: trunk/ecore/src/lib/ecore/ecore_thread.c Modified: trunk/ecore/src/lib/ecore/ecore_thread.c =================================================================== --- trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-23 17:22:52 UTC (rev 50458) +++ trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-23 17:30:21 UTC (rev 50459) @@ -37,6 +37,8 @@ #ifdef EFL_HAVE_PTHREAD pthread_t self; Eina_Hash *hash; + pthread_cond_t cond; + pthread_mutex_t mutex; #endif const void *data; @@ -70,6 +72,8 @@ static Eina_Hash *_ecore_thread_global_hash = NULL; static pthread_rwlock_t _ecore_thread_global_hash_lock = PTHREAD_RWLOCK_INITIALIZER; +static pthread_mutex_t _ecore_thread_global_hash_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_cond_t _ecore_thread_global_hash_cond = PTHREAD_COND_INITIALIZER; static void _ecore_thread_pipe_free(void *data __UNUSED__, void *event) { @@ -120,7 +124,8 @@ if (work->long_run) ecore_pipe_del(work->u.long_run.notify); - + pthread_cond_destroy(&work->cond); + pthread_mutex_destroy(&work->mutex); eina_hash_free(work->hash); free(work); } @@ -328,7 +333,7 @@ ecore_pipe_del(pth->p); } - + eina_hash_free(_ecore_thread_global_hash); ecore_event_handler_del(del_handler); del_handler = NULL; #endif @@ -379,6 +384,9 @@ } work->u.short_run.func_blocking = func_blocking; + work->hash = NULL; + pthread_cond_init(&work->cond, NULL); + pthread_mutex_init(&work->mutex, NULL); work->func_end = func_end; work->func_cancel = func_cancel; work->cancel = EINA_FALSE; @@ -547,6 +555,8 @@ worker->u.long_run.func_heavy = func_heavy; worker->u.long_run.func_notify = func_notify; worker->hash = NULL; + pthread_cond_init(&worker->cond, NULL); + pthread_mutex_init(&worker->mutex, NULL); worker->func_cancel = func_cancel; worker->func_end = func_end; worker->data = data; @@ -616,6 +626,8 @@ worker.u.long_run.func_heavy = func_heavy; worker.u.long_run.func_notify = func_notify; worker->hash = NULL; + pthread_cond_init(&worker->cond, NULL); + pthread_mutex_init(&worker->mutex, NULL); worker.u.long_run.notify = NULL; worker.func_cancel = func_cancel; worker.func_end = func_end; @@ -818,6 +830,8 @@ ecore_thread_pool_data_add(Ecore_Thread *thread, const char *key, const void *value, Eina_Bool direct) { Ecore_Pthread_Worker *worker = (Ecore_Pthread_Worker *) thread; + Eina_Bool ret; + if ((!thread) || (!key) || (!value)) return EINA_FALSE; #ifdef EFL_HAVE_PTHREAD @@ -829,6 +843,13 @@ if (!worker->hash) return EINA_FALSE; if (direct) + ret = eina_hash_direct_add(worker->hash, key, value); + else + ret = eina_hash_add(worker->hash, key, value); + pthread_cond_broadcast(&worker->cond); + return ret; + + if (direct) return eina_hash_direct_add(worker->hash, key, value); return eina_hash_add(worker->hash, key, value); #else @@ -852,6 +873,7 @@ ecore_thread_pool_data_set(Ecore_Thread *thread, const char *key, const void *value) { Ecore_Pthread_Worker *worker = (Ecore_Pthread_Worker *) thread; + void *ret; if ((!thread) || (!key) || (!value)) return NULL; #ifdef EFL_HAVE_PTHREAD @@ -863,7 +885,9 @@ if (!worker->hash) return NULL; - return eina_hash_set(worker->hash, key, value); + ret = eina_hash_set(worker->hash, key, value); + pthread_cond_broadcast(&worker->cond); + return ret; #else return NULL; #endif @@ -952,11 +976,9 @@ ret = eina_hash_find(worker->hash, key); if ((ret) || (!seconds) || ((seconds > 0) && (time <= ecore_time_get()))) break; - //try to sleep for a reasonable amount of time - if (time) - usleep((seconds * 1000000) / 2); - else - usleep(1000000); + pthread_mutex_lock(&worker->mutex); + pthread_cond_wait(&worker->cond, &worker->mutex); + pthread_mutex_unlock(&worker->mutex); } return ret; #else @@ -994,6 +1016,7 @@ else ret = eina_hash_add(_ecore_thread_global_hash, key, value); pthread_rwlock_unlock(&_ecore_thread_global_hash_lock); + pthread_cond_broadcast(&_ecore_thread_global_hash_cond); return ret; #else return EINA_TRUE; @@ -1028,6 +1051,7 @@ pthread_rwlock_wrlock(&_ecore_thread_global_hash_lock); ret = eina_hash_set(_ecore_thread_global_hash, key, value); pthread_rwlock_unlock(&_ecore_thread_global_hash_lock); + pthread_cond_broadcast(&_ecore_thread_global_hash_cond); return ret; #else return NULL; @@ -1117,11 +1141,9 @@ pthread_rwlock_unlock(&_ecore_thread_global_hash_lock); if ((ret) || (!seconds) || ((seconds > 0) && (time <= ecore_time_get()))) break; - //try to sleep for a reasonable amount of time - if (time) - usleep((seconds * 1000000) / 2); - else - usleep(1000000); + pthread_mutex_lock(&_ecore_thread_global_hash_mutex); + pthread_cond_wait(&_ecore_thread_global_hash_cond, &_ecore_thread_global_hash_mutex); + pthread_mutex_unlock(&_ecore_thread_global_hash_mutex); } return ret; #else |
From: Enlightenment S. <no-...@en...> - 2010-07-23 17:52:59
|
Log: shut up eina Author: discomfitor Date: 2010-07-23 10:52:50 -0700 (Fri, 23 Jul 2010) New Revision: 50460 Modified: trunk/ecore/src/lib/ecore/ecore_thread.c Modified: trunk/ecore/src/lib/ecore/ecore_thread.c =================================================================== --- trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-23 17:30:21 UTC (rev 50459) +++ trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-23 17:52:50 UTC (rev 50460) @@ -126,7 +126,8 @@ ecore_pipe_del(work->u.long_run.notify); pthread_cond_destroy(&work->cond); pthread_mutex_destroy(&work->mutex); - eina_hash_free(work->hash); + if (work->hash) + eina_hash_free(work->hash); free(work); } @@ -333,7 +334,8 @@ ecore_pipe_del(pth->p); } - eina_hash_free(_ecore_thread_global_hash); + if (_ecore_thread_global_hash) + eina_hash_free(_ecore_thread_global_hash); ecore_event_handler_del(del_handler); del_handler = NULL; #endif |
From: Enlightenment S. <no-...@en...> - 2010-07-23 22:28:25
|
Log: correctly init some variables that I missed somehow. I blame Sachiel. Author: discomfitor Date: 2010-07-23 15:28:18 -0700 (Fri, 23 Jul 2010) New Revision: 50465 Modified: trunk/ecore/src/lib/ecore/ecore_thread.c Modified: trunk/ecore/src/lib/ecore/ecore_thread.c =================================================================== --- trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-23 21:56:25 UTC (rev 50464) +++ trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-23 22:28:18 UTC (rev 50465) @@ -236,6 +236,9 @@ work->func_cancel = NULL; work->cancel = EINA_FALSE; work->long_run = EINA_FALSE; + work->hash = NULL; + pthread_cond_init(&work->cond, NULL); + pthread_mutex_init(&work->mutex, NULL); ecore_pipe_write(pth->p, &work, sizeof (Ecore_Pthread_Worker *)); @@ -285,6 +288,9 @@ work->func_cancel = NULL; work->cancel = EINA_FALSE; work->long_run = EINA_FALSE; + work->hash = NULL; + pthread_cond_init(&work->cond, NULL); + pthread_mutex_init(&work->mutex, NULL); ecore_pipe_write(pth->p, &work, sizeof (Ecore_Pthread_Worker *)); |
From: Enlightenment S. <no-...@en...> - 2010-07-24 02:05:42
|
Log: fix longstanding leak Author: discomfitor Date: 2010-07-23 19:05:35 -0700 (Fri, 23 Jul 2010) New Revision: 50470 Modified: trunk/ecore/src/lib/ecore/ecore_thread.c Modified: trunk/ecore/src/lib/ecore/ecore_thread.c =================================================================== --- trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-24 02:04:53 UTC (rev 50469) +++ trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-24 02:05:35 UTC (rev 50470) @@ -100,6 +100,7 @@ _ecore_active_job_threads = eina_list_remove(_ecore_active_job_threads, pth); ecore_event_add(ECORE_THREAD_PIPE_DEL, pth->p, _ecore_thread_pipe_free, NULL); + free(pth); } static void |
From: Enlightenment S. <no-...@en...> - 2010-07-26 04:20:27
|
Log: add typedefs for ecore thread function types because I'm tired of typing them out Author: discomfitor Date: 2010-07-25 21:20:18 -0700 (Sun, 25 Jul 2010) New Revision: 50499 Modified: trunk/ecore/src/lib/ecore/Ecore.h trunk/ecore/src/lib/ecore/ecore_thread.c Modified: trunk/ecore/src/lib/ecore/Ecore.h =================================================================== --- trunk/ecore/src/lib/ecore/Ecore.h 2010-07-26 03:17:40 UTC (rev 50498) +++ trunk/ecore/src/lib/ecore/Ecore.h 2010-07-26 04:20:18 UTC (rev 50499) @@ -167,7 +167,14 @@ typedef struct _Ecore_Exe_Event_Data_Line Ecore_Exe_Event_Data_Line; /**< Lines from a child process */ typedef struct _Ecore_Exe_Event_Data Ecore_Exe_Event_Data; /**< Data from a child process */ typedef struct _Ecore_Thread Ecore_Thread; + typedef void (*Ecore_Thread_Func_Blocking) (void *data); + typedef void (*Ecore_Thread_Func_End) (void *data); + typedef void (*Ecore_Thread_Func_Cancel) (void *data); + typedef void (*Ecore_Thread_Func_Heavy) (Ecore_Thread *thread, void *data); + typedef void (*Ecore_Thread_Func_Notify) (Ecore_Thread *thread, void *msg_data, void *data); + + typedef struct _Ecore_Job Ecore_Job; /**< A job handle */ struct _Ecore_Event_Signal_User /** User signal event */ @@ -335,18 +342,16 @@ EAPI void ecore_pipe_write_close(Ecore_Pipe *p); EAPI void ecore_pipe_read_close(Ecore_Pipe *p); - EAPI Ecore_Thread *ecore_thread_run(void (*func_blocking)(void *data), - void (*func_end)(void *data), - void (*func_cancel)(void *data), + EAPI Ecore_Thread *ecore_thread_run(Ecore_Thread_Func_Blocking, + Ecore_Thread_Func_End, + Ecore_Thread_Func_Cancel, const void *data); - EAPI Ecore_Thread *ecore_long_run(void (*func_heavy)(Ecore_Thread *thread, - void *data), - void (*func_notify)(Ecore_Thread *thread, - void *msg_data, void *data), - void (*func_end)(void *data), - void (*func_cancel)(void *data), - const void *data, - Eina_Bool try_no_queue); + EAPI Ecore_Thread *ecore_long_run(Ecore_Thread_Func_Heavy, + Ecore_Thread_Func_Notify, + Ecore_Thread_Func_End, + Ecore_Thread_Func_Cancel, + 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); Modified: trunk/ecore/src/lib/ecore/ecore_thread.c =================================================================== --- trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-26 03:17:40 UTC (rev 50498) +++ trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-26 04:20:18 UTC (rev 50499) @@ -374,10 +374,10 @@ * host CPU can handle. */ EAPI Ecore_Thread * -ecore_thread_run(void (*func_blocking)(void *data), - void (*func_end)(void *data), - void (*func_cancel)(void *data), - const void *data) +ecore_thread_run(Ecore_Thread_Func_Blocking, + Ecore_Thread_Func_End, + Ecore_Thread_Func_Cancel, + const void *data) { #ifdef EFL_HAVE_PTHREAD Ecore_Pthread_Worker *work; @@ -543,13 +543,12 @@ * the CPU down, so be carefull 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(void (*func_heavy)(Ecore_Thread *thread, void *data), - void (*func_notify)(Ecore_Thread *thread, void *msg_data, void *data), - void (*func_end)(void *data), - void (*func_cancel)(void *data), - const void *data, - Eina_Bool try_no_queue) +EAPI Ecore_Thread *ecore_long_run(Ecore_Thread_Func_Heavy, + Ecore_Thread_Func_Notify, + Ecore_Thread_Func_End, + Ecore_Thread_Func_Cancel, + const void *data, + Eina_Bool try_no_queue) { #ifdef EFL_HAVE_PTHREAD |
From: Enlightenment S. <no-...@en...> - 2010-07-26 05:47:40
|
Log: whoops Author: discomfitor Date: 2010-07-25 22:47:33 -0700 (Sun, 25 Jul 2010) New Revision: 50504 Modified: trunk/ecore/src/lib/ecore/ecore_thread.c Modified: trunk/ecore/src/lib/ecore/ecore_thread.c =================================================================== --- trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-26 05:37:36 UTC (rev 50503) +++ trunk/ecore/src/lib/ecore/ecore_thread.c 2010-07-26 05:47:33 UTC (rev 50504) @@ -374,9 +374,9 @@ * host CPU can handle. */ EAPI Ecore_Thread * -ecore_thread_run(Ecore_Thread_Func_Blocking, - Ecore_Thread_Func_End, - Ecore_Thread_Func_Cancel, +ecore_thread_run(Ecore_Thread_Func_Blocking func_blocking, + Ecore_Thread_Func_End func_end, + Ecore_Thread_Func_Cancel func_cancel, const void *data) { #ifdef EFL_HAVE_PTHREAD @@ -543,10 +543,10 @@ * the CPU down, so be carefull 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_Func_Heavy, - Ecore_Thread_Func_Notify, - Ecore_Thread_Func_End, - Ecore_Thread_Func_Cancel, +EAPI Ecore_Thread *ecore_long_run(Ecore_Thread_Func_Heavy func_heavy, + Ecore_Thread_Func_Notify func_notify, + Ecore_Thread_Func_End func_end, + Ecore_Thread_Func_Cancel func_cancel, const void *data, Eina_Bool try_no_queue) { |