forked from enlightenment/efl
use Win32 native mutex on Windows. To use it, pass the following option
to configure: --enable-win32-threads By default, pthreads are used SVN revision: 50220
This commit is contained in:
parent
9f425c5892
commit
c97a897584
|
@ -37,8 +37,9 @@ m4/efl_compiler_flag.m4 \
|
|||
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
|
||||
|
||||
|
|
|
@ -84,11 +84,21 @@ EFL_CHECK_CPU_SSE([have_sse="yes"], [have_sse="no"])
|
|||
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
|
||||
|
||||
|
@ -566,7 +576,12 @@ echo " Safety checks........: ${have_safety_checks}"
|
|||
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
|
||||
|
|
|
@ -8,5 +8,5 @@ Description: A Library that implements fast data types and miscellaneous tools
|
|||
@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
|
||||
|
|
|
@ -1,130 +0,0 @@
|
|||
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])
|
||||
|
||||
])
|
|
@ -0,0 +1,189 @@
|
|||
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])
|
||||
|
||||
])
|
|
@ -109,6 +109,12 @@
|
|||
* 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
|
||||
|
|
|
@ -120,7 +120,7 @@
|
|||
} \
|
||||
} 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);
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef EFL_HAVE_PTHREAD
|
||||
#ifdef EFL_HAVE_THREADS
|
||||
# ifdef _WIN32
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
|
@ -34,7 +34,9 @@
|
|||
# define _GNU_SOURCE
|
||||
# include <sched.h>
|
||||
# endif
|
||||
# include <pthread.h>
|
||||
# ifdef EFL_HAVE_POSIX_THREADS
|
||||
# include <pthread.h>
|
||||
# endif
|
||||
|
||||
# define TH_MAX 8
|
||||
#endif
|
||||
|
@ -126,7 +128,7 @@ EAPI Eina_Cpu_Features eina_cpu_features_get(void)
|
|||
|
||||
EAPI int eina_cpu_count(void)
|
||||
{
|
||||
#ifdef EFL_HAVE_PTHREAD
|
||||
#ifdef EFL_HAVE_THREADS
|
||||
|
||||
# if defined (_WIN32)
|
||||
SYSTEM_INFO sysinfo;
|
||||
|
|
|
@ -271,7 +271,7 @@
|
|||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef EFL_HAVE_PTHREAD
|
||||
#ifdef EFL_HAVE_POSIX_THREADS
|
||||
# include <pthread.h>
|
||||
#endif
|
||||
|
||||
|
@ -337,27 +337,19 @@ static Eina_Bool _disable_function = EINA_FALSE;
|
|||
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;
|
||||
|
||||
# ifdef EFL_HAVE_POSIX_THREADS
|
||||
|
||||
typedef pthread_t Thread;
|
||||
|
||||
static pthread_t _main_thread;
|
||||
|
||||
# define IS_MAIN(t) pthread_equal(t, _main_thread)
|
||||
# define IS_OTHER(t) EINA_UNLIKELY(!IS_MAIN(t))
|
||||
|
||||
# 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
|
||||
# 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())) { \
|
||||
|
@ -367,39 +359,12 @@ static pthread_t _main_thread;
|
|||
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", \
|
||||
|
@ -407,8 +372,8 @@ static pthread_spinlock_t _log_lock;
|
|||
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); \
|
||||
|
@ -417,31 +382,58 @@ static pthread_spinlock_t _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_PTHREAD_SPINLOCK */
|
||||
# endif /* ! EFL_HAVE_POSIX_THREADS_SPINLOCK */
|
||||
|
||||
#else /* ! EFL_HAVE_PTHREAD */
|
||||
# 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() do {} while (0)
|
||||
# define INIT() (1)
|
||||
# define SHUTDOWN() do {} while (0)
|
||||
|
||||
#endif /* ! EFL_HAVE_PTHREAD */
|
||||
#endif /* ! EFL_HAVE_THREADS */
|
||||
|
||||
|
||||
// List of domains registered
|
||||
|
@ -721,23 +713,18 @@ eina_log_print_prefix_NOthreads_color_file_NOfunc(FILE *fp, const Eina_Log_Domai
|
|||
}
|
||||
|
||||
/** 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);
|
||||
|
@ -746,19 +733,14 @@ eina_log_print_prefix_threads_NOcolor_file_func(FILE *fp, const Eina_Log_Domain
|
|||
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);
|
||||
|
@ -767,19 +749,14 @@ eina_log_print_prefix_threads_NOcolor_NOfile_func(FILE *fp, const Eina_Log_Domai
|
|||
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);
|
||||
|
@ -789,10 +766,10 @@ eina_log_print_prefix_threads_NOcolor_file_NOfunc(FILE *fp, const Eina_Log_Domai
|
|||
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
|
||||
|
@ -809,7 +786,7 @@ eina_log_print_prefix_threads_color_file_func(FILE *fp, const Eina_Log_Domain *d
|
|||
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);
|
||||
|
@ -839,10 +816,10 @@ eina_log_print_prefix_threads_color_file_func(FILE *fp, const Eina_Log_Domain *d
|
|||
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
|
||||
|
@ -859,7 +836,7 @@ eina_log_print_prefix_threads_color_NOfile_func(FILE *fp, const Eina_Log_Domain
|
|||
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);
|
||||
|
@ -886,10 +863,10 @@ eina_log_print_prefix_threads_color_NOfile_func(FILE *fp, const Eina_Log_Domain
|
|||
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
|
||||
|
@ -906,7 +883,7 @@ eina_log_print_prefix_threads_color_file_NOfunc(FILE *fp, const Eina_Log_Domain
|
|||
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);
|
||||
|
@ -924,7 +901,7 @@ eina_log_print_prefix_threads_color_file_NOfunc(FILE *fp, const Eina_Log_Domain
|
|||
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;
|
||||
|
||||
|
@ -942,7 +919,7 @@ eina_log_print_prefix_update(void)
|
|||
#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)
|
||||
|
@ -1411,7 +1388,7 @@ eina_log_shutdown(void)
|
|||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
#ifdef EFL_HAVE_PTHREAD
|
||||
#ifdef EFL_HAVE_THREADS
|
||||
|
||||
/**
|
||||
* @internal
|
||||
|
@ -1425,9 +1402,9 @@ eina_log_shutdown(void)
|
|||
void
|
||||
eina_log_threads_init(void)
|
||||
{
|
||||
_main_thread = pthread_self();
|
||||
_threads_enabled = EINA_TRUE;
|
||||
INIT();
|
||||
_main_thread = SELF();
|
||||
if (INIT())
|
||||
_threads_enabled = EINA_TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1574,7 +1551,7 @@ EAPI int EINA_LOG_DOMAIN_GLOBAL = 0;
|
|||
EAPI void
|
||||
eina_log_threads_enable(void)
|
||||
{
|
||||
#ifdef EFL_HAVE_PTHREAD
|
||||
#ifdef EFL_HAVE_THREADS
|
||||
_threads_enabled = 1;
|
||||
eina_log_print_prefix_update();
|
||||
#endif
|
||||
|
@ -1650,8 +1627,8 @@ eina_log_level_get(void)
|
|||
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
|
||||
|
@ -2078,23 +2055,21 @@ eina_log_print_cb_file(const Eina_Log_Domain *d, __UNUSED__ Eina_Log_Level level
|
|||
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);
|
||||
|
@ -2129,7 +2104,29 @@ eina_log_print_unlocked(int domain, Eina_Log_Level level, const char *file, cons
|
|||
|
||||
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))
|
||||
|
|
|
@ -22,10 +22,16 @@
|
|||
# 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"
|
||||
|
@ -55,7 +61,7 @@ EAPI Eina_Version *eina_version = &_version;
|
|||
*/
|
||||
|
||||
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;
|
||||
|
@ -70,16 +76,23 @@ 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
|
||||
|
@ -262,8 +275,14 @@ eina_shutdown(void)
|
|||
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;
|
||||
|
@ -302,7 +321,7 @@ eina_threads_init(void)
|
|||
EAPI int
|
||||
eina_threads_shutdown(void)
|
||||
{
|
||||
#ifdef EFL_HAVE_PTHREAD
|
||||
#ifdef EFL_HAVE_THREADS
|
||||
int ret;
|
||||
|
||||
LOCK();
|
||||
|
@ -320,6 +339,10 @@ eina_threads_shutdown(void)
|
|||
|
||||
UNLOCK_FORCE();
|
||||
|
||||
# ifdef EFL_HAVE_WIN32_THREADS
|
||||
if (_mutex) CloseHandle(_mutex);
|
||||
# endif
|
||||
|
||||
return ret;
|
||||
#else
|
||||
return 0;
|
||||
|
|
|
@ -70,7 +70,7 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef EFL_HAVE_PTHREAD
|
||||
#ifdef EFL_HAVE_POSIX_THREADS
|
||||
# include <pthread.h>
|
||||
#endif
|
||||
|
||||
|
@ -180,21 +180,32 @@ static int _eina_stringshare_log_dom = -1;
|
|||
|
||||
|
||||
|
||||
#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
|
||||
|
||||
|
||||
|
@ -1014,7 +1025,7 @@ eina_stringshare_shutdown(void)
|
|||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
#ifdef EFL_HAVE_PTHREAD
|
||||
#ifdef EFL_HAVE_THREADS
|
||||
|
||||
/**
|
||||
* @internal
|
||||
|
|
|
@ -26,10 +26,16 @@
|
|||
#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"
|
||||
|
@ -57,8 +63,12 @@ struct _Chained_Mempool
|
|||
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
|
||||
};
|
||||
|
||||
|
@ -100,8 +110,12 @@ eina_chained_mempool_malloc(void *data, __UNUSED__ unsigned int size)
|
|||
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
|
||||
|
@ -122,7 +136,11 @@ eina_chained_mempool_malloc(void *data, __UNUSED__ unsigned int size)
|
|||
if (!p)
|
||||
{
|
||||
#ifdef EFL_HAVE_PTHREAD
|
||||
# ifdef EFL_HAVE_POSIX_THREADS
|
||||
pthread_mutex_unlock(&pool->mutex);
|
||||
# else
|
||||
ReleaseMutex(pool->mutex);
|
||||
# endif
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
@ -138,9 +156,14 @@ eina_chained_mempool_malloc(void *data, __UNUSED__ unsigned int size)
|
|||
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;
|
||||
}
|
||||
|
||||
|
@ -156,8 +179,12 @@ eina_chained_mempool_free(void *data, void *ptr)
|
|||
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)
|
||||
|
@ -187,8 +214,12 @@ eina_chained_mempool_free(void *data, void *ptr)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef EFL_HAVE_PTHREAD
|
||||
#ifdef EFL_HAVE_THREADS
|
||||
# ifdef EFL_HAVE_POSIX_THREADS
|
||||
pthread_mutex_unlock(&pool->mutex);
|
||||
# else
|
||||
ReleaseMutex(pool->mutex);
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -218,8 +249,12 @@ eina_chained_mempool_init(const char *context, __UNUSED__ const char *option, va
|
|||
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;
|
||||
|
@ -245,8 +280,12 @@ eina_chained_mempool_shutdown(void *data)
|
|||
_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);
|
||||
|
|
Loading…
Reference in New Issue