Eina now abstracts threads, so use that.
the touched files had the EFL_HAVE_THREADS as it's mandatory now.
SVN revision: 81935
#include "Ecore.h"
#include "ecore_private.h"
-#ifdef EFL_HAVE_THREADS
-
# define LK(x) Eina_Lock x
# define LKI(x) eina_lock_new(&(x))
# define LKD(x) eina_lock_free(&(x))
# define PHC(x, f, d) eina_thread_create(&(x), EINA_THREAD_BACKGROUND, -1, (void *)f, d)
# 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 Ecore_Pthread;
typedef struct _Ecore_Thread_Data Ecore_Thread_Data;
Ecore_Thread_Cb func_cancel;
Ecore_Thread_Cb func_end;
-#ifdef EFL_HAVE_THREADS
PH(self);
Eina_Hash *hash;
CD(cond);
LK(mutex);
-#endif
const void *data;
int cancel;
-#ifdef EFL_HAVE_THREADS
LK(cancel_mutex);
-#endif
Eina_Bool message_run : 1;
Eina_Bool feedback_run : 1;
Eina_Bool no_queue : 1;
};
-#ifdef EFL_HAVE_THREADS
typedef struct _Ecore_Pthread_Notify Ecore_Pthread_Notify;
struct _Ecore_Pthread_Notify
{
Eina_Bool sync : 1;
};
-#endif
-
static int _ecore_thread_count_max = 0;
-#ifdef EFL_HAVE_THREADS
-
static void _ecore_thread_handler(void *data);
static int _ecore_thread_count = 0;
return NULL;
}
-#endif
-
static Ecore_Pthread_Worker *
_ecore_thread_worker_new(void)
{
-#ifdef EFL_HAVE_THREADS
Ecore_Pthread_Worker *result;
result = eina_trash_pop(&_ecore_thread_worker_trash);
CDI(result->cond, result->mutex);
return result;
-#else
- return malloc(sizeof (Ecore_Pthread_Worker));
-#endif
}
void
if (_ecore_thread_count_max <= 0)
_ecore_thread_count_max = 1;
-#ifdef EFL_HAVE_THREADS
LKI(_ecore_pending_job_threads_mutex);
LRWKI(_ecore_thread_global_hash_lock);
LKI(_ecore_thread_global_hash_mutex);
LKI(_ecore_running_job_mutex);
CDI(_ecore_thread_global_hash_cond, _ecore_thread_global_hash_mutex);
-#endif
}
void
_ecore_thread_shutdown(void)
{
/* FIXME: If function are still running in the background, should we kill them ? */
-#ifdef EFL_HAVE_THREADS
Ecore_Pthread_Worker *work;
Eina_List *l;
Eina_Bool test;
LKD(_ecore_thread_global_hash_mutex);
LKD(_ecore_running_job_mutex);
CDD(_ecore_thread_global_hash_cond);
-#endif
}
EAPI Ecore_Thread *
{
Ecore_Pthread_Worker *work;
Eina_Bool tried = EINA_FALSE;
-#ifdef EFL_HAVE_THREADS
PH(thread);
-#endif
EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
-
+
if (!func_blocking) return NULL;
work = _ecore_thread_worker_new();
work->no_queue = EINA_FALSE;
work->data = data;
-#ifdef EFL_HAVE_THREADS
work->self = 0;
work->hash = NULL;
eina_threads_shutdown();
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
ecore_thread_cancel(Ecore_Thread *thread)
{
-#ifdef EFL_HAVE_THREADS
Ecore_Pthread_Worker *volatile work = (Ecore_Pthread_Worker *)thread;
Eina_List *l;
int cancel;
LKU(work->cancel_mutex);
return EINA_FALSE;
-#else
- (void) thread;
- return EINA_TRUE;
-#endif
}
EAPI Eina_Bool
int cancel;
if (!worker) return EINA_TRUE;
-#ifdef EFL_HAVE_THREADS
LKL(worker->cancel_mutex);
-#endif
+
cancel = worker->cancel;
/* 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.
But ecore_thread_check will only work correctly with a printf, all the volatile,
lock and even usleep don't help here... */
/* fprintf(stderr, "wc: %i\n", cancel); */
-#ifdef EFL_HAVE_THREADS
LKU(worker->cancel_mutex);
-#endif
return cancel;
}
const void *data,
Eina_Bool try_no_queue)
{
-#ifdef EFL_HAVE_THREADS
Ecore_Pthread_Worker *worker;
Eina_Bool tried = EINA_FALSE;
PH(thread);
EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
-
+
if (!func_heavy) return NULL;
worker = _ecore_thread_worker_new();
LKU(_ecore_pending_job_threads_mutex);
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
if (!worker) return EINA_FALSE;
-#ifdef EFL_HAVE_THREADS
if (!PHE(worker->self, PHS())) return EINA_FALSE;
if (worker->feedback_run)
return EINA_FALSE;
return EINA_TRUE;
-#else
- worker->u.feedback_run.func_notify((void *)worker->data, thread, (void *)data);
-
- return EINA_TRUE;
-#endif
}
#if 0
Ecore_Thread_Cb func_cancel,
const void *data)
{
-#ifdef EFL_HAVE_THREADS
Ecore_Pthread_Worker *worker;
PH(t);
CDD(worker->cond);
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);
if (!worker) return EINA_FALSE;
-#ifdef EFL_HAVE_THREADS
if (!PHE(worker->self, PHS())) return EINA_FALSE;
-#endif
worker->reschedule = EINA_TRUE;
return EINA_TRUE;
EAPI int
ecore_thread_active_get(void)
{
-#ifdef EFL_HAVE_THREADS
EINA_MAIN_LOOP_CHECK_RETURN_VAL(0);
return _ecore_thread_count;
-#else
- return 0;
-#endif
}
EAPI int
ecore_thread_pending_get(void)
{
-#ifdef EFL_HAVE_THREADS
int ret;
EINA_MAIN_LOOP_CHECK_RETURN_VAL(0);
ret = eina_list_count(_ecore_pending_job_threads);
LKU(_ecore_pending_job_threads_mutex);
return ret;
-#else
- return 0;
-#endif
}
EAPI int
ecore_thread_pending_feedback_get(void)
{
-#ifdef EFL_HAVE_THREADS
int ret;
EINA_MAIN_LOOP_CHECK_RETURN_VAL(0);
ret = eina_list_count(_ecore_pending_job_threads_feedback);
LKU(_ecore_pending_job_threads_mutex);
return ret;
-#else
- return 0;
-#endif
}
EAPI int
ecore_thread_pending_total_get(void)
{
-#ifdef EFL_HAVE_THREADS
int ret;
EINA_MAIN_LOOP_CHECK_RETURN_VAL(0);
ret = eina_list_count(_ecore_pending_job_threads) + eina_list_count(_ecore_pending_job_threads_feedback);
LKU(_ecore_pending_job_threads_mutex);
return ret;
-#else
- return 0;
-#endif
}
EAPI int
EAPI int
ecore_thread_available_get(void)
{
-#ifdef EFL_HAVE_THREADS
int ret;
LKL(_ecore_pending_job_threads_mutex);
ret = _ecore_thread_count_max - _ecore_thread_count;
LKU(_ecore_pending_job_threads_mutex);
return ret;
-#else
- return 0;
-#endif
}
EAPI Eina_Bool
Eina_Free_Cb cb,
Eina_Bool direct)
{
-#ifdef EFL_HAVE_THREADS
Ecore_Pthread_Worker *worker = (Ecore_Pthread_Worker *)thread;
Ecore_Thread_Data *d;
Eina_Bool ret;
-#endif
if ((!thread) || (!key) || (!value))
return EINA_FALSE;
-#ifdef EFL_HAVE_THREADS
+
if (!PHE(worker->self, PHS())) return EINA_FALSE;
if (!worker->hash)
ret = eina_hash_add(worker->hash, key, d);
CDB(worker->cond);
return ret;
-#else
- (void) cb;
- (void) direct;
- return EINA_FALSE;
-#endif
}
EAPI void *
void *value,
Eina_Free_Cb cb)
{
-#ifdef EFL_HAVE_THREADS
Ecore_Pthread_Worker *worker = (Ecore_Pthread_Worker *)thread;
Ecore_Thread_Data *d, *r;
void *ret;
-#endif
if ((!thread) || (!key) || (!value))
return NULL;
-#ifdef EFL_HAVE_THREADS
+
if (!PHE(worker->self, PHS())) return NULL;
if (!worker->hash)
ret = r->data;
free(r);
return ret;
-#else
- (void) cb;
- return NULL;
-#endif
}
EAPI void *
ecore_thread_local_data_find(Ecore_Thread *thread,
const char *key)
{
-#ifdef EFL_HAVE_THREADS
Ecore_Pthread_Worker *worker = (Ecore_Pthread_Worker *)thread;
Ecore_Thread_Data *d;
-#endif
if ((!thread) || (!key))
return NULL;
-#ifdef EFL_HAVE_THREADS
+
if (!PHE(worker->self, PHS())) return NULL;
if (!worker->hash)
if (d)
return d->data;
return NULL;
-#else
- return NULL;
-#endif
}
EAPI Eina_Bool
ecore_thread_local_data_del(Ecore_Thread *thread,
const char *key)
{
-#ifdef EFL_HAVE_THREADS
Ecore_Pthread_Worker *worker = (Ecore_Pthread_Worker *)thread;
-#endif
if ((!thread) || (!key))
return EINA_FALSE;
-#ifdef EFL_HAVE_THREADS
+
if (!PHE(worker->self, PHS())) return EINA_FALSE;
if (!worker->hash)
return EINA_FALSE;
return eina_hash_del_by_key(worker->hash, key);
-#else
- return EINA_TRUE;
-#endif
}
EAPI Eina_Bool
Eina_Free_Cb cb,
Eina_Bool direct)
{
-#ifdef EFL_HAVE_THREADS
Ecore_Thread_Data *d;
Eina_Bool ret;
-#endif
if ((!key) || (!value))
return EINA_FALSE;
-#ifdef EFL_HAVE_THREADS
+
LRWKWL(_ecore_thread_global_hash_lock);
if (!_ecore_thread_global_hash)
_ecore_thread_global_hash = eina_hash_string_small_new(_ecore_thread_data_free);
LRWKU(_ecore_thread_global_hash_lock);
CDB(_ecore_thread_global_hash_cond);
return ret;
-#else
- (void) cb;
- (void) direct;
- return EINA_TRUE;
-#endif
}
EAPI void *
void *value,
Eina_Free_Cb cb)
{
-#ifdef EFL_HAVE_THREADS
Ecore_Thread_Data *d, *r;
void *ret;
-#endif
if ((!key) || (!value))
return NULL;
-#ifdef EFL_HAVE_THREADS
+
LRWKWL(_ecore_thread_global_hash_lock);
if (!_ecore_thread_global_hash)
_ecore_thread_global_hash = eina_hash_string_small_new(_ecore_thread_data_free);
ret = r->data;
free(r);
return ret;
-#else
- (void) cb;
- return NULL;
-#endif
}
EAPI void *
ecore_thread_global_data_find(const char *key)
{
-#ifdef EFL_HAVE_THREADS
Ecore_Thread_Data *ret;
-#endif
if (!key)
return NULL;
-#ifdef EFL_HAVE_THREADS
+
if (!_ecore_thread_global_hash) return NULL;
LRWKRL(_ecore_thread_global_hash_lock);
if (ret)
return ret->data;
return NULL;
-#else
- return NULL;
-#endif
}
EAPI Eina_Bool
ecore_thread_global_data_del(const char *key)
{
-#ifdef EFL_HAVE_THREADS
Eina_Bool ret;
-#endif
if (!key)
return EINA_FALSE;
-#ifdef EFL_HAVE_THREADS
+
if (!_ecore_thread_global_hash)
return EINA_FALSE;
ret = eina_hash_del_by_key(_ecore_thread_global_hash, key);
LRWKU(_ecore_thread_global_hash_lock);
return ret;
-#else
- return EINA_TRUE;
-#endif
}
EAPI void *
ecore_thread_global_data_wait(const char *key,
double seconds)
{
-#ifdef EFL_HAVE_THREADS
double tm = 0;
Ecore_Thread_Data *ret = NULL;
-#endif
if (!key)
return NULL;
-#ifdef EFL_HAVE_THREADS
+
if (!_ecore_thread_global_hash)
return NULL;
if (seconds > 0)
}
if (ret) return ret->data;
return NULL;
-#else
- (void) seconds;
- return NULL;
-#endif
}
-
# include <unistd.h>
#endif
-#ifdef EFL_HAVE_POSIX_THREADS
-# include <pthread.h>
-#endif
-
#ifdef HAVE_EVIL
# include <Evil.h>
#endif
#include "eina_config.h"
#include "eina_private.h"
#include "eina_inlist.h"
+#include "eina_lock.h"
+#include "eina_thread.h"
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
#include "eina_safety_checks.h"
static int _backtrace_level = -1;
#endif
-#ifdef EFL_HAVE_THREADS
-
static Eina_Bool _threads_enabled = EINA_FALSE;
static Eina_Bool _threads_inited = EINA_FALSE;
-# ifdef EFL_HAVE_POSIX_THREADS
-
-typedef pthread_t Thread;
-
-static pthread_t _main_thread;
+static Eina_Thread _main_thread;
-# define SELF() pthread_self()
-# define IS_MAIN(t) pthread_equal(t, _main_thread)
+# define SELF() eina_thread_self()
+# define IS_MAIN(t) eina_thread_equal(t, _main_thread)
# define IS_OTHER(t) EINA_UNLIKELY(!IS_MAIN(t))
# define CHECK_MAIN(...) \
do { \
- if (!IS_MAIN(pthread_self())) { \
+ if (!IS_MAIN(eina_thread_self())) { \
fprintf(stderr, \
"ERR: not main thread! current=%lu, main=%lu\n", \
- (unsigned long)pthread_self(), \
+ (unsigned long)eina_thread_self(), \
(unsigned long)_main_thread); \
return __VA_ARGS__; \
} \
} while (0)
-# ifdef EFL_HAVE_POSIX_THREADS_SPINLOCK
+#ifdef EFL_HAVE_POSIX_THREADS_SPINLOCK
static pthread_spinlock_t _log_lock;
do { \
if (0) { \
fprintf(stderr, "+++LOG LOG_LOCKED! [%s, %lu]\n", \
- __FUNCTION__, (unsigned long)pthread_self()); } \
+ __FUNCTION__, (unsigned long)eina_thread_self()); } \
if (EINA_UNLIKELY(_threads_enabled)) { \
pthread_spin_lock(&_log_lock); } \
} while (0)
if (0) { \
fprintf(stderr, \
"---LOG LOG_UNLOCKED! [%s, %lu]\n", \
- __FUNCTION__, (unsigned long)pthread_self()); } \
+ __FUNCTION__, (unsigned long)eina_thread_self()); } \
} while (0)
# define INIT() _eina_log_spinlock_init()
# define SHUTDOWN() pthread_spin_destroy(&_log_lock)
-# else /* ! EFL_HAVE_POSIX_THREADS_SPINLOCK */
-
-static pthread_mutex_t _log_mutex = PTHREAD_MUTEX_INITIALIZER;
-# define LOG_LOCK() if(_threads_enabled) {pthread_mutex_lock(&_log_mutex); }
-# define LOG_UNLOCK() if(_threads_enabled) {pthread_mutex_unlock(&_log_mutex); }
-# define INIT() (1)
-# define SHUTDOWN() do {} while (0)
-
-# endif /* ! EFL_HAVE_POSIX_THREADS_SPINLOCK */
-
-# else /* EFL_HAVE_WIN32_THREADS */
-
-typedef DWORD Thread;
+#else /* ! EFL_HAVE_POSIX_THREADS_SPINLOCK */
-static DWORD _main_thread;
+static Eina_Lock _log_mutex;
+# define LOG_LOCK() if(_threads_enabled) {eina_lock_take(&_log_mutex); }
+# define LOG_UNLOCK() if(_threads_enabled) {eina_lock_release(&_log_mutex); }
+# define INIT() eina_lock_new(&_log_mutex)
+# define SHUTDOWN() eina_lock_free(&_log_mutex)
-# 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 */
+#endif /* ! EFL_HAVE_POSIX_THREADS_SPINLOCK */
// List of domains registered
}
/** threads, No color */
-#ifdef EFL_HAVE_THREADS
static void
eina_log_print_prefix_threads_NOcolor_file_func(FILE *fp,
const Eina_Log_Domain *d,
const char *fnc,
int line)
{
- Thread cur;
+ Eina_Thread cur;
DECLARE_LEVEL_NAME(level);
cur = SELF();
const char *fnc,
int line EINA_UNUSED)
{
- Thread cur;
+ Eina_Thread cur;
DECLARE_LEVEL_NAME(level);
cur = SELF();
const char *fnc EINA_UNUSED,
int line)
{
- Thread cur;
+ Eina_Thread cur;
DECLARE_LEVEL_NAME(level);
cur = SELF();
const char *fnc,
int line)
{
- Thread cur;
+ Eina_Thread cur;
DECLARE_LEVEL_NAME_COLOR(level);
cur = SELF();
const char *fnc,
int line EINA_UNUSED)
{
- Thread cur;
+ Eina_Thread cur;
DECLARE_LEVEL_NAME_COLOR(level);
cur = SELF();
const char *fnc EINA_UNUSED,
int line)
{
- Thread cur;
+ Eina_Thread cur;
DECLARE_LEVEL_NAME_COLOR(level);
cur = SELF();
color, name, d->domain_str, file, line);
# endif
}
-#endif /* EFL_HAVE_THREADS */
static void (*_eina_log_print_prefix)(FILE *fp, const Eina_Log_Domain *d,
Eina_Log_Level level, const char *file,
NOfile \
## file_ ## NOfunc ## func
-#ifdef EFL_HAVE_THREADS
if (_threads_enabled)
{
if (_disable_color)
return;
}
-#endif
-
if (_disable_color)
{
if (_disable_file)
return EINA_TRUE;
}
-#ifdef EFL_HAVE_THREADS
-
/**
* @internal
* @brief Activate the log mutex.
#endif
}
-#endif
-
/*============================================================================*
* API *
*============================================================================*/
EAPI 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_inited) eina_log_threads_init();
_threads_enabled = EINA_TRUE;
EAPI Eina_Bool
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()));
#else
return EINA_TRUE;
#ifdef EINA_ENABLE_LOG
EINA_SAFETY_ON_NULL_RETURN(data);
FILE *f = data;
-#ifdef EFL_HAVE_THREADS
if (_threads_enabled)
{
- Thread cur;
+ Eina_Thread cur;
cur = SELF();
if (IS_OTHER(cur))
}
}
-#endif
fprintf(f, "%s<%u> %s:%d %s() ", d->name, eina_log_pid_get(),
file, line, fnc);
DISPLAY_BACKTRACE(f, level);
-#ifdef EFL_HAVE_THREADS
+
end:
-#endif
vfprintf(f, fmt, args);
putc('\n', f);
#else
#include <string.h>
#include <stddef.h>
-#ifdef EFL_HAVE_POSIX_THREADS
-# include <pthread.h>
-#endif
-
#ifdef HAVE_EVIL
# include <Evil.h>
#endif
#include <stdlib.h>
#include <string.h>
-#ifdef EFL_HAVE_POSIX_THREADS
-#include <pthread.h>
-
-# ifdef EINA_HAVE_DEBUG_THREADS
-# include <assert.h>
-# endif
+#ifdef EINA_HAVE_DEBUG_THREADS
+# include <assert.h>
#endif
#ifdef EINA_DEBUG_MALLOC
# include <malloc.h>
#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_inlist.h"
#include "eina_error.h"
int minimal_size;
#endif
#ifdef EINA_HAVE_DEBUG_THREADS
- pthread_t self;
+ Eina_Tthread self;
#endif
Eina_Lock mutex;
};
if (!eina_lock_take(&pool->mutex))
{
#ifdef EINA_HAVE_DEBUG_THREADS
- assert(pthread_equal(pool->self, pthread_self()));
+ assert(eina_thread_equal(pool->self, eina_thread_self()));
#endif
}
if (!eina_lock_take(&pool->mutex))
{
#ifdef EINA_HAVE_DEBUG_THREADS
- assert(pthread_equal(pool->self, pthread_self()));
+ assert(eina_thread_equal(pool->self, eina_thread_self()));
#endif
}
if (!eina_lock_take(&pool->mutex))
{
#ifdef EINA_HAVE_DEBUG_THREADS
- assert(pthread_equal(pool->self, pthread_self()));
+ assert(eina_threadequal(pool->self, eina_threadself()));
#endif
}
#endif
#ifdef EINA_HAVE_DEBUG_THREADS
- mp->self = pthread_self();
+ mp->self = eina_threadself();
#endif
eina_lock_new(&mp->mutex);
eina_lock_free(&mp->mutex);
#ifdef EINA_HAVE_DEBUG_THREADS
- assert(pthread_equal(mp->self, pthread_self()));
+ assert(eina_threadequal(mp->self, eina_threadself()));
#endif
free(mp);
#include <stdlib.h>
#include <string.h>
-#ifdef EFL_HAVE_POSIX_THREADS
-# include <pthread.h>
-#endif
-
#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_mempool.h"
#include "eina_trash.h"
Eina_Inlist *over_list;
#ifdef EINA_HAVE_DEBUG_THREADS
- pthread_t self;
+ Eina_Thread self;
#endif
Eina_Lock mutex;
};
if (!eina_lock_take(&pool->mutex))
{
#ifdef EINA_HAVE_DEBUG_THREADS
- assert(pthread_equal(pool->self, pthread_self()));
+ assert(eina_thread_equal(pool->self, eina_thread_self()));
#endif
}
if (!eina_lock_take(&pool->mutex))
{
#ifdef EINA_HAVE_DEBUG_THREADS
- assert(pthread_equal(pool->self, pthread_self()));
+ assert(eina_thread_equal(pool->self, eina_thread_self()));
#endif
}
}
#ifdef EINA_HAVE_DEBUG_THREADS
- pool->self = pthread_self();
+ pool->self = eina_thread_self();
#endif
eina_lock_new(&pool->mutex);
if (!eina_lock_take(&pool->mutex))
{
#ifdef EINA_HAVE_DEBUG_THREADS
- assert(pthread_equal(pool->self, pthread_self()));
+ assert(eina_thread_equal(pool->self, eina_thread_self()));
#endif
}
#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 "eet_suite.h"
END_TEST
-#ifdef EINA_HAVE_THREADS
-
static Eina_Bool open_worker_stop;
-# ifdef _EET_INCLUDED_PTHREAD
-
static void *
-open_close_worker(void *path)
+open_close_worker(void *path, Eina_Thread tid EINA_UNUSED)
{
while (!open_worker_stop)
{
Eet_File *ef = eet_open((char const *)path, EET_FILE_MODE_READ);
if (ef == NULL)
- pthread_exit("eet_open() failed");
+ return "eet_open() failed";
else
{
Eet_Error err_code = eet_close(ef);
if (err_code != EET_ERROR_NONE)
- pthread_exit("eet_close() failed");
+ return "eet_close() failed";
}
}
- pthread_exit(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 */
+ return NULL;
+}
START_TEST(eet_cache_concurrency)
{
Eet_File *ef;
void *thread_ret;
unsigned int n;
-# ifdef _EET_INCLUDED_PTHREAD
- pthread_t thread;
-# else /* ifdef _EET_INCLUDED_PTHREAD */
- uintptr_t thread;
- unsigned int thread_id;
- DWORD ret;
-# endif /* ifdef _EET_INCLUDED_PTHREAD */
+ Eina_Thread thread;
eet_init();
eina_threads_init();
/* start a thread that repeatedly opens and closes a file */
open_worker_stop = 0;
-# ifdef _EET_INCLUDED_PTHREAD
- 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 */
+ eina_thread_create(&thread, EINA_THREAD_NORMAL, -1, open_close_worker, file);
+
/* clear the cache repeatedly in this thread */
for (n = 0; n < 20000; ++n)
{
/* join the other thread, and fail if it returned an error message */
open_worker_stop = 1;
-# ifdef _EET_INCLUDED_PTHREAD
- fail_if(pthread_join(thread, &thread_ret) != 0);
+ thread_ret = eina_thread_join(thread);
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);
}
END_TEST
-#endif /* EINA_HAVE_THREADS */
-
typedef struct _Eet_Connection_Data Eet_Connection_Data;
struct _Eet_Connection_Data
{
suite_add_tcase(s, tc);
#endif /* ifdef HAVE_CIPHER */
-#ifdef EINA_HAVE_THREADS
tc = tcase_create("Eet Cache");
tcase_add_test(tc, eet_cache_concurrency);
suite_add_tcase(s, tc);
-#endif /* ifdef EFL_HAVE_THREADS */
tc = tcase_create("Eet Connection");
tcase_add_test(tc, eet_connection_check);
# include "config.h"
#endif
-#if defined(EFL_HAVE_THREADS) && defined __linux__
-#include <pthread.h>
+#ifdef __linux__
#include <errno.h>
#include <sys/resource.h>
#endif
#include "eina_suite.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
*/
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 niceval2;
{
int niceval = getpriority(PRIO_PROCESS, 0);
int niceval2;
- pthread_t tid;
+ Eina_Thread tid;
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);
/* niceness of main thread should not have changed */
fail_if(niceval2 != niceval);
- pthread_join(tid, NULL);
+ eina_thread_join(tid);
/* niceness of main thread should not have changed */
fail_if(niceval2 != niceval);