efl: cleanup HAVE_THREADS and pthread usage outside of eina.

Eina now abstracts threads, so use that.

the touched files had the EFL_HAVE_THREADS as it's mandatory now.



SVN revision: 81935
This commit is contained in:
Gustavo Sverzut Barbieri 2012-12-31 16:14:40 +00:00
parent 12e0602452
commit 4668d04f04
7 changed files with 67 additions and 399 deletions

View File

@ -18,8 +18,6 @@
#include "Ecore.h" #include "Ecore.h"
#include "ecore_private.h" #include "ecore_private.h"
#ifdef EFL_HAVE_THREADS
# define LK(x) Eina_Lock x # define LK(x) Eina_Lock x
# define LKI(x) eina_lock_new(&(x)) # define LKI(x) eina_lock_new(&(x))
# define LKD(x) eina_lock_free(&(x)) # define LKD(x) eina_lock_free(&(x))
@ -45,26 +43,6 @@
# define PHC(x, f, d) eina_thread_create(&(x), EINA_THREAD_BACKGROUND, -1, (void *)f, d) # define PHC(x, f, d) eina_thread_create(&(x), EINA_THREAD_BACKGROUND, -1, (void *)f, d)
# define PHJ(x) eina_thread_join(x) # define PHJ(x) eina_thread_join(x)
# ifdef EFL_HAVE_POSIX_THREADS
# include <pthread.h>
# ifdef __linux__
# include <sched.h>
# include <sys/resource.h>
# include <unistd.h>
# include <sys/syscall.h>
# include <errno.h>
# endif
# else /* EFL_HAVE_WIN32_THREADS */
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# undef WIN32_LEAN_AND_MEAN
# endif
#endif
typedef struct _Ecore_Pthread_Worker Ecore_Pthread_Worker; typedef struct _Ecore_Pthread_Worker Ecore_Pthread_Worker;
typedef struct _Ecore_Pthread Ecore_Pthread; typedef struct _Ecore_Pthread Ecore_Pthread;
typedef struct _Ecore_Thread_Data Ecore_Thread_Data; typedef struct _Ecore_Thread_Data Ecore_Thread_Data;
@ -108,20 +86,16 @@ struct _Ecore_Pthread_Worker
Ecore_Thread_Cb func_cancel; Ecore_Thread_Cb func_cancel;
Ecore_Thread_Cb func_end; Ecore_Thread_Cb func_end;
#ifdef EFL_HAVE_THREADS
PH(self); PH(self);
Eina_Hash *hash; Eina_Hash *hash;
CD(cond); CD(cond);
LK(mutex); LK(mutex);
#endif
const void *data; const void *data;
int cancel; int cancel;
#ifdef EFL_HAVE_THREADS
LK(cancel_mutex); LK(cancel_mutex);
#endif
Eina_Bool message_run : 1; Eina_Bool message_run : 1;
Eina_Bool feedback_run : 1; Eina_Bool feedback_run : 1;
@ -130,7 +104,6 @@ struct _Ecore_Pthread_Worker
Eina_Bool no_queue : 1; Eina_Bool no_queue : 1;
}; };
#ifdef EFL_HAVE_THREADS
typedef struct _Ecore_Pthread_Notify Ecore_Pthread_Notify; typedef struct _Ecore_Pthread_Notify Ecore_Pthread_Notify;
struct _Ecore_Pthread_Notify struct _Ecore_Pthread_Notify
{ {
@ -156,12 +129,8 @@ struct _Ecore_Pthread_Message
Eina_Bool sync : 1; Eina_Bool sync : 1;
}; };
#endif
static int _ecore_thread_count_max = 0; static int _ecore_thread_count_max = 0;
#ifdef EFL_HAVE_THREADS
static void _ecore_thread_handler(void *data); static void _ecore_thread_handler(void *data);
static int _ecore_thread_count = 0; static int _ecore_thread_count = 0;
@ -498,12 +467,9 @@ restart:
return NULL; return NULL;
} }
#endif
static Ecore_Pthread_Worker * static Ecore_Pthread_Worker *
_ecore_thread_worker_new(void) _ecore_thread_worker_new(void)
{ {
#ifdef EFL_HAVE_THREADS
Ecore_Pthread_Worker *result; Ecore_Pthread_Worker *result;
result = eina_trash_pop(&_ecore_thread_worker_trash); result = eina_trash_pop(&_ecore_thread_worker_trash);
@ -519,9 +485,6 @@ _ecore_thread_worker_new(void)
CDI(result->cond, result->mutex); CDI(result->cond, result->mutex);
return result; return result;
#else
return malloc(sizeof (Ecore_Pthread_Worker));
#endif
} }
void void
@ -531,20 +494,17 @@ _ecore_thread_init(void)
if (_ecore_thread_count_max <= 0) if (_ecore_thread_count_max <= 0)
_ecore_thread_count_max = 1; _ecore_thread_count_max = 1;
#ifdef EFL_HAVE_THREADS
LKI(_ecore_pending_job_threads_mutex); LKI(_ecore_pending_job_threads_mutex);
LRWKI(_ecore_thread_global_hash_lock); LRWKI(_ecore_thread_global_hash_lock);
LKI(_ecore_thread_global_hash_mutex); LKI(_ecore_thread_global_hash_mutex);
LKI(_ecore_running_job_mutex); LKI(_ecore_running_job_mutex);
CDI(_ecore_thread_global_hash_cond, _ecore_thread_global_hash_mutex); CDI(_ecore_thread_global_hash_cond, _ecore_thread_global_hash_mutex);
#endif
} }
void void
_ecore_thread_shutdown(void) _ecore_thread_shutdown(void)
{ {
/* FIXME: If function are still running in the background, should we kill them ? */ /* FIXME: If function are still running in the background, should we kill them ? */
#ifdef EFL_HAVE_THREADS
Ecore_Pthread_Worker *work; Ecore_Pthread_Worker *work;
Eina_List *l; Eina_List *l;
Eina_Bool test; Eina_Bool test;
@ -610,7 +570,6 @@ _ecore_thread_shutdown(void)
LKD(_ecore_thread_global_hash_mutex); LKD(_ecore_thread_global_hash_mutex);
LKD(_ecore_running_job_mutex); LKD(_ecore_running_job_mutex);
CDD(_ecore_thread_global_hash_cond); CDD(_ecore_thread_global_hash_cond);
#endif
} }
EAPI Ecore_Thread * EAPI Ecore_Thread *
@ -621,12 +580,10 @@ ecore_thread_run(Ecore_Thread_Cb func_blocking,
{ {
Ecore_Pthread_Worker *work; Ecore_Pthread_Worker *work;
Eina_Bool tried = EINA_FALSE; Eina_Bool tried = EINA_FALSE;
#ifdef EFL_HAVE_THREADS
PH(thread); PH(thread);
#endif
EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL); EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
if (!func_blocking) return NULL; if (!func_blocking) return NULL;
work = _ecore_thread_worker_new(); work = _ecore_thread_worker_new();
@ -648,7 +605,6 @@ ecore_thread_run(Ecore_Thread_Cb func_blocking,
work->no_queue = EINA_FALSE; work->no_queue = EINA_FALSE;
work->data = data; work->data = data;
#ifdef EFL_HAVE_THREADS
work->self = 0; work->self = 0;
work->hash = NULL; work->hash = NULL;
@ -697,33 +653,11 @@ ecore_thread_run(Ecore_Thread_Cb func_blocking,
eina_threads_shutdown(); eina_threads_shutdown();
return (Ecore_Thread *)work; return (Ecore_Thread *)work;
#else
/*
If no thread and as we don't want to break app that rely on this
facility, we will lock the interface until we are done.
*/
do {
/* Handle reschedule by forcing it here. That would mean locking the app,
* would be better with an idler, but really to complex for a case where
* thread should really exist.
*/
work->reschedule = EINA_FALSE;
func_blocking((void *)data, (Ecore_Thread *)work);
if (work->cancel == EINA_FALSE) func_end((void *)data, (Ecore_Thread *)work);
else func_cancel((void *)data, (Ecore_Thread *)work);
} while (work->reschedule == EINA_TRUE);
free(work);
return NULL;
#endif
} }
EAPI Eina_Bool EAPI Eina_Bool
ecore_thread_cancel(Ecore_Thread *thread) ecore_thread_cancel(Ecore_Thread *thread)
{ {
#ifdef EFL_HAVE_THREADS
Ecore_Pthread_Worker *volatile work = (Ecore_Pthread_Worker *)thread; Ecore_Pthread_Worker *volatile work = (Ecore_Pthread_Worker *)thread;
Eina_List *l; Eina_List *l;
int cancel; int cancel;
@ -794,10 +728,6 @@ ecore_thread_cancel(Ecore_Thread *thread)
LKU(work->cancel_mutex); LKU(work->cancel_mutex);
return EINA_FALSE; return EINA_FALSE;
#else
(void) thread;
return EINA_TRUE;
#endif
} }
EAPI Eina_Bool EAPI Eina_Bool
@ -807,18 +737,15 @@ ecore_thread_check(Ecore_Thread *thread)
int cancel; int cancel;
if (!worker) return EINA_TRUE; if (!worker) return EINA_TRUE;
#ifdef EFL_HAVE_THREADS
LKL(worker->cancel_mutex); LKL(worker->cancel_mutex);
#endif
cancel = worker->cancel; cancel = worker->cancel;
/* FIXME: there is an insane bug driving me nuts here. I don't know if /* FIXME: there is an insane bug driving me nuts here. I don't know if
it's a race condition, some cache issue or some alien attack on our software. it's a race condition, some cache issue or some alien attack on our software.
But ecore_thread_check will only work correctly with a printf, all the volatile, But ecore_thread_check will only work correctly with a printf, all the volatile,
lock and even usleep don't help here... */ lock and even usleep don't help here... */
/* fprintf(stderr, "wc: %i\n", cancel); */ /* fprintf(stderr, "wc: %i\n", cancel); */
#ifdef EFL_HAVE_THREADS
LKU(worker->cancel_mutex); LKU(worker->cancel_mutex);
#endif
return cancel; return cancel;
} }
@ -830,13 +757,12 @@ ecore_thread_feedback_run(Ecore_Thread_Cb func_heavy,
const void *data, const void *data,
Eina_Bool try_no_queue) Eina_Bool try_no_queue)
{ {
#ifdef EFL_HAVE_THREADS
Ecore_Pthread_Worker *worker; Ecore_Pthread_Worker *worker;
Eina_Bool tried = EINA_FALSE; Eina_Bool tried = EINA_FALSE;
PH(thread); PH(thread);
EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL); EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
if (!func_heavy) return NULL; if (!func_heavy) return NULL;
worker = _ecore_thread_worker_new(); worker = _ecore_thread_worker_new();
@ -942,38 +868,6 @@ on_error:
LKU(_ecore_pending_job_threads_mutex); LKU(_ecore_pending_job_threads_mutex);
return (Ecore_Thread *)worker; return (Ecore_Thread *)worker;
#else
Ecore_Pthread_Worker worker;
(void)try_no_queue;
/*
If no thread and as we don't want to break app that rely on this
facility, we will lock the interface until we are done.
*/
worker.u.feedback_run.func_heavy = func_heavy;
worker.u.feedback_run.func_notify = func_notify;
worker.u.feedback_run.send = 0;
worker.u.feedback_run.received = 0;
worker.func_cancel = func_cancel;
worker.func_end = func_end;
worker.data = data;
worker.cancel = EINA_FALSE;
worker.feedback_run = EINA_TRUE;
worker.message_run = EINA_FALSE;
worker.kill = EINA_FALSE;
do {
worker.reschedule = EINA_FALSE;
func_heavy((void *)data, (Ecore_Thread *)&worker);
if (worker.cancel) func_cancel((void *)data, (Ecore_Thread *)&worker);
else func_end((void *)data, (Ecore_Thread *)&worker);
} while (worker.reschedule == EINA_TRUE);
return NULL;
#endif
} }
EAPI Eina_Bool EAPI Eina_Bool
@ -984,7 +878,6 @@ ecore_thread_feedback(Ecore_Thread *thread,
if (!worker) return EINA_FALSE; if (!worker) return EINA_FALSE;
#ifdef EFL_HAVE_THREADS
if (!PHE(worker->self, PHS())) return EINA_FALSE; if (!PHE(worker->self, PHS())) return EINA_FALSE;
if (worker->feedback_run) if (worker->feedback_run)
@ -1027,11 +920,6 @@ ecore_thread_feedback(Ecore_Thread *thread,
return EINA_FALSE; return EINA_FALSE;
return EINA_TRUE; return EINA_TRUE;
#else
worker->u.feedback_run.func_notify((void *)worker->data, thread, (void *)data);
return EINA_TRUE;
#endif
} }
#if 0 #if 0
@ -1042,7 +930,6 @@ ecore_thread_message_run(Ecore_Thread_Cb func_main,
Ecore_Thread_Cb func_cancel, Ecore_Thread_Cb func_cancel,
const void *data) const void *data)
{ {
#ifdef EFL_HAVE_THREADS
Ecore_Pthread_Worker *worker; Ecore_Pthread_Worker *worker;
PH(t); PH(t);
@ -1087,11 +974,6 @@ ecore_thread_message_run(Ecore_Thread_Cb func_main,
CDD(worker->cond); CDD(worker->cond);
LKD(worker->mutex); LKD(worker->mutex);
#else
/* Note: This type of thread can't and never will work without thread support */
WRN("ecore_thread_message_run called, but threads disable in Ecore, things will go wrong. Starting now !");
# warning "You disabled threads support in ecore, I hope you know what you are doing !"
#endif
func_cancel((void *) data, NULL); func_cancel((void *) data, NULL);
@ -1106,9 +988,7 @@ ecore_thread_reschedule(Ecore_Thread *thread)
if (!worker) return EINA_FALSE; if (!worker) return EINA_FALSE;
#ifdef EFL_HAVE_THREADS
if (!PHE(worker->self, PHS())) return EINA_FALSE; if (!PHE(worker->self, PHS())) return EINA_FALSE;
#endif
worker->reschedule = EINA_TRUE; worker->reschedule = EINA_TRUE;
return EINA_TRUE; return EINA_TRUE;
@ -1117,18 +997,13 @@ ecore_thread_reschedule(Ecore_Thread *thread)
EAPI int EAPI int
ecore_thread_active_get(void) ecore_thread_active_get(void)
{ {
#ifdef EFL_HAVE_THREADS
EINA_MAIN_LOOP_CHECK_RETURN_VAL(0); EINA_MAIN_LOOP_CHECK_RETURN_VAL(0);
return _ecore_thread_count; return _ecore_thread_count;
#else
return 0;
#endif
} }
EAPI int EAPI int
ecore_thread_pending_get(void) ecore_thread_pending_get(void)
{ {
#ifdef EFL_HAVE_THREADS
int ret; int ret;
EINA_MAIN_LOOP_CHECK_RETURN_VAL(0); EINA_MAIN_LOOP_CHECK_RETURN_VAL(0);
@ -1136,15 +1011,11 @@ ecore_thread_pending_get(void)
ret = eina_list_count(_ecore_pending_job_threads); ret = eina_list_count(_ecore_pending_job_threads);
LKU(_ecore_pending_job_threads_mutex); LKU(_ecore_pending_job_threads_mutex);
return ret; return ret;
#else
return 0;
#endif
} }
EAPI int EAPI int
ecore_thread_pending_feedback_get(void) ecore_thread_pending_feedback_get(void)
{ {
#ifdef EFL_HAVE_THREADS
int ret; int ret;
EINA_MAIN_LOOP_CHECK_RETURN_VAL(0); EINA_MAIN_LOOP_CHECK_RETURN_VAL(0);
@ -1152,15 +1023,11 @@ ecore_thread_pending_feedback_get(void)
ret = eina_list_count(_ecore_pending_job_threads_feedback); ret = eina_list_count(_ecore_pending_job_threads_feedback);
LKU(_ecore_pending_job_threads_mutex); LKU(_ecore_pending_job_threads_mutex);
return ret; return ret;
#else
return 0;
#endif
} }
EAPI int EAPI int
ecore_thread_pending_total_get(void) ecore_thread_pending_total_get(void)
{ {
#ifdef EFL_HAVE_THREADS
int ret; int ret;
EINA_MAIN_LOOP_CHECK_RETURN_VAL(0); EINA_MAIN_LOOP_CHECK_RETURN_VAL(0);
@ -1168,9 +1035,6 @@ ecore_thread_pending_total_get(void)
ret = eina_list_count(_ecore_pending_job_threads) + eina_list_count(_ecore_pending_job_threads_feedback); ret = eina_list_count(_ecore_pending_job_threads) + eina_list_count(_ecore_pending_job_threads_feedback);
LKU(_ecore_pending_job_threads_mutex); LKU(_ecore_pending_job_threads_mutex);
return ret; return ret;
#else
return 0;
#endif
} }
EAPI int EAPI int
@ -1201,16 +1065,12 @@ ecore_thread_max_reset(void)
EAPI int EAPI int
ecore_thread_available_get(void) ecore_thread_available_get(void)
{ {
#ifdef EFL_HAVE_THREADS
int ret; int ret;
LKL(_ecore_pending_job_threads_mutex); LKL(_ecore_pending_job_threads_mutex);
ret = _ecore_thread_count_max - _ecore_thread_count; ret = _ecore_thread_count_max - _ecore_thread_count;
LKU(_ecore_pending_job_threads_mutex); LKU(_ecore_pending_job_threads_mutex);
return ret; return ret;
#else
return 0;
#endif
} }
EAPI Eina_Bool EAPI Eina_Bool
@ -1220,15 +1080,13 @@ ecore_thread_local_data_add(Ecore_Thread *thread,
Eina_Free_Cb cb, Eina_Free_Cb cb,
Eina_Bool direct) Eina_Bool direct)
{ {
#ifdef EFL_HAVE_THREADS
Ecore_Pthread_Worker *worker = (Ecore_Pthread_Worker *)thread; Ecore_Pthread_Worker *worker = (Ecore_Pthread_Worker *)thread;
Ecore_Thread_Data *d; Ecore_Thread_Data *d;
Eina_Bool ret; Eina_Bool ret;
#endif
if ((!thread) || (!key) || (!value)) if ((!thread) || (!key) || (!value))
return EINA_FALSE; return EINA_FALSE;
#ifdef EFL_HAVE_THREADS
if (!PHE(worker->self, PHS())) return EINA_FALSE; if (!PHE(worker->self, PHS())) return EINA_FALSE;
if (!worker->hash) if (!worker->hash)
@ -1249,11 +1107,6 @@ ecore_thread_local_data_add(Ecore_Thread *thread,
ret = eina_hash_add(worker->hash, key, d); ret = eina_hash_add(worker->hash, key, d);
CDB(worker->cond); CDB(worker->cond);
return ret; return ret;
#else
(void) cb;
(void) direct;
return EINA_FALSE;
#endif
} }
EAPI void * EAPI void *
@ -1262,15 +1115,13 @@ ecore_thread_local_data_set(Ecore_Thread *thread,
void *value, void *value,
Eina_Free_Cb cb) Eina_Free_Cb cb)
{ {
#ifdef EFL_HAVE_THREADS
Ecore_Pthread_Worker *worker = (Ecore_Pthread_Worker *)thread; Ecore_Pthread_Worker *worker = (Ecore_Pthread_Worker *)thread;
Ecore_Thread_Data *d, *r; Ecore_Thread_Data *d, *r;
void *ret; void *ret;
#endif
if ((!thread) || (!key) || (!value)) if ((!thread) || (!key) || (!value))
return NULL; return NULL;
#ifdef EFL_HAVE_THREADS
if (!PHE(worker->self, PHS())) return NULL; if (!PHE(worker->self, PHS())) return NULL;
if (!worker->hash) if (!worker->hash)
@ -1290,24 +1141,18 @@ ecore_thread_local_data_set(Ecore_Thread *thread,
ret = r->data; ret = r->data;
free(r); free(r);
return ret; return ret;
#else
(void) cb;
return NULL;
#endif
} }
EAPI void * EAPI void *
ecore_thread_local_data_find(Ecore_Thread *thread, ecore_thread_local_data_find(Ecore_Thread *thread,
const char *key) const char *key)
{ {
#ifdef EFL_HAVE_THREADS
Ecore_Pthread_Worker *worker = (Ecore_Pthread_Worker *)thread; Ecore_Pthread_Worker *worker = (Ecore_Pthread_Worker *)thread;
Ecore_Thread_Data *d; Ecore_Thread_Data *d;
#endif
if ((!thread) || (!key)) if ((!thread) || (!key))
return NULL; return NULL;
#ifdef EFL_HAVE_THREADS
if (!PHE(worker->self, PHS())) return NULL; if (!PHE(worker->self, PHS())) return NULL;
if (!worker->hash) if (!worker->hash)
@ -1317,30 +1162,22 @@ ecore_thread_local_data_find(Ecore_Thread *thread,
if (d) if (d)
return d->data; return d->data;
return NULL; return NULL;
#else
return NULL;
#endif
} }
EAPI Eina_Bool EAPI Eina_Bool
ecore_thread_local_data_del(Ecore_Thread *thread, ecore_thread_local_data_del(Ecore_Thread *thread,
const char *key) const char *key)
{ {
#ifdef EFL_HAVE_THREADS
Ecore_Pthread_Worker *worker = (Ecore_Pthread_Worker *)thread; Ecore_Pthread_Worker *worker = (Ecore_Pthread_Worker *)thread;
#endif
if ((!thread) || (!key)) if ((!thread) || (!key))
return EINA_FALSE; return EINA_FALSE;
#ifdef EFL_HAVE_THREADS
if (!PHE(worker->self, PHS())) return EINA_FALSE; if (!PHE(worker->self, PHS())) return EINA_FALSE;
if (!worker->hash) if (!worker->hash)
return EINA_FALSE; return EINA_FALSE;
return eina_hash_del_by_key(worker->hash, key); return eina_hash_del_by_key(worker->hash, key);
#else
return EINA_TRUE;
#endif
} }
EAPI Eina_Bool EAPI Eina_Bool
@ -1349,14 +1186,12 @@ ecore_thread_global_data_add(const char *key,
Eina_Free_Cb cb, Eina_Free_Cb cb,
Eina_Bool direct) Eina_Bool direct)
{ {
#ifdef EFL_HAVE_THREADS
Ecore_Thread_Data *d; Ecore_Thread_Data *d;
Eina_Bool ret; Eina_Bool ret;
#endif
if ((!key) || (!value)) if ((!key) || (!value))
return EINA_FALSE; return EINA_FALSE;
#ifdef EFL_HAVE_THREADS
LRWKWL(_ecore_thread_global_hash_lock); LRWKWL(_ecore_thread_global_hash_lock);
if (!_ecore_thread_global_hash) if (!_ecore_thread_global_hash)
_ecore_thread_global_hash = eina_hash_string_small_new(_ecore_thread_data_free); _ecore_thread_global_hash = eina_hash_string_small_new(_ecore_thread_data_free);
@ -1378,11 +1213,6 @@ ecore_thread_global_data_add(const char *key,
LRWKU(_ecore_thread_global_hash_lock); LRWKU(_ecore_thread_global_hash_lock);
CDB(_ecore_thread_global_hash_cond); CDB(_ecore_thread_global_hash_cond);
return ret; return ret;
#else
(void) cb;
(void) direct;
return EINA_TRUE;
#endif
} }
EAPI void * EAPI void *
@ -1390,14 +1220,12 @@ ecore_thread_global_data_set(const char *key,
void *value, void *value,
Eina_Free_Cb cb) Eina_Free_Cb cb)
{ {
#ifdef EFL_HAVE_THREADS
Ecore_Thread_Data *d, *r; Ecore_Thread_Data *d, *r;
void *ret; void *ret;
#endif
if ((!key) || (!value)) if ((!key) || (!value))
return NULL; return NULL;
#ifdef EFL_HAVE_THREADS
LRWKWL(_ecore_thread_global_hash_lock); LRWKWL(_ecore_thread_global_hash_lock);
if (!_ecore_thread_global_hash) if (!_ecore_thread_global_hash)
_ecore_thread_global_hash = eina_hash_string_small_new(_ecore_thread_data_free); _ecore_thread_global_hash = eina_hash_string_small_new(_ecore_thread_data_free);
@ -1420,22 +1248,16 @@ ecore_thread_global_data_set(const char *key,
ret = r->data; ret = r->data;
free(r); free(r);
return ret; return ret;
#else
(void) cb;
return NULL;
#endif
} }
EAPI void * EAPI void *
ecore_thread_global_data_find(const char *key) ecore_thread_global_data_find(const char *key)
{ {
#ifdef EFL_HAVE_THREADS
Ecore_Thread_Data *ret; Ecore_Thread_Data *ret;
#endif
if (!key) if (!key)
return NULL; return NULL;
#ifdef EFL_HAVE_THREADS
if (!_ecore_thread_global_hash) return NULL; if (!_ecore_thread_global_hash) return NULL;
LRWKRL(_ecore_thread_global_hash_lock); LRWKRL(_ecore_thread_global_hash_lock);
@ -1444,21 +1266,16 @@ ecore_thread_global_data_find(const char *key)
if (ret) if (ret)
return ret->data; return ret->data;
return NULL; return NULL;
#else
return NULL;
#endif
} }
EAPI Eina_Bool EAPI Eina_Bool
ecore_thread_global_data_del(const char *key) ecore_thread_global_data_del(const char *key)
{ {
#ifdef EFL_HAVE_THREADS
Eina_Bool ret; Eina_Bool ret;
#endif
if (!key) if (!key)
return EINA_FALSE; return EINA_FALSE;
#ifdef EFL_HAVE_THREADS
if (!_ecore_thread_global_hash) if (!_ecore_thread_global_hash)
return EINA_FALSE; return EINA_FALSE;
@ -1466,23 +1283,18 @@ ecore_thread_global_data_del(const char *key)
ret = eina_hash_del_by_key(_ecore_thread_global_hash, key); ret = eina_hash_del_by_key(_ecore_thread_global_hash, key);
LRWKU(_ecore_thread_global_hash_lock); LRWKU(_ecore_thread_global_hash_lock);
return ret; return ret;
#else
return EINA_TRUE;
#endif
} }
EAPI void * EAPI void *
ecore_thread_global_data_wait(const char *key, ecore_thread_global_data_wait(const char *key,
double seconds) double seconds)
{ {
#ifdef EFL_HAVE_THREADS
double tm = 0; double tm = 0;
Ecore_Thread_Data *ret = NULL; Ecore_Thread_Data *ret = NULL;
#endif
if (!key) if (!key)
return NULL; return NULL;
#ifdef EFL_HAVE_THREADS
if (!_ecore_thread_global_hash) if (!_ecore_thread_global_hash)
return NULL; return NULL;
if (seconds > 0) if (seconds > 0)
@ -1501,9 +1313,4 @@ ecore_thread_global_data_wait(const char *key,
} }
if (ret) return ret->data; if (ret) return ret->data;
return NULL; return NULL;
#else
(void) seconds;
return NULL;
#endif
} }

View File

@ -37,10 +37,6 @@
# include <unistd.h> # include <unistd.h>
#endif #endif
#ifdef EFL_HAVE_POSIX_THREADS
# include <pthread.h>
#endif
#ifdef HAVE_EVIL #ifdef HAVE_EVIL
# include <Evil.h> # include <Evil.h>
#endif #endif
@ -48,6 +44,8 @@
#include "eina_config.h" #include "eina_config.h"
#include "eina_private.h" #include "eina_private.h"
#include "eina_inlist.h" #include "eina_inlist.h"
#include "eina_lock.h"
#include "eina_thread.h"
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */ /* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
#include "eina_safety_checks.h" #include "eina_safety_checks.h"
@ -109,32 +107,26 @@ static int _abort_level_on_critical = EINA_LOG_LEVEL_CRITICAL;
static int _backtrace_level = -1; static int _backtrace_level = -1;
#endif #endif
#ifdef EFL_HAVE_THREADS
static Eina_Bool _threads_enabled = EINA_FALSE; static Eina_Bool _threads_enabled = EINA_FALSE;
static Eina_Bool _threads_inited = EINA_FALSE; static Eina_Bool _threads_inited = EINA_FALSE;
# ifdef EFL_HAVE_POSIX_THREADS static Eina_Thread _main_thread;
typedef pthread_t Thread; # define SELF() eina_thread_self()
# define IS_MAIN(t) eina_thread_equal(t, _main_thread)
static pthread_t _main_thread;
# define SELF() pthread_self()
# define IS_MAIN(t) pthread_equal(t, _main_thread)
# define IS_OTHER(t) EINA_UNLIKELY(!IS_MAIN(t)) # define IS_OTHER(t) EINA_UNLIKELY(!IS_MAIN(t))
# define CHECK_MAIN(...) \ # define CHECK_MAIN(...) \
do { \ do { \
if (!IS_MAIN(pthread_self())) { \ if (!IS_MAIN(eina_thread_self())) { \
fprintf(stderr, \ fprintf(stderr, \
"ERR: not main thread! current=%lu, main=%lu\n", \ "ERR: not main thread! current=%lu, main=%lu\n", \
(unsigned long)pthread_self(), \ (unsigned long)eina_thread_self(), \
(unsigned long)_main_thread); \ (unsigned long)_main_thread); \
return __VA_ARGS__; \ return __VA_ARGS__; \
} \ } \
} while (0) } while (0)
# ifdef EFL_HAVE_POSIX_THREADS_SPINLOCK #ifdef EFL_HAVE_POSIX_THREADS_SPINLOCK
static pthread_spinlock_t _log_lock; static pthread_spinlock_t _log_lock;
@ -154,7 +146,7 @@ static Eina_Bool _eina_log_spinlock_init(void)
do { \ do { \
if (0) { \ if (0) { \
fprintf(stderr, "+++LOG LOG_LOCKED! [%s, %lu]\n", \ fprintf(stderr, "+++LOG LOG_LOCKED! [%s, %lu]\n", \
__FUNCTION__, (unsigned long)pthread_self()); } \ __FUNCTION__, (unsigned long)eina_thread_self()); } \
if (EINA_UNLIKELY(_threads_enabled)) { \ if (EINA_UNLIKELY(_threads_enabled)) { \
pthread_spin_lock(&_log_lock); } \ pthread_spin_lock(&_log_lock); } \
} while (0) } while (0)
@ -166,60 +158,20 @@ static Eina_Bool _eina_log_spinlock_init(void)
if (0) { \ if (0) { \
fprintf(stderr, \ fprintf(stderr, \
"---LOG LOG_UNLOCKED! [%s, %lu]\n", \ "---LOG LOG_UNLOCKED! [%s, %lu]\n", \
__FUNCTION__, (unsigned long)pthread_self()); } \ __FUNCTION__, (unsigned long)eina_thread_self()); } \
} while (0) } while (0)
# define INIT() _eina_log_spinlock_init() # define INIT() _eina_log_spinlock_init()
# define SHUTDOWN() pthread_spin_destroy(&_log_lock) # define SHUTDOWN() pthread_spin_destroy(&_log_lock)
# else /* ! EFL_HAVE_POSIX_THREADS_SPINLOCK */ #else /* ! EFL_HAVE_POSIX_THREADS_SPINLOCK */
static pthread_mutex_t _log_mutex = PTHREAD_MUTEX_INITIALIZER; static Eina_Lock _log_mutex;
# define LOG_LOCK() if(_threads_enabled) {pthread_mutex_lock(&_log_mutex); } # define LOG_LOCK() if(_threads_enabled) {eina_lock_take(&_log_mutex); }
# define LOG_UNLOCK() if(_threads_enabled) {pthread_mutex_unlock(&_log_mutex); } # define LOG_UNLOCK() if(_threads_enabled) {eina_lock_release(&_log_mutex); }
# define INIT() (1) # define INIT() eina_lock_new(&_log_mutex)
# define SHUTDOWN() do {} while (0) # define SHUTDOWN() eina_lock_free(&_log_mutex)
# endif /* ! EFL_HAVE_POSIX_THREADS_SPINLOCK */ #endif /* ! EFL_HAVE_POSIX_THREADS_SPINLOCK */
# else /* EFL_HAVE_WIN32_THREADS */
typedef DWORD Thread;
static DWORD _main_thread;
# define SELF() GetCurrentThreadId()
# define IS_MAIN(t) (t == _main_thread)
# define IS_OTHER(t) EINA_UNLIKELY(!IS_MAIN(t))
# define CHECK_MAIN(...) \
do { \
if (!IS_MAIN(GetCurrentThreadId())) { \
fprintf(stderr, \
"ERR: not main thread! current=%lu, main=%lu\n", \
GetCurrentThreadId(), _main_thread); \
return __VA_ARGS__; \
} \
} while (0)
static HANDLE _log_mutex = NULL;
# define LOG_LOCK() if(_threads_enabled) WaitForSingleObject(_log_mutex, INFINITE)
# define LOG_UNLOCK() if(_threads_enabled) ReleaseMutex(_log_mutex)
# define INIT() ((_log_mutex = CreateMutex(NULL, FALSE, NULL)) ? 1 : 0)
# define SHUTDOWN() if (_log_mutex) CloseHandle(_log_mutex)
# endif /* EFL_HAVE_WIN32_THREADS */
#else /* ! EFL_HAVE_THREADS */
# define LOG_LOCK() do {} while (0)
# define LOG_UNLOCK() do {} while (0)
# define IS_MAIN(t) (1)
# define IS_OTHER(t) (0)
# define CHECK_MAIN(...) do {} while (0)
# define INIT() (1)
# define SHUTDOWN() do {} while (0)
#endif /* ! EFL_HAVE_THREADS */
// List of domains registered // List of domains registered
@ -602,7 +554,6 @@ eina_log_print_prefix_NOthreads_color_file_NOfunc(FILE *fp,
} }
/** threads, No color */ /** threads, No color */
#ifdef EFL_HAVE_THREADS
static void static void
eina_log_print_prefix_threads_NOcolor_file_func(FILE *fp, eina_log_print_prefix_threads_NOcolor_file_func(FILE *fp,
const Eina_Log_Domain *d, const Eina_Log_Domain *d,
@ -611,7 +562,7 @@ eina_log_print_prefix_threads_NOcolor_file_func(FILE *fp,
const char *fnc, const char *fnc,
int line) int line)
{ {
Thread cur; Eina_Thread cur;
DECLARE_LEVEL_NAME(level); DECLARE_LEVEL_NAME(level);
cur = SELF(); cur = SELF();
@ -634,7 +585,7 @@ eina_log_print_prefix_threads_NOcolor_NOfile_func(FILE *fp,
const char *fnc, const char *fnc,
int line EINA_UNUSED) int line EINA_UNUSED)
{ {
Thread cur; Eina_Thread cur;
DECLARE_LEVEL_NAME(level); DECLARE_LEVEL_NAME(level);
cur = SELF(); cur = SELF();
@ -657,7 +608,7 @@ eina_log_print_prefix_threads_NOcolor_file_NOfunc(FILE *fp,
const char *fnc EINA_UNUSED, const char *fnc EINA_UNUSED,
int line) int line)
{ {
Thread cur; Eina_Thread cur;
DECLARE_LEVEL_NAME(level); DECLARE_LEVEL_NAME(level);
cur = SELF(); cur = SELF();
@ -682,7 +633,7 @@ eina_log_print_prefix_threads_color_file_func(FILE *fp,
const char *fnc, const char *fnc,
int line) int line)
{ {
Thread cur; Eina_Thread cur;
DECLARE_LEVEL_NAME_COLOR(level); DECLARE_LEVEL_NAME_COLOR(level);
cur = SELF(); cur = SELF();
@ -756,7 +707,7 @@ eina_log_print_prefix_threads_color_NOfile_func(FILE *fp,
const char *fnc, const char *fnc,
int line EINA_UNUSED) int line EINA_UNUSED)
{ {
Thread cur; Eina_Thread cur;
DECLARE_LEVEL_NAME_COLOR(level); DECLARE_LEVEL_NAME_COLOR(level);
cur = SELF(); cur = SELF();
@ -825,7 +776,7 @@ eina_log_print_prefix_threads_color_file_NOfunc(FILE *fp,
const char *fnc EINA_UNUSED, const char *fnc EINA_UNUSED,
int line) int line)
{ {
Thread cur; Eina_Thread cur;
DECLARE_LEVEL_NAME_COLOR(level); DECLARE_LEVEL_NAME_COLOR(level);
cur = SELF(); cur = SELF();
@ -878,7 +829,6 @@ eina_log_print_prefix_threads_color_file_NOfunc(FILE *fp,
color, name, d->domain_str, file, line); color, name, d->domain_str, file, line);
# endif # endif
} }
#endif /* EFL_HAVE_THREADS */
static void (*_eina_log_print_prefix)(FILE *fp, const Eina_Log_Domain *d, static void (*_eina_log_print_prefix)(FILE *fp, const Eina_Log_Domain *d,
Eina_Log_Level level, const char *file, Eina_Log_Level level, const char *file,
@ -903,7 +853,6 @@ eina_log_print_prefix_update(void)
NOfile \ NOfile \
## file_ ## NOfunc ## func ## file_ ## NOfunc ## func
#ifdef EFL_HAVE_THREADS
if (_threads_enabled) if (_threads_enabled)
{ {
if (_disable_color) if (_disable_color)
@ -928,8 +877,6 @@ eina_log_print_prefix_update(void)
return; return;
} }
#endif
if (_disable_color) if (_disable_color)
{ {
if (_disable_file) if (_disable_file)
@ -1500,8 +1447,6 @@ eina_log_shutdown(void)
return EINA_TRUE; return EINA_TRUE;
} }
#ifdef EFL_HAVE_THREADS
/** /**
* @internal * @internal
* @brief Activate the log mutex. * @brief Activate the log mutex.
@ -1543,8 +1488,6 @@ eina_log_threads_shutdown(void)
#endif #endif
} }
#endif
/*============================================================================* /*============================================================================*
* API * * API *
*============================================================================*/ *============================================================================*/
@ -1562,7 +1505,7 @@ EAPI int EINA_LOG_DOMAIN_GLOBAL = 0;
EAPI void EAPI void
eina_log_threads_enable(void) eina_log_threads_enable(void)
{ {
#if defined (EFL_HAVE_THREADS) && defined (EINA_ENABLE_LOG) #ifdef EINA_ENABLE_LOG
if (_threads_enabled) return; if (_threads_enabled) return;
if (!_threads_inited) eina_log_threads_init(); if (!_threads_inited) eina_log_threads_init();
_threads_enabled = EINA_TRUE; _threads_enabled = EINA_TRUE;
@ -1611,7 +1554,7 @@ eina_log_level_get(void)
EAPI Eina_Bool EAPI Eina_Bool
eina_log_main_thread_check(void) eina_log_main_thread_check(void)
{ {
#if defined (EFL_HAVE_THREADS) && defined (EINA_ENABLE_LOG) #ifdef EINA_ENABLE_LOG
return ((!_threads_enabled) || IS_MAIN(SELF())); return ((!_threads_enabled) || IS_MAIN(SELF()));
#else #else
return EINA_TRUE; return EINA_TRUE;
@ -1947,10 +1890,9 @@ eina_log_print_cb_file(const Eina_Log_Domain *d,
#ifdef EINA_ENABLE_LOG #ifdef EINA_ENABLE_LOG
EINA_SAFETY_ON_NULL_RETURN(data); EINA_SAFETY_ON_NULL_RETURN(data);
FILE *f = data; FILE *f = data;
#ifdef EFL_HAVE_THREADS
if (_threads_enabled) if (_threads_enabled)
{ {
Thread cur; Eina_Thread cur;
cur = SELF(); cur = SELF();
if (IS_OTHER(cur)) if (IS_OTHER(cur))
@ -1961,13 +1903,11 @@ eina_log_print_cb_file(const Eina_Log_Domain *d,
} }
} }
#endif
fprintf(f, "%s<%u> %s:%d %s() ", d->name, eina_log_pid_get(), fprintf(f, "%s<%u> %s:%d %s() ", d->name, eina_log_pid_get(),
file, line, fnc); file, line, fnc);
DISPLAY_BACKTRACE(f, level); DISPLAY_BACKTRACE(f, level);
#ifdef EFL_HAVE_THREADS
end: end:
#endif
vfprintf(f, fmt, args); vfprintf(f, fmt, args);
putc('\n', f); putc('\n', f);
#else #else

View File

@ -63,10 +63,6 @@
#include <string.h> #include <string.h>
#include <stddef.h> #include <stddef.h>
#ifdef EFL_HAVE_POSIX_THREADS
# include <pthread.h>
#endif
#ifdef HAVE_EVIL #ifdef HAVE_EVIL
# include <Evil.h> # include <Evil.h>
#endif #endif

View File

@ -23,24 +23,14 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef EFL_HAVE_POSIX_THREADS #ifdef EINA_HAVE_DEBUG_THREADS
#include <pthread.h> # include <assert.h>
# ifdef EINA_HAVE_DEBUG_THREADS
# include <assert.h>
# endif
#endif #endif
#ifdef EINA_DEBUG_MALLOC #ifdef EINA_DEBUG_MALLOC
# include <malloc.h> # include <malloc.h>
#endif #endif
#ifdef EFL_HAVE_WIN32_THREADS
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# undef WIN32_LEAN_AND_MEAN
#endif
#include "eina_config.h" #include "eina_config.h"
#include "eina_inlist.h" #include "eina_inlist.h"
#include "eina_error.h" #include "eina_error.h"
@ -83,7 +73,7 @@ struct _Chained_Mempool
int minimal_size; int minimal_size;
#endif #endif
#ifdef EINA_HAVE_DEBUG_THREADS #ifdef EINA_HAVE_DEBUG_THREADS
pthread_t self; Eina_Tthread self;
#endif #endif
Eina_Lock mutex; Eina_Lock mutex;
}; };
@ -266,7 +256,7 @@ eina_chained_mempool_malloc(void *data, EINA_UNUSED unsigned int size)
if (!eina_lock_take(&pool->mutex)) if (!eina_lock_take(&pool->mutex))
{ {
#ifdef EINA_HAVE_DEBUG_THREADS #ifdef EINA_HAVE_DEBUG_THREADS
assert(pthread_equal(pool->self, pthread_self())); assert(eina_thread_equal(pool->self, eina_thread_self()));
#endif #endif
} }
@ -316,7 +306,7 @@ eina_chained_mempool_free(void *data, void *ptr)
if (!eina_lock_take(&pool->mutex)) if (!eina_lock_take(&pool->mutex))
{ {
#ifdef EINA_HAVE_DEBUG_THREADS #ifdef EINA_HAVE_DEBUG_THREADS
assert(pthread_equal(pool->self, pthread_self())); assert(eina_thread_equal(pool->self, eina_thread_self()));
#endif #endif
} }
@ -361,7 +351,7 @@ eina_chained_mempool_repack(void *data,
if (!eina_lock_take(&pool->mutex)) if (!eina_lock_take(&pool->mutex))
{ {
#ifdef EINA_HAVE_DEBUG_THREADS #ifdef EINA_HAVE_DEBUG_THREADS
assert(pthread_equal(pool->self, pthread_self())); assert(eina_threadequal(pool->self, eina_threadself()));
#endif #endif
} }
@ -479,7 +469,7 @@ eina_chained_mempool_init(const char *context,
#endif #endif
#ifdef EINA_HAVE_DEBUG_THREADS #ifdef EINA_HAVE_DEBUG_THREADS
mp->self = pthread_self(); mp->self = eina_threadself();
#endif #endif
eina_lock_new(&mp->mutex); eina_lock_new(&mp->mutex);
@ -523,7 +513,7 @@ eina_chained_mempool_shutdown(void *data)
eina_lock_free(&mp->mutex); eina_lock_free(&mp->mutex);
#ifdef EINA_HAVE_DEBUG_THREADS #ifdef EINA_HAVE_DEBUG_THREADS
assert(pthread_equal(mp->self, pthread_self())); assert(eina_threadequal(mp->self, eina_threadself()));
#endif #endif
free(mp); free(mp);

View File

@ -23,18 +23,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef EFL_HAVE_POSIX_THREADS
# include <pthread.h>
#endif
#include <assert.h> #include <assert.h>
#ifdef EFL_HAVE_WIN32_THREADS
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# undef WIN32_LEAN_AND_MEAN
#endif
#include "eina_config.h" #include "eina_config.h"
#include "eina_mempool.h" #include "eina_mempool.h"
#include "eina_trash.h" #include "eina_trash.h"
@ -78,7 +68,7 @@ struct _One_Big
Eina_Inlist *over_list; Eina_Inlist *over_list;
#ifdef EINA_HAVE_DEBUG_THREADS #ifdef EINA_HAVE_DEBUG_THREADS
pthread_t self; Eina_Thread self;
#endif #endif
Eina_Lock mutex; Eina_Lock mutex;
}; };
@ -92,7 +82,7 @@ eina_one_big_malloc(void *data, EINA_UNUSED unsigned int size)
if (!eina_lock_take(&pool->mutex)) if (!eina_lock_take(&pool->mutex))
{ {
#ifdef EINA_HAVE_DEBUG_THREADS #ifdef EINA_HAVE_DEBUG_THREADS
assert(pthread_equal(pool->self, pthread_self())); assert(eina_thread_equal(pool->self, eina_thread_self()));
#endif #endif
} }
@ -160,7 +150,7 @@ eina_one_big_free(void *data, void *ptr)
if (!eina_lock_take(&pool->mutex)) if (!eina_lock_take(&pool->mutex))
{ {
#ifdef EINA_HAVE_DEBUG_THREADS #ifdef EINA_HAVE_DEBUG_THREADS
assert(pthread_equal(pool->self, pthread_self())); assert(eina_thread_equal(pool->self, eina_thread_self()));
#endif #endif
} }
@ -233,7 +223,7 @@ eina_one_big_init(const char *context,
} }
#ifdef EINA_HAVE_DEBUG_THREADS #ifdef EINA_HAVE_DEBUG_THREADS
pool->self = pthread_self(); pool->self = eina_thread_self();
#endif #endif
eina_lock_new(&pool->mutex); eina_lock_new(&pool->mutex);
@ -253,7 +243,7 @@ eina_one_big_shutdown(void *data)
if (!eina_lock_take(&pool->mutex)) if (!eina_lock_take(&pool->mutex))
{ {
#ifdef EINA_HAVE_DEBUG_THREADS #ifdef EINA_HAVE_DEBUG_THREADS
assert(pthread_equal(pool->self, pthread_self())); assert(eina_thread_equal(pool->self, eina_thread_self()));
#endif #endif
} }

View File

@ -13,13 +13,6 @@
#include <Eina.h> #include <Eina.h>
#ifdef EINA_HAVE_THREADS
#if ((!defined(_WIN32_WCE)) && (!defined(_WIN32)))
# include <pthread.h>
# define _EET_INCLUDED_PTHREAD
#endif
#endif /* ifdef EINA_HAVE_THREADS */
#include <check.h> #include <check.h>
#include "eet_suite.h" #include "eet_suite.h"
@ -1849,53 +1842,26 @@ START_TEST(eet_cipher_decipher_simple)
END_TEST END_TEST
#ifdef EINA_HAVE_THREADS
static Eina_Bool open_worker_stop; static Eina_Bool open_worker_stop;
# ifdef _EET_INCLUDED_PTHREAD
static void * static void *
open_close_worker(void *path) open_close_worker(void *path, Eina_Thread tid EINA_UNUSED)
{ {
while (!open_worker_stop) while (!open_worker_stop)
{ {
Eet_File *ef = eet_open((char const *)path, EET_FILE_MODE_READ); Eet_File *ef = eet_open((char const *)path, EET_FILE_MODE_READ);
if (ef == NULL) if (ef == NULL)
pthread_exit("eet_open() failed"); return "eet_open() failed";
else else
{ {
Eet_Error err_code = eet_close(ef); Eet_Error err_code = eet_close(ef);
if (err_code != EET_ERROR_NONE) if (err_code != EET_ERROR_NONE)
pthread_exit("eet_close() failed"); return "eet_close() failed";
} }
} }
pthread_exit(NULL); return NULL;
} /* open_close_worker */ }
# else /* ifdef _EET_INCLUDED_PTHREAD */
static unsigned int __stdcall
open_close_worker(void *path)
{
while (!open_worker_stop)
{
Eet_File *ef = eet_open((char const *)path, EET_FILE_MODE_READ);
if (ef == NULL)
_endthreadex(-1);
else
{
Eet_Error err_code = eet_close(ef);
if (err_code != EET_ERROR_NONE)
_endthreadex(-2);
}
}
_endthreadex(0);
} /* open_close_worker */
# endif /* ifdef _EET_INCLUDED_PTHREAD */
START_TEST(eet_cache_concurrency) START_TEST(eet_cache_concurrency)
{ {
@ -1904,13 +1870,7 @@ START_TEST(eet_cache_concurrency)
Eet_File *ef; Eet_File *ef;
void *thread_ret; void *thread_ret;
unsigned int n; unsigned int n;
# ifdef _EET_INCLUDED_PTHREAD Eina_Thread thread;
pthread_t thread;
# else /* ifdef _EET_INCLUDED_PTHREAD */
uintptr_t thread;
unsigned int thread_id;
DWORD ret;
# endif /* ifdef _EET_INCLUDED_PTHREAD */
eet_init(); eet_init();
eina_threads_init(); eina_threads_init();
@ -1923,11 +1883,8 @@ START_TEST(eet_cache_concurrency)
/* start a thread that repeatedly opens and closes a file */ /* start a thread that repeatedly opens and closes a file */
open_worker_stop = 0; open_worker_stop = 0;
# ifdef _EET_INCLUDED_PTHREAD eina_thread_create(&thread, EINA_THREAD_NORMAL, -1, open_close_worker, file);
pthread_create(&thread, NULL, open_close_worker, file);
# else /* ifdef _EET_INCLUDED_PTHREAD */
thread = _beginthreadex(NULL, 0, open_close_worker, file, 0, &thread_id);
# endif /* ifdef _EET_INCLUDED_PTHREAD */
/* clear the cache repeatedly in this thread */ /* clear the cache repeatedly in this thread */
for (n = 0; n < 20000; ++n) for (n = 0; n < 20000; ++n)
{ {
@ -1936,15 +1893,8 @@ START_TEST(eet_cache_concurrency)
/* join the other thread, and fail if it returned an error message */ /* join the other thread, and fail if it returned an error message */
open_worker_stop = 1; open_worker_stop = 1;
# ifdef _EET_INCLUDED_PTHREAD thread_ret = eina_thread_join(thread);
fail_if(pthread_join(thread, &thread_ret) != 0);
fail_unless(thread_ret == NULL, (char const *)thread_ret); fail_unless(thread_ret == NULL, (char const *)thread_ret);
# else /* ifdef _EET_INCLUDED_PTHREAD */
ret = WaitForSingleObject((HANDLE)thread, INFINITE);
fail_if(ret != WAIT_OBJECT_0);
fail_if(GetExitCodeThread((HANDLE)thread, &ret) == FALSE);
fail_if(ret != 0);
# endif /* ifdef _EET_INCLUDED_PTHREAD */
eet_close(ef); eet_close(ef);
@ -1955,8 +1905,6 @@ START_TEST(eet_cache_concurrency)
} }
END_TEST END_TEST
#endif /* EINA_HAVE_THREADS */
typedef struct _Eet_Connection_Data Eet_Connection_Data; typedef struct _Eet_Connection_Data Eet_Connection_Data;
struct _Eet_Connection_Data struct _Eet_Connection_Data
{ {
@ -2746,11 +2694,9 @@ eet_suite(void)
suite_add_tcase(s, tc); suite_add_tcase(s, tc);
#endif /* ifdef HAVE_CIPHER */ #endif /* ifdef HAVE_CIPHER */
#ifdef EINA_HAVE_THREADS
tc = tcase_create("Eet Cache"); tc = tcase_create("Eet Cache");
tcase_add_test(tc, eet_cache_concurrency); tcase_add_test(tc, eet_cache_concurrency);
suite_add_tcase(s, tc); suite_add_tcase(s, tc);
#endif /* ifdef EFL_HAVE_THREADS */
tc = tcase_create("Eet Connection"); tc = tcase_create("Eet Connection");
tcase_add_test(tc, eet_connection_check); tcase_add_test(tc, eet_connection_check);

View File

@ -20,8 +20,7 @@
# include "config.h" # include "config.h"
#endif #endif
#if defined(EFL_HAVE_THREADS) && defined __linux__ #ifdef __linux__
#include <pthread.h>
#include <errno.h> #include <errno.h>
#include <sys/resource.h> #include <sys/resource.h>
#endif #endif
@ -29,7 +28,7 @@
#include "eina_suite.h" #include "eina_suite.h"
#include "Eina.h" #include "Eina.h"
#if defined(EFL_HAVE_THREADS) && defined __linux__ #ifdef __linux__
/* /*
* TODO: Test if RT priorities are right. However, make check should be run as * TODO: Test if RT priorities are right. However, make check should be run as
@ -37,7 +36,7 @@
*/ */
static void * static void *
_thread_run(void *arg EINA_UNUSED) _thread_run(void *arg EINA_UNUSED, Eina_Thread tid EINA_UNUSED)
{ {
int niceval = getpriority(PRIO_PROCESS, 0); int niceval = getpriority(PRIO_PROCESS, 0);
int niceval2; int niceval2;
@ -53,17 +52,17 @@ START_TEST(eina_test_sched_prio_drop)
{ {
int niceval = getpriority(PRIO_PROCESS, 0); int niceval = getpriority(PRIO_PROCESS, 0);
int niceval2; int niceval2;
pthread_t tid; Eina_Thread tid;
eina_init(); eina_init();
pthread_create(&tid, NULL, _thread_run, NULL); eina_thread_create(&tid, EINA_THREAD_NORMAL, -1, _thread_run, NULL);
niceval2 = getpriority(PRIO_PROCESS, 0); niceval2 = getpriority(PRIO_PROCESS, 0);
/* niceness of main thread should not have changed */ /* niceness of main thread should not have changed */
fail_if(niceval2 != niceval); fail_if(niceval2 != niceval);
pthread_join(tid, NULL); eina_thread_join(tid);
/* niceness of main thread should not have changed */ /* niceness of main thread should not have changed */
fail_if(niceval2 != niceval); fail_if(niceval2 != niceval);