m4/efl_coverage.m4 \
m4/efl_cpu.m4 \
m4/efl_doxygen.m4 \
-m4/efl_pthread.m4 \
+m4/efl_fnmatch.m4 \
m4/efl_tests.m4 \
+m4/efl_threads.m4 \
m4/eina_bench.m4 \
m4/eina_check.m4
EFL_CHECK_CPU_SSE2([have_sse2="yes"], [have_sse2="no"])
EFL_CHECK_CPU_ALTIVEC([have_altivec="yes"], [have_altivec="no"])
-EFL_CHECK_PTHREAD(["yes"],
- [have_pthread="yes"],
- [have_pthread="no"],
- [have_pthread_spinlock="yes"],
- [have_pthread_spinlock="no"])
+EFL_CHECK_THREADS(["yes"],
+ [
+ if test "x${_efl_have_posix_threads}" = "xyes" ; then
+ have_threads="POSIX"
+ else
+ if test "x${_efl_have_win32_threads}" = "xyes" ; then
+ have_threads="Win32"
+ else
+ have_threads="no"
+ fi
+ fi
+ ],
+ [have_threads="no"],
+ [have_posix_threads_spinlock="yes"],
+ [have_posix_threads_spinlock="no"])
### Additional options to configure
echo " Maximum log level....: ${with_max_log_level}"
echo " Report string usage..: ${have_stringshare_usage}"
echo " Default mempool......: ${have_default_mempool}"
-echo " Thread Support.......: ${have_pthread} (spinlock: ${have_pthread_spinlock})"
+echo $ECHO_N " Thread Support.......: ${have_threads}$ECHO_C"
+if test "${have_threads}" = "POSIX" ; then
+ echo " (spinlock: ${have_posix_threads_spinlock})"
+else
+ echo
+fi
echo " Amalgamation.........: ${do_amalgamation}"
echo " Iconv support........: ${have_iconv}"
echo
@pkgconfig_requires_private@: @requirement_eina@
Version: @VERSION@
Libs: -L${libdir} -leina
-Libs.private: @EFL_FNMATCH_LIBS@ -ldl
+Libs.private: @EFL_FNMATCH_LIBS@ @EFL_PTHREAD_LIBS@ -ldl
Cflags: -I${includedir}/eina-@VMAJ@ -I${includedir}/eina-@VMAJ@/eina
+++ /dev/null
-dnl Copyright (C) 2010 Vincent Torri <vtorri at univ-evry dot fr>
-dnl That code is public domain and can be freely used or copied.
-
-dnl Macro that check if several pthread library is available or not.
-
-dnl Usage: EFL_CHECK_PTHREAD(want_pthread_spin[, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
-dnl Call AC_SUBST(EFL_PTHREAD_CFLAGS)
-dnl Call AC_SUBST(EFL_PTHREAD_LIBS)
-dnl Define EFL_HAVE_PTHREAD
-dnl Define EFL_HAVE_PTHREAD_SPINLOCK
-
-AC_DEFUN([EFL_CHECK_PTHREAD],
-[
-
-dnl configure option
-
-AC_ARG_ENABLE([pthread],
- [AC_HELP_STRING([--disable-pthread], [enable POSIX threads code @<:@default=auto@:>@])],
- [
- if test "x${enableval}" = "xyes" ; then
- _efl_enable_pthread="yes"
- else
- _efl_enable_pthread="no"
- fi
- ],
- [_efl_enable_pthread="auto"])
-
-AC_MSG_CHECKING([whether to build POSIX threads code])
-AC_MSG_RESULT([${_efl_enable_pthread}])
-
-dnl check if the compiler supports pthreads
-
-case "$host_os" in
- mingw*)
- _efl_pthread_cflags=""
- _efl_pthread_libs="-lpthreadGC2"
- ;;
- solaris*)
- _efl_pthread_cflags="-mt"
- _efl_pthread_libs="-mt"
- ;;
- *)
- _efl_pthread_cflags="-pthread"
- _efl_pthread_libs="-pthread"
- ;;
-esac
-
-_efl_have_pthread="no"
-
-if test "x${_efl_enable_pthread}" = "xyes" || test "x${_efl_enable_pthread}" = "xauto" ; then
-
- SAVE_CFLAGS=${CFLAGS}
- CFLAGS="${CFLAGS} ${_efl_pthread_cflags}"
- SAVE_LIBS=${LIBS}
- LIBS="${LIBS} ${_efl_pthread_libs}"
- AC_LINK_IFELSE(
- [AC_LANG_PROGRAM([[
-#include <pthread.h>
- ]],
- [[
-pthread_t id;
-id = pthread_self();
- ]])],
- [_efl_have_pthread="yes"],
- [_efl_have_pthread="no"])
- CFLAGS=${SAVE_CFLAGS}
- LIBS=${SAVE_LIBS}
-
-fi
-
-AC_MSG_CHECKING([whether system support POSIX threads])
-AC_MSG_RESULT([${_efl_have_pthread}])
-if test "$x{_efl_enable_pthread}" = "xyes" && test "x${_efl_have_pthread}" = "xno"; then
- AC_MSG_ERROR([pthread support requested but not found.])
-fi
-
-EFL_PTHREAD_CFLAGS=""
-EFL_PTHREAD_LIBS=""
-if test "x${_efl_have_pthread}" = "xyes" ; then
- EFL_PTHREAD_CFLAGS=${_efl_pthread_cflags}
- EFL_PTHREAD_LIBS=${_efl_pthread_libs}
-fi
-
-AC_SUBST(EFL_PTHREAD_CFLAGS)
-AC_SUBST(EFL_PTHREAD_LIBS)
-
-if test "x${_efl_have_pthread}" = "xyes" ; then
- AC_DEFINE(EFL_HAVE_PTHREAD, 1, [Define to mention that POSIX threads are supported])
-fi
-
-dnl check if the compiler supports pthreads spinlock
-
-_efl_have_pthread_spinlock="no"
-
-if test "x${_efl_have_pthread}" = "xyes" && test "x$1" = "xyes" ; then
-
- SAVE_CFLAGS=${CFLAGS}
- CFLAGS="${CFLAGS} ${EFL_PTHREAD_CFLAGS}"
- SAVE_LIBS=${LIBS}
- LIBS="${LIBS} ${EFL_PTHREAD_LIBS}"
- AC_LINK_IFELSE(
- [AC_LANG_PROGRAM([[
-#include <pthread.h>
- ]],
- [[
-pthread_spinlock_t lock;
-int res;
-res = pthread_spin_init(&lock, PTHREAD_PROCESS_PRIVATE);
- ]])],
- [_efl_have_pthread_spinlock="yes"],
- [_efl_have_pthread_spinlock="no"])
- CFLAGS=${SAVE_CFLAGS}
- LIBS=${SAVE_LIBS}
-
-fi
-
-AC_MSG_CHECKING([whether to build POSIX threads spinlock code])
-AC_MSG_RESULT([${_efl_have_pthread_spinlock}])
-if test "x${_efl_enable_pthread}" = "xyes" && test "x${_efl_have_pthread_spinlock}" = "xno" && test "x$1" = "xyes" ; then
- AC_MSG_WARN([pthread support requested but spinlocks are not supported])
-fi
-
-if test "x${_efl_have_pthread_spinlock}" = "xyes" ; then
- AC_DEFINE(EFL_HAVE_PTHREAD_SPINLOCK, 1, [Define to mention that POSIX threads spinlocks are supported])
-fi
-
-AS_IF([test "x$_efl_have_pthread" = "xyes"], [$2], [$3])
-AS_IF([test "x$_efl_have_pthread_spinlock" = "xyes"], [$4], [$5])
-
-])
--- /dev/null
+dnl Copyright (C) 2010 Vincent Torri <vtorri at univ-evry dot fr>
+dnl That code is public domain and can be freely used or copied.
+
+dnl Macro that check if POSIX or Win32 threads library is available or not.
+
+dnl Usage: EFL_CHECK_THREADS(want_pthread_spin[, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
+dnl Call AC_SUBST(EFL_PTHREAD_CFLAGS)
+dnl Call AC_SUBST(EFL_PTHREAD_LIBS)
+dnl Define EFL_HAVE_POSIX_THREADS or EFL_HAVE_WIN32_THREADS, and EFL_HAVE_THREADS
+dnl Define EFL_HAVE_POSIX_THREADS_SPINLOCK
+
+AC_DEFUN([EFL_CHECK_THREADS],
+[
+
+dnl configure option
+
+AC_ARG_ENABLE([posix-threads],
+ [AC_HELP_STRING([--disable-posix-threads], [enable POSIX threads code @<:@default=auto@:>@])],
+ [
+ if test "x${enableval}" = "xyes" ; then
+ _efl_enable_posix_threads="yes"
+ else
+ _efl_enable_posix_threads="no"
+ fi
+ ],
+ [_efl_enable_posix_threads="auto"])
+
+AC_MSG_CHECKING([whether to build POSIX threads code])
+AC_MSG_RESULT([${_efl_enable_posix_threads}])
+
+AC_ARG_ENABLE([win32-threads],
+ [AC_HELP_STRING([--disable-win32-threads], [enable Win32 threads code @<:@default=no@:>@])],
+ [
+ if test "x${enableval}" = "xyes" ; then
+ _efl_enable_win32_threads="yes"
+ else
+ _efl_enable_win32_threads="no"
+ fi
+ ],
+ [_efl_enable_win32_threads="no"])
+
+AC_MSG_CHECKING([whether to build Windows threads code])
+AC_MSG_RESULT([${_efl_enable_win32_threads}])
+
+dnl
+dnl * no + no
+dnl * yes + no : win32: error, other : pthread
+dnl * yes + yes : win32 : wthread, other : pthread
+dnl * no + yes : win32 : wthread, other : error
+
+if test "x${_efl_enable_posix_threads}" = "xyes" && test "x${_efl_enable_win32_threads}" = "xyes" ; then
+ case "$host_os" in
+ mingw*)
+ _efl_enable_posix_threads=no
+ ;;
+ *)
+ _efl_enable_win32_threads=no
+ ;;
+ esac
+fi
+
+if test "x${_efl_enable_win32_threads}" = "xyes" ; then
+ case "$host_os" in
+ mingw*)
+ ;;
+ *)
+ AC_MSG_ERROR([Win32 threads support requested but non Windows system found.])
+ ;;
+ esac
+fi
+
+if test "x${_efl_enable_posix_threads}" = "xyes" ; then
+ case "$host_os" in
+ mingw*)
+ AC_MSG_ERROR([POSIX threads support requested but Windows system found.])
+ ;;
+ *)
+ ;;
+ esac
+fi
+
+dnl check if the compiler supports POSIX threads
+
+case "$host_os" in
+ mingw*)
+ ;;
+ solaris*)
+ _efl_thread_cflags="-mt"
+ _efl_thread_libs="-mt"
+ ;;
+ *)
+ _efl_thread_cflags="-pthread"
+ _efl_thread_libs="-pthread"
+ ;;
+esac
+
+_efl_have_posix_threads="no"
+_efl_have_win32_threads="no"
+
+if test "x${_efl_enable_posix_threads}" = "xyes" || test "x${_efl_enable_posix_threads}" = "xauto" ; then
+
+ SAVE_CFLAGS=${CFLAGS}
+ CFLAGS="${CFLAGS} ${_efl_threads_cflags}"
+ SAVE_LIBS=${LIBS}
+ LIBS="${LIBS} ${_efl_threads_libs}"
+ AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM([[
+#include <pthread.h>
+ ]],
+ [[
+pthread_t id;
+id = pthread_self();
+ ]])],
+ [_efl_have_posix_threads="yes"],
+ [_efl_have_posix_threads="no"])
+ CFLAGS=${SAVE_CFLAGS}
+ LIBS=${SAVE_LIBS}
+
+fi
+
+AC_MSG_CHECKING([whether system support POSIX threads])
+AC_MSG_RESULT([${_efl_have_posix_threads}])
+if test "$x{_efl_enable_posix_threads}" = "xyes" && test "x${_efl_have_posix_threads}" = "xno"; then
+ AC_MSG_ERROR([POSIX threads support requested but not found.])
+fi
+
+EFL_PTHREAD_CFLAGS=""
+EFL_PTHREAD_LIBS=""
+if test "x${_efl_have_posix_threads}" = "xyes" ; then
+ EFL_PTHREAD_CFLAGS=${_efl_thread_cflags}
+ EFL_PTHREAD_LIBS=${_efl_thread_libs}
+fi
+
+AC_SUBST(EFL_PTHREAD_CFLAGS)
+AC_SUBST(EFL_PTHREAD_LIBS)
+
+if test "x${_efl_have_posix_threads}" = "xyes" ; then
+ AC_DEFINE([EFL_HAVE_POSIX_THREADS], [1], [Define to mention that POSIX threads are supported])
+fi
+
+dnl check if the compiler supports pthreads spinlock
+
+_efl_have_posix_threads_spinlock="no"
+
+if test "x${_efl_have_posix_threads}" = "xyes" && test "x$1" = "xyes" ; then
+
+ SAVE_CFLAGS=${CFLAGS}
+ CFLAGS="${CFLAGS} ${EFL_PTHREAD_CFLAGS}"
+ SAVE_LIBS=${LIBS}
+ LIBS="${LIBS} ${EFL_PTHREAD_LIBS}"
+ AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM([[
+#include <pthread.h>
+ ]],
+ [[
+pthread_spinlock_t lock;
+int res;
+res = pthread_spin_init(&lock, PTHREAD_PROCESS_PRIVATE);
+ ]])],
+ [_efl_have_posix_threads_spinlock="yes"],
+ [_efl_have_posix_threads_spinlock="no"])
+ CFLAGS=${SAVE_CFLAGS}
+ LIBS=${SAVE_LIBS}
+
+fi
+
+AC_MSG_CHECKING([whether to build POSIX threads spinlock code])
+AC_MSG_RESULT([${_efl_have_posix_threads_spinlock}])
+if test "x${_efl_enable_posix_threads}" = "xyes" && test "x${_efl_have_posix_threads_spinlock}" = "xno" && test "x$1" = "xyes" ; then
+ AC_MSG_WARN([POSIX threads support requested but spinlocks are not supported])
+fi
+
+if test "x${_efl_have_posix_threads_spinlock}" = "xyes" ; then
+ AC_DEFINE([EFL_HAVE_POSIX_THREADS_SPINLOCK], [1], [Define to mention that POSIX threads spinlocks are supported])
+fi
+
+if test "x${_efl_enable_win32_threads}" = "xyes" ; then
+ _efl_have_win32_threads="yes"
+ AC_DEFINE([EFL_HAVE_WIN32_THREADS], [1], [Define to mention that Win32 threads are supported])
+fi
+
+if test "x${_efl_have_posix_threads}" = "xyes" || test "x${_efl_have_win32_threads}" = "xyes" ; then
+ AC_DEFINE([EFL_HAVE_THREADS], [1], [Define to mention that POSIX or Win32 threads are supported])
+fi
+
+AS_IF([test "x$_efl_have_posix_threads" = "xyes" || test "x$_efl_have_win32_threads" = "xyes"], [$2], [$3])
+AS_IF([test "x$_efl_have_posix_threads_spinlock" = "xyes"], [$4], [$5])
+
+])
* make it safer, log errors, manage memory more efficiently and more.
*/
+#include <dirent.h>
+
+#ifdef _WIN32
+# include <Evil.h>
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
} \
} while(0);
-#ifdef EFL_HAVE_PTHREAD
+#ifdef EFL_HAVE_THREADS
void eina_stringshare_threads_init(void);
void eina_stringshare_threads_shutdown(void);
void eina_log_threads_init(void);
# include "config.h"
#endif
-#ifdef EFL_HAVE_PTHREAD
+#ifdef EFL_HAVE_THREADS
# ifdef _WIN32
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# define _GNU_SOURCE
# include <sched.h>
# endif
-# include <pthread.h>
+# ifdef EFL_HAVE_POSIX_THREADS
+# include <pthread.h>
+# endif
# define TH_MAX 8
#endif
EAPI int eina_cpu_count(void)
{
-#ifdef EFL_HAVE_PTHREAD
+#ifdef EFL_HAVE_THREADS
# if defined (_WIN32)
SYSTEM_INFO sysinfo;
# include <unistd.h>
#endif
-#ifdef EFL_HAVE_PTHREAD
+#ifdef EFL_HAVE_POSIX_THREADS
# include <pthread.h>
#endif
static Eina_Bool _abort_on_critical = EINA_FALSE;
static int _abort_level_on_critical = EINA_LOG_LEVEL_CRITICAL;
-#ifdef EFL_HAVE_PTHREAD
+#ifdef EFL_HAVE_THREADS
static Eina_Bool _threads_enabled = EINA_FALSE;
-static pthread_t _main_thread;
-# define IS_MAIN(t) pthread_equal(t, _main_thread)
-# define IS_OTHER(t) EINA_UNLIKELY(!IS_MAIN(t))
+# ifdef EFL_HAVE_POSIX_THREADS
-# ifdef _WIN32
-# define CHECK_MAIN(...) \
- do { \
- if (!IS_MAIN(pthread_self())) { \
- pthread_t cur; \
- cur = pthread_self(); \
- fprintf(stderr, \
- "ERR: not main thread! current=%p, main=%p\n", \
- cur.p, _main_thread.p); \
- return __VA_ARGS__; \
- } \
- } while (0)
-# else
+typedef pthread_t 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 CHECK_MAIN(...) \
do { \
if (!IS_MAIN(pthread_self())) { \
return __VA_ARGS__; \
} \
} while (0)
-# endif
-# ifdef EFL_HAVE_PTHREAD_SPINLOCK
+# ifdef EFL_HAVE_POSIX_THREADS_SPINLOCK
static pthread_spinlock_t _log_lock;
-
-# ifdef _WIN32
# define LOG_LOCK() \
- if(_threads_enabled) \
- do { \
- pthread_t cur; \
- cur = pthread_self(); \
- if (0) \
- fprintf(stderr, "+++LOG LOG_LOCKED! [%s, %p]\n", \
- __FUNCTION__, cur.p); \
- if (EINA_UNLIKELY(_threads_enabled)) \
- pthread_spin_lock(&_log_lock); \
- } while (0)
-# define LOG_UNLOCK() \
- if(_threads_enabled) \
- do { \
- pthread_t cur; \
- cur = pthread_self(); \
- if (EINA_UNLIKELY(_threads_enabled)) \
- pthread_spin_unlock(&_log_lock); \
- if (0) \
- fprintf(stderr, \
- "---LOG LOG_UNLOCKED! [%s, %p]\n", \
- __FUNCTION__, cur.p); \
- } while (0)
-# else
-# define LOG_LOCK() \
- if(_threads_enabled) \
+ if(_threads_enabled) \
do { \
if (0) \
fprintf(stderr, "+++LOG LOG_LOCKED! [%s, %lu]\n", \
if (EINA_UNLIKELY(_threads_enabled)) \
pthread_spin_lock(&_log_lock); \
} while (0)
-# define LOG_UNLOCK() \
- if(_threads_enabled) \
+# define LOG_UNLOCK() \
+ if(_threads_enabled) \
do { \
if (EINA_UNLIKELY(_threads_enabled)) \
pthread_spin_unlock(&_log_lock); \
"---LOG LOG_UNLOCKED! [%s, %lu]\n", \
__FUNCTION__, pthread_self()); \
} while (0)
-# endif
-# define INIT() pthread_spin_init(&_log_lock, PTHREAD_PROCESS_PRIVATE);
-# define SHUTDOWN() pthread_spin_destroy(&_log_lock);
+# define INIT() pthread_spin_init(&_log_lock, PTHREAD_PROCESS_PRIVATE)
+# define SHUTDOWN() pthread_spin_destroy(&_log_lock)
-# else /* ! EFL_HAVE_PTHREAD_SPINLOCK */
+# 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() do {} while (0)
-# define SHUTDOWN() do {} while (0)
+# 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 */
-# endif /* ! EFL_HAVE_PTHREAD_SPINLOCK */
+typedef DWORD Thread;
-#else /* ! EFL_HAVE_PTHREAD */
+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() do {} while (0)
+# define INIT() (1)
# define SHUTDOWN() do {} while (0)
-#endif /* ! EFL_HAVE_PTHREAD */
+#endif /* ! EFL_HAVE_THREADS */
// List of domains registered
}
/** threads, No color */
-#ifdef EFL_HAVE_PTHREAD
+#ifdef EFL_HAVE_THREADS
static void
eina_log_print_prefix_threads_NOcolor_file_func(FILE *fp, const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc, int line)
{
- pthread_t cur;
+ Thread cur;
DECLARE_LEVEL_NAME(level);
- cur = pthread_self();
+ cur = SELF();
if (IS_OTHER(cur))
{
-#ifdef _WIN32
- fprintf(fp, "%s:%s[T:%p] %s:%d %s() ",
- name, d->domain_str, cur.p, file, line, fnc);
-#else
fprintf(fp, "%s:%s[T:%lu] %s:%d %s() ",
name, d->domain_str, cur, file, line, fnc);
-#endif
return;
}
fprintf(fp, "%s:%s %s:%d %s() ", name, d->domain_str, file, line, fnc);
static void
eina_log_print_prefix_threads_NOcolor_NOfile_func(FILE *fp, const Eina_Log_Domain *d, Eina_Log_Level level, const char *file __UNUSED__, const char *fnc, int line __UNUSED__)
{
- pthread_t cur;
+ Thread cur;
DECLARE_LEVEL_NAME(level);
- cur = pthread_self();
+ cur = SELF();
if (IS_OTHER(cur))
{
-#ifdef _WIN32
- fprintf(fp, "%s:%s[T:%p] %s() ",
- name, d->domain_str, cur.p, fnc);
-#else
fprintf(fp, "%s:%s[T:%lu] %s() ",
name, d->domain_str, cur, fnc);
-#endif
return;
}
fprintf(fp, "%s:%s %s() ", name, d->domain_str, fnc);
static void
eina_log_print_prefix_threads_NOcolor_file_NOfunc(FILE *fp, const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc __UNUSED__, int line)
{
- pthread_t cur;
+ Thread cur;
DECLARE_LEVEL_NAME(level);
- cur = pthread_self();
+ cur = SELF();
if (IS_OTHER(cur))
{
-#ifdef _WIN32
- fprintf(fp, "%s:%s[T:%p] %s:%d ",
- name, d->domain_str, cur.p, file, line);
-#else
fprintf(fp, "%s:%s[T:%lu] %s:%d ",
name, d->domain_str, cur, file, line);
-#endif
return;
}
fprintf(fp, "%s:%s %s:%d ", name, d->domain_str, file, line);
static void
eina_log_print_prefix_threads_color_file_func(FILE *fp, const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc, int line)
{
- pthread_t cur;
+ Thread cur;
DECLARE_LEVEL_NAME_COLOR(level);
- cur = pthread_self();
+ cur = SELF();
if (IS_OTHER(cur))
{
# ifdef _WIN32
fprintf(fp, "[T:");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
FOREGROUND_GREEN | FOREGROUND_BLUE);
- fprintf(fp, "%lu", (unsigned long)cur.p);
+ fprintf(fp, "%lu", (unsigned long)cur);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
fprintf(fp, "] %s:%d ", file, line);
static void
eina_log_print_prefix_threads_color_NOfile_func(FILE *fp, const Eina_Log_Domain *d, Eina_Log_Level level, const char *file __UNUSED__, const char *fnc, int line __UNUSED__)
{
- pthread_t cur;
+ Thread cur;
DECLARE_LEVEL_NAME_COLOR(level);
- cur = pthread_self();
+ cur = SELF();
if (IS_OTHER(cur))
{
# ifdef _WIN32
fprintf(fp, "[T:");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
FOREGROUND_GREEN | FOREGROUND_BLUE);
- fprintf(fp, "%lu", (unsigned long)cur.p);
+ fprintf(fp, "%lu", (unsigned long)cur);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
fprintf(fp, "%s()", fnc);
static void
eina_log_print_prefix_threads_color_file_NOfunc(FILE *fp, const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc __UNUSED__, int line)
{
- pthread_t cur;
+ Thread cur;
DECLARE_LEVEL_NAME_COLOR(level);
- cur = pthread_self();
+ cur = SELF();
if (IS_OTHER(cur))
{
# ifdef _WIN32
fprintf(fp, "[T:");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
FOREGROUND_GREEN | FOREGROUND_BLUE);
- fprintf(fp, "%lu", (unsigned long)cur.p);
+ fprintf(fp, "%lu", (unsigned long)cur);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
fprintf(fp, "] %s:%d ", 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, Eina_Log_Level level, const char *file, const char *fnc, int line) = eina_log_print_prefix_NOthreads_color_file_func;
#define S(NOthread, NOcolor, NOfile, NOfunc) \
_eina_log_print_prefix = eina_log_print_prefix_##NOthread##threads_##NOcolor##color_##NOfile##file_##NOfunc##func
-#ifdef EFL_HAVE_PTHREAD
+#ifdef EFL_HAVE_THREADS
if (_threads_enabled)
{
if (_disable_color)
return EINA_TRUE;
}
-#ifdef EFL_HAVE_PTHREAD
+#ifdef EFL_HAVE_THREADS
/**
* @internal
void
eina_log_threads_init(void)
{
- _main_thread = pthread_self();
- _threads_enabled = EINA_TRUE;
- INIT();
+ _main_thread = SELF();
+ if (INIT())
+ _threads_enabled = EINA_TRUE;
}
/**
EAPI void
eina_log_threads_enable(void)
{
-#ifdef EFL_HAVE_PTHREAD
+#ifdef EFL_HAVE_THREADS
_threads_enabled = 1;
eina_log_print_prefix_update();
#endif
EAPI Eina_Bool
eina_log_main_thread_check(void)
{
-#ifdef EFL_HAVE_PTHREAD
- return ((!_threads_enabled) || pthread_equal(_main_thread, pthread_self()));
+#ifdef EFL_HAVE_THREADS
+ return ((!_threads_enabled) || IS_MAIN(SELF()));
#else
return EINA_TRUE;
#endif
void *data, va_list args)
{
FILE *f = data;
-#ifdef EFL_HAVE_PTHREAD
+#ifdef EFL_HAVE_THREADS
if (_threads_enabled)
{
- pthread_t cur = pthread_self();
+ Thread cur;
+
+ cur = SELF();
if (IS_OTHER(cur))
{
-# ifdef _WIN32
- fprintf(f, "%s[T:%p] %s:%d %s() ", d->name, cur.p, file, line, fnc);
-# else
fprintf(f, "%s[T:%lu] %s:%d %s() ", d->name, cur, file, line, fnc);
-# endif
goto end;
}
}
#endif
fprintf(f, "%s %s:%d %s() ", d->name, file, line, fnc);
-#ifdef EFL_HAVE_PTHREAD
+#ifdef EFL_HAVE_THREADS
end:
#endif
vfprintf(f, fmt, args);
if (level > d->level) return;
+#ifdef _WIN32
+ {
+ char *wfmt;
+ char *tmp;
+
+ wfmt = strdup(fmt);
+ if (!wfmt)
+ {
+ fprintf(stderr, "ERR: %s: can not allocate memory\n", __FUNCTION__);
+ return;
+ }
+ tmp = wfmt;
+ while (strchr(tmp, "%"))
+ {
+ tmp++;
+ if (*tmp == 'z')
+ *tmp = 'I';
+ }
+ _print_cb(d, level, file, fnc, line, wfmt, _print_cb_data, args);
+ }
+#else
_print_cb(d, level, file, fnc, line, fmt, _print_cb_data, args);
+#endif
if (EINA_UNLIKELY(_abort_on_critical) &&
EINA_UNLIKELY(level <= _abort_level_on_critical))
# include "config.h"
#endif
-#ifdef EFL_HAVE_PTHREAD
+#ifdef EFL_HAVE_POSIX_THREADS
# include <pthread.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_private.h"
#include "eina_types.h"
*/
static int _eina_main_count = 0;
-#ifdef EFL_HAVE_PTHREAD
+#ifdef EFL_HAVE_THREADS
static int _eina_main_thread_count = 0;
#endif
static int _eina_log_dom = -1;
#endif
#define DBG(...) EINA_LOG_DOM_DBG(_eina_log_dom, __VA_ARGS__)
-#ifdef EFL_HAVE_PTHREAD
+#ifdef EFL_HAVE_THREADS
static Eina_Bool _threads_activated = EINA_FALSE;
+# ifdef EFL_HAVE_POSIX_THREADS
static pthread_mutex_t _mutex = PTHREAD_MUTEX_INITIALIZER;
-#define LOCK() if(_threads_activated) pthread_mutex_lock(&_mutex)
-#define UNLOCK() if(_threads_activated) pthread_mutex_unlock(&_mutex)
-#define UNLOCK_FORCE() pthread_mutex_unlock(&_mutex)
+# define LOCK() if(_threads_activated) pthread_mutex_lock(&_mutex)
+# define UNLOCK() if(_threads_activated) pthread_mutex_unlock(&_mutex)
+# define UNLOCK_FORCE() pthread_mutex_unlock(&_mutex)
+# else /* EFL_HAVE_WIN32_THREADS */
+static HANDLE _mutex = NULL;
+# define LOCK() if(_threads_activated) WaitForSingleObject(_mutex, INFINITE)
+# define UNLOCK() if(_threads_activated) ReleaseMutex(_mutex)
+# define UNLOCK_FORCE() ReleaseMutex(_mutex)
+# endif
#else
-#define LOCK() do {} while (0)
-#define UNLOCK() do {} while (0)
-#define UNLOCK_FORCE() do {} while (0)
+# define LOCK() do {} while (0)
+# define UNLOCK() do {} while (0)
+# define UNLOCK_FORCE() do {} while (0)
#endif
/* place module init/shutdown functions here to avoid other modules
EAPI int
eina_threads_init(void)
{
-#ifdef EFL_HAVE_PTHREAD
+#ifdef EFL_HAVE_THREADS
int ret;
+
+# ifdef EFL_HAVE_WIN32_THREADS
+ if (!_mutex)
+ _mutex = CreateMutex(NULL, FALSE, NULL);
+ if (!_mutex) return 0;
+# endif
LOCK();
++_eina_main_thread_count;
EAPI int
eina_threads_shutdown(void)
{
-#ifdef EFL_HAVE_PTHREAD
+#ifdef EFL_HAVE_THREADS
int ret;
LOCK();
UNLOCK_FORCE();
+# ifdef EFL_HAVE_WIN32_THREADS
+ if (_mutex) CloseHandle(_mutex);
+# endif
+
return ret;
#else
return 0;
#include <stdio.h>
#include <string.h>
-#ifdef EFL_HAVE_PTHREAD
+#ifdef EFL_HAVE_POSIX_THREADS
# include <pthread.h>
#endif
-#ifdef EFL_HAVE_PTHREAD
+#ifdef EFL_HAVE_THREADS
static Eina_Bool _stringshare_threads_activated = EINA_FALSE;
-//string < 4
+
+# ifdef EFL_HAVE_POSIX_THREADS
+/* string < 4 */
static pthread_mutex_t _mutex_small = PTHREAD_MUTEX_INITIALIZER;
-//string >= 4
+/* string >= 4 */
static pthread_mutex_t _mutex_big = PTHREAD_MUTEX_INITIALIZER;
-#define STRINGSHARE_LOCK_SMALL() if(_stringshare_threads_activated) pthread_mutex_lock(&_mutex_small)
-#define STRINGSHARE_UNLOCK_SMALL() if(_stringshare_threads_activated) pthread_mutex_unlock(&_mutex_small)
-#define STRINGSHARE_LOCK_BIG() if(_stringshare_threads_activated) pthread_mutex_lock(&_mutex_big)
-#define STRINGSHARE_UNLOCK_BIG() if(_stringshare_threads_activated) pthread_mutex_unlock(&_mutex_big)
-#else
-#define STRINGSHARE_LOCK_SMALL() do {} while (0)
-#define STRINGSHARE_UNLOCK_SMALL() do {} while (0)
-#define STRINGSHARE_LOCK_BIG() do {} while (0)
-#define STRINGSHARE_UNLOCK_BIG() do {} while (0)
+# define STRINGSHARE_LOCK_SMALL() if(_stringshare_threads_activated) pthread_mutex_lock(&_mutex_small)
+# define STRINGSHARE_UNLOCK_SMALL() if(_stringshare_threads_activated) pthread_mutex_unlock(&_mutex_small)
+# define STRINGSHARE_LOCK_BIG() if(_stringshare_threads_activated) pthread_mutex_lock(&_mutex_big)
+# define STRINGSHARE_UNLOCK_BIG() if(_stringshare_threads_activated) pthread_mutex_unlock(&_mutex_big)
+# else /* EFL_HAVE_WIN32_THREADS */
+static HANDLE _mutex_small = NULL;
+static HANDLE _mutex_big = NULL;
+# define STRINGSHARE_LOCK_SMALL() if(_stringshare_threads_activated) WaitForSingleObject(_mutex_small, INFINITE)
+# define STRINGSHARE_UNLOCK_SMALL() if(_stringshare_threads_activated) ReleaseMutex(_mutex_small)
+# define STRINGSHARE_LOCK_BIG() if(_stringshare_threads_activated) WaitForSingleObject(_mutex_big, INFINITE)
+# define STRINGSHARE_UNLOCK_BIG() if(_stringshare_threads_activated) ReleaseMutex(_mutex_big)
+
+# endif /* EFL_HAVE_WIN32_THREADS */
+#else /* EFL_HAVE_THREADS */
+# define STRINGSHARE_LOCK_SMALL() do {} while (0)
+# define STRINGSHARE_UNLOCK_SMALL() do {} while (0)
+# define STRINGSHARE_LOCK_BIG() do {} while (0)
+# define STRINGSHARE_UNLOCK_BIG() do {} while (0)
#endif
return EINA_TRUE;
}
-#ifdef EFL_HAVE_PTHREAD
+#ifdef EFL_HAVE_THREADS
/**
* @internal
#include <stdlib.h>
#include <string.h>
-#ifdef EFL_HAVE_PTHREAD
+#ifdef EFL_HAVE_POSIX_THREADS
#include <pthread.h>
#endif
+#ifdef EFL_HAVE_WIN32_THREADS
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+# undef WIN32_LEAN_AND_MEAN
+#endif
+
#include "eina_inlist.h"
#include "eina_error.h"
#include "eina_module.h"
int item_size;
int pool_size;
int usage;
-#ifdef EFL_HAVE_PTHREAD
+#ifdef EFL_HAVE_THREADS
+# ifdef EFL_HAVE_POSIX_THREADS
pthread_mutex_t mutex;
+# else
+ HANDLE mutex;
+# endif
#endif
};
Chained_Pool *p = NULL;
void *mem;
-#ifdef EFL_HAVE_PTHREAD
+#ifdef EFL_HAVE_THREADS
+# ifdef EFL_HAVE_POSIX_THREADS
pthread_mutex_lock(&pool->mutex);
+# else
+ WaitForSingleObject(pool->mutex, INFINITE);
+# endif
#endif
// look 4 pool from 2nd bucket on
if (!p)
{
#ifdef EFL_HAVE_PTHREAD
+# ifdef EFL_HAVE_POSIX_THREADS
pthread_mutex_unlock(&pool->mutex);
+# else
+ ReleaseMutex(pool->mutex);
+# endif
#endif
return NULL;
}
p->usage++;
pool->usage++;
-#ifdef EFL_HAVE_PTHREAD
+#ifdef EFL_HAVE_THREADS
+# ifdef EFL_HAVE_POSIX_THREADS
pthread_mutex_unlock(&pool->mutex);
+# else
+ ReleaseMutex(pool->mutex);
+# endif
#endif
+
return mem;
}
psize = item_alloc * pool->pool_size;
// look 4 pool
-#ifdef EFL_HAVE_PTHREAD
+#ifdef EFL_HAVE_THREADS
+# ifdef EFL_HAVE_POSIX_THREADS
pthread_mutex_lock(&pool->mutex);
+# else
+ WaitForSingleObject(pool->mutex, INFINITE);
+# endif
#endif
EINA_INLIST_FOREACH(pool->first, p)
}
}
-#ifdef EFL_HAVE_PTHREAD
+#ifdef EFL_HAVE_THREADS
+# ifdef EFL_HAVE_POSIX_THREADS
pthread_mutex_unlock(&pool->mutex);
+# else
+ ReleaseMutex(pool->mutex);
+# endif
#endif
}
memcpy((char*) mp->name, context, length);
}
-#ifdef EFL_HAVE_PTHREAD
+#ifdef EFL_HAVE_THREADS
+# ifdef EFL_HAVE_POSIX_THREADS
pthread_mutex_init(&mp->mutex, NULL);
+# else
+ mp->mutex = CreateMutex(NULL, FALSE, NULL);
+# endif
#endif
return mp;
_eina_chained_mp_pool_free(p);
}
-#ifdef EFL_HAVE_PTHREAD
+#ifdef EFL_HAVE_THREADS
+# ifdef EFL_HAVE_POSIX_THREADS
pthread_mutex_destroy(&mp->mutex);
+# else
+ CloseHandle(mp->mutex);
+# endif
#endif
free(mp);