{
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;
}
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);
}
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 *));
}
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 *));
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;
*/
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;
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 *));
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
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;
}
/* 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);
}
/**
EAPI void
ecore_thread_max_reset(void)
{
- pthread_mutex_lock(&_mutex);
_ecore_thread_count_max = eina_cpu_count();
- pthread_mutex_unlock(&_mutex);
}
/**
* @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.
*/
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
* @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
* @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.
*/
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
* @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
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