#ifdef EFL_HAVE_PTHREAD
pthread_t self;
Eina_Hash *hash;
+ pthread_cond_t cond;
+ pthread_mutex_t mutex;
#endif
const void *data;
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)
{
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);
}
ecore_pipe_del(pth->p);
}
-
+ eina_hash_free(_ecore_thread_global_hash);
ecore_event_handler_del(del_handler);
del_handler = NULL;
#endif
}
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;
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;
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;
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
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
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
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
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
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;
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;
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