forked from enlightenment/efl
add native win32 thread support in ecore_thread. Not tested a lot at all.
SVN revision: 55014
This commit is contained in:
parent
883850c5ec
commit
6b4b7bc42d
|
@ -923,9 +923,21 @@ if test "x${want_epoll}" = "xyes" ; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# basic pthread support
|
# thread support
|
||||||
|
|
||||||
EFL_CHECK_PTHREAD([no], [have_pthread="yes"], [have_pthread="no"])
|
EFL_CHECK_THREADS(
|
||||||
|
[
|
||||||
|
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"])
|
||||||
|
|
||||||
### Checks for types
|
### Checks for types
|
||||||
AC_CHECK_SIZEOF(int, 4)
|
AC_CHECK_SIZEOF(int, 4)
|
||||||
|
@ -1422,7 +1434,7 @@ echo
|
||||||
echo " Core:"
|
echo " Core:"
|
||||||
echo
|
echo
|
||||||
echo " Ecore........................: always"
|
echo " Ecore........................: always"
|
||||||
echo " Thread support.............: $have_pthread"
|
echo " Thread support.............: $have_pthreads"
|
||||||
echo " GLib support...............: $have_glib"
|
echo " GLib support...............: $have_glib"
|
||||||
echo " Always integrate GLib......: $want_glib_integration_always"
|
echo " Always integrate GLib......: $want_glib_integration_always"
|
||||||
echo " Use g_main_loop............: $want_g_main_loop"
|
echo " Use g_main_loop............: $want_g_main_loop"
|
||||||
|
|
|
@ -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,206 @@
|
||||||
|
dnl Copyright (C) 2010 Vincent Torri <vtorri at univ-evry dot fr>
|
||||||
|
dnl rwlock code added by Mike Blumenkrantz <mike at zentific dot com>
|
||||||
|
dnl This 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(ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND])
|
||||||
|
dnl Call AC_SUBST(EFL_PTHREAD_CFLAGS)
|
||||||
|
dnl Call AC_SUBST(EFL_PTHREAD_LIBS)
|
||||||
|
dnl Defines EFL_HAVE_POSIX_THREADS or EFL_HAVE_WIN32_THREADS, and EFL_HAVE_THREADS
|
||||||
|
|
||||||
|
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_threads_cflags="-mt"
|
||||||
|
_efl_threads_libs="-mt"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
_efl_threads_cflags="-pthread"
|
||||||
|
_efl_threads_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_threads_cflags}
|
||||||
|
EFL_PTHREAD_LIBS=${_efl_threads_libs}
|
||||||
|
fi
|
||||||
|
|
||||||
|
AC_SUBST(EFL_PTHREAD_CFLAGS)
|
||||||
|
AC_SUBST(EFL_PTHREAD_LIBS)
|
||||||
|
|
||||||
|
_efl_enable_debug_threads="no"
|
||||||
|
AC_ARG_ENABLE([debug-threads],
|
||||||
|
[AC_HELP_STRING([--enable-debug-threads], [disable assert when you forgot to call eina_threads_init])],
|
||||||
|
[_efl_enable_debug_threads="${enableval}"])
|
||||||
|
|
||||||
|
have_debug_threads="no"
|
||||||
|
if test "x${_efl_have_posix_threads}" = "xyes" -a "x${_efl_enable_debug_threads}" = "xyes"; then
|
||||||
|
have_debug_threads="yes"
|
||||||
|
AC_DEFINE([EFL_DEBUG_THREADS], [1], [Assert when forgot to call eina_threads_init])
|
||||||
|
fi
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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"], [$1], [$2])
|
||||||
|
])
|
||||||
|
|
||||||
|
dnl Usage: EFL_CHECK_SPINLOCK(ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND])
|
||||||
|
dnl Defines EFL_HAVE_POSIX_THREADS_SPINLOCK
|
||||||
|
AC_DEFUN([EFL_CHECK_SPINLOCK],
|
||||||
|
[
|
||||||
|
|
||||||
|
dnl check if the compiler supports pthreads spinlock
|
||||||
|
|
||||||
|
_efl_have_posix_threads_spinlock="no"
|
||||||
|
|
||||||
|
if test "x${_efl_have_posix_threads}" = "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" ; 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
|
||||||
|
AS_IF([test "x$_efl_have_posix_threads_spinlock" = "xyes"], [$1], [$2])
|
||||||
|
])
|
||||||
|
|
|
@ -46,6 +46,6 @@ endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
libecore_la_LIBADD = @dlopen_libs@ @EINA_LIBS@ @EVIL_LIBS@ @GLIB_LIBS@ @WIN32_LIBS@ @LTLIBINTL@ @EFL_PTHREAD_LIBS@ @rt_libs@ -lm
|
libecore_la_LIBADD = @dlopen_libs@ @EINA_LIBS@ @EVIL_LIBS@ @GLIB_LIBS@ @WIN32_LIBS@ @LTLIBINTL@ @EFL_PTHREAD_LIBS@ @rt_libs@ -lm
|
||||||
libecore_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -version-info @version_info@ @release_info@
|
libecore_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -version-info @version_info@ @release_info@ @EFL_PTHREAD_LIBS@
|
||||||
|
|
||||||
EXTRA_DIST = ecore_private.h
|
EXTRA_DIST = ecore_private.h
|
||||||
|
|
|
@ -6,7 +6,12 @@
|
||||||
# include <Evil.h>
|
# include <Evil.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EFL_HAVE_PTHREAD
|
#include "Ecore.h"
|
||||||
|
#include "ecore_private.h"
|
||||||
|
|
||||||
|
#ifdef EFL_HAVE_THREADS
|
||||||
|
|
||||||
|
# ifdef EFL_HAVE_POSIX_THREADS
|
||||||
# include <pthread.h>
|
# include <pthread.h>
|
||||||
# ifdef __linux__
|
# ifdef __linux__
|
||||||
# include <sched.h>
|
# include <sched.h>
|
||||||
|
@ -16,13 +21,6 @@
|
||||||
# include <sys/syscall.h>
|
# include <sys/syscall.h>
|
||||||
# include <errno.h>
|
# include <errno.h>
|
||||||
# endif
|
# endif
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "Ecore.h"
|
|
||||||
#include "ecore_private.h"
|
|
||||||
|
|
||||||
#ifdef EFL_HAVE_PTHREAD
|
|
||||||
# include <pthread.h>
|
|
||||||
|
|
||||||
# define PH(x) pthread_t x
|
# define PH(x) pthread_t x
|
||||||
# define PHE(x, y) pthread_equal(x, y)
|
# define PHE(x, y) pthread_equal(x, y)
|
||||||
|
@ -50,18 +48,128 @@
|
||||||
# define LRWKRL(x) pthread_rwlock_rdlock(&(x));
|
# define LRWKRL(x) pthread_rwlock_rdlock(&(x));
|
||||||
# define LRWKU(x) pthread_rwlock_unlock(&(x));
|
# define LRWKU(x) pthread_rwlock_unlock(&(x));
|
||||||
|
|
||||||
#else /* EFL_HAVE_WIN32_THREADS */
|
# else /* EFL_HAVE_WIN32_THREADS */
|
||||||
|
|
||||||
# define WIN32_LEAN_AND_MEAN
|
# define WIN32_LEAN_AND_MEAN
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
# undef WIN32_LEAN_AND_MEAN
|
# undef WIN32_LEAN_AND_MEAN
|
||||||
|
|
||||||
# error "Please define PH*, CD* and LRWK* on windows"
|
# define PH(x) HANDLE x
|
||||||
|
# define PHE(x, y) ((x) == (y))
|
||||||
|
# define PHS() (HANDLE)GetCurrentThreadId()
|
||||||
|
# define PHC(x, f, d) ((x = CreateThread(NULL, 0, f, d, 0, NULL)) == NULL)
|
||||||
|
# define PHJ(x, p) \
|
||||||
|
do { \
|
||||||
|
if (!PHE(x, PHS())) \
|
||||||
|
{ \
|
||||||
|
WaitForSingleObject(x, INFINITE); \
|
||||||
|
CloseHandle(x); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
# define PHA(x) TerminateThread(x)
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
HANDLE semaphore;
|
||||||
|
LONG threads_count;
|
||||||
|
CRITICAL_SECTION threads_count_lock;
|
||||||
|
} win32_cond;
|
||||||
|
|
||||||
|
# define CD(x) win32_cond *x
|
||||||
|
|
||||||
|
# define CDI(x) \
|
||||||
|
do { \
|
||||||
|
x = (win32_cond *)calloc(1, sizeof(win32_cond)); \
|
||||||
|
if (x) \
|
||||||
|
{ \
|
||||||
|
x->semaphore = CreateSemaphore(NULL, 0, 0x7fffffff, NULL); \
|
||||||
|
if (x->semaphore) \
|
||||||
|
InitializeCriticalSection(&_c->threads_count_lock_); \
|
||||||
|
else \
|
||||||
|
{ \
|
||||||
|
free(x); \
|
||||||
|
x = NULL; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
# define CDD(x) \
|
||||||
|
do { \
|
||||||
|
CloseHandle(x->semaphore); \
|
||||||
|
free(x); \
|
||||||
|
x = NULL; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
# define CDB(x) \
|
||||||
|
do { \
|
||||||
|
EnterCriticalSection(&x->threads_count_lock); \
|
||||||
|
if (x->threads_count > 0) \
|
||||||
|
ReleaseSemaphore(x->semaphore, x->threads_count, NULL); \
|
||||||
|
LeaveCriticalSection (&x->threads_count_lock); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
# define CDW(x, y, t) \
|
||||||
|
do { \
|
||||||
|
DWORD val = t->tv_sec * 1000 + (tv_nsec / 1000000); \
|
||||||
|
LKL(y); \
|
||||||
|
EnterCriticalSection (&x->threads_count_lock); \
|
||||||
|
x->threads_count++; \
|
||||||
|
LeaveCriticalSection (&x->threads_count_lock); \
|
||||||
|
LKU(y); \
|
||||||
|
WaitForingleObject(x->semaphore, val); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
# define LK(x) HANDLE x
|
# define LK(x) HANDLE x
|
||||||
# define LKI(x) x = CreateMutex(NULL, FALSE, NULL)
|
# define LKI(x) x = CreateMutex(NULL, FALSE, NULL)
|
||||||
# define LKD(x) CloseHandle(x)
|
# define LKD(x) CloseHandle(x)
|
||||||
# define LKL(x) WaitForSingleObject(x, INFINITE)
|
# define LKL(x) WaitForSingleObject(x, INFINITE)
|
||||||
# define LKU(x) ReleaseMutex(x)
|
# define LKU(x) ReleaseMutex(x)
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
HANDLE semaphore_read;
|
||||||
|
HANDLE semaphore_write;
|
||||||
|
SRWLOCK l;
|
||||||
|
} win32_rwl;
|
||||||
|
|
||||||
|
# define LRWK(x) win32_rwl *x
|
||||||
|
# define LRWKI(x) \
|
||||||
|
do { \
|
||||||
|
x = (win32_rwl *)calloc(1, sizeof(win32_rwl)); \
|
||||||
|
if (x) \
|
||||||
|
{ \
|
||||||
|
InitializeSRWLock(&x->l); \
|
||||||
|
x->semaphore_read = CreateSemaphore (NULL, 0, 1, NULL); \
|
||||||
|
if (x->semaphore_read) \
|
||||||
|
{ \
|
||||||
|
x->semaphore_write = CreateSemaphore (NULL, 0, 1, NULL); \
|
||||||
|
if (!semaphore_write) \
|
||||||
|
{ \
|
||||||
|
CloseHandle(x->semaphore_read); \
|
||||||
|
free(x); \
|
||||||
|
x = NULL; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
else \
|
||||||
|
{ \
|
||||||
|
free(x); \
|
||||||
|
x = NULL; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
# define LRWKD(x) \
|
||||||
|
do { \
|
||||||
|
CloseHandle(x->semaphore_write); \
|
||||||
|
CloseHandle(x->semaphore_read); \
|
||||||
|
free(x); \
|
||||||
|
} while (0)
|
||||||
|
# define LRWKWL(x) AcquireSRWLockExclusive(&x->l)
|
||||||
|
# define LRWKRL(x) AcquireSRWLockShared(&x->l)
|
||||||
|
# define LRWKU(x) ReleaseSRWLockExclusive(&x->l)
|
||||||
|
|
||||||
|
# endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct _Ecore_Pthread_Worker Ecore_Pthread_Worker;
|
typedef struct _Ecore_Pthread_Worker Ecore_Pthread_Worker;
|
||||||
|
@ -95,7 +203,7 @@ 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_PTHREAD
|
#ifdef EFL_HAVE_THREADS
|
||||||
PH(self);
|
PH(self);
|
||||||
Eina_Hash *hash;
|
Eina_Hash *hash;
|
||||||
CD(cond);
|
CD(cond);
|
||||||
|
@ -109,7 +217,7 @@ struct _Ecore_Pthread_Worker
|
||||||
Eina_Bool kill : 1;
|
Eina_Bool kill : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef EFL_HAVE_PTHREAD
|
#ifdef EFL_HAVE_THREADS
|
||||||
typedef struct _Ecore_Pthread_Data Ecore_Pthread_Data;
|
typedef struct _Ecore_Pthread_Data Ecore_Pthread_Data;
|
||||||
|
|
||||||
struct _Ecore_Pthread_Data
|
struct _Ecore_Pthread_Data
|
||||||
|
@ -136,7 +244,7 @@ _ecore_thread_pipe_get(void)
|
||||||
return ecore_pipe_add(_ecore_thread_handler, NULL);
|
return ecore_pipe_add(_ecore_thread_handler, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef EFL_HAVE_PTHREAD
|
#ifdef EFL_HAVE_THREADS
|
||||||
static int _ecore_thread_count = 0;
|
static int _ecore_thread_count = 0;
|
||||||
|
|
||||||
static Ecore_Event_Handler *del_handler = NULL;
|
static Ecore_Event_Handler *del_handler = NULL;
|
||||||
|
@ -156,19 +264,6 @@ static Eina_Bool have_main_loop_thread = 0;
|
||||||
static Eina_Trash *_ecore_thread_worker_trash = NULL;
|
static Eina_Trash *_ecore_thread_worker_trash = NULL;
|
||||||
static int _ecore_thread_worker_count = 0;
|
static int _ecore_thread_worker_count = 0;
|
||||||
|
|
||||||
static Ecore_Pthread_Worker *
|
|
||||||
_ecore_thread_worker_new(void)
|
|
||||||
{
|
|
||||||
Ecore_Pthread_Worker *result;
|
|
||||||
|
|
||||||
result = eina_trash_pop(&_ecore_thread_worker_trash);
|
|
||||||
|
|
||||||
if (!result) result = malloc(sizeof (Ecore_Pthread_Worker));
|
|
||||||
else _ecore_thread_worker_count--;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_ecore_thread_worker_free(Ecore_Pthread_Worker *worker)
|
_ecore_thread_worker_free(Ecore_Pthread_Worker *worker)
|
||||||
{
|
{
|
||||||
|
@ -457,6 +552,23 @@ _ecore_thread_worker(Ecore_Pthread_Data *pth)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static Ecore_Pthread_Worker *
|
||||||
|
_ecore_thread_worker_new(void)
|
||||||
|
{
|
||||||
|
Ecore_Pthread_Worker *result;
|
||||||
|
|
||||||
|
#ifdef EFL_HAVE_THREADS
|
||||||
|
result = eina_trash_pop(&_ecore_thread_worker_trash);
|
||||||
|
|
||||||
|
if (!result) result = malloc(sizeof (Ecore_Pthread_Worker));
|
||||||
|
else _ecore_thread_worker_count--;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
#else
|
||||||
|
return malloc(sizeof (Ecore_Pthread_Worker));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_ecore_thread_init(void)
|
_ecore_thread_init(void)
|
||||||
{
|
{
|
||||||
|
@ -467,7 +579,7 @@ _ecore_thread_init(void)
|
||||||
ECORE_THREAD_PIPE_DEL = ecore_event_type_new();
|
ECORE_THREAD_PIPE_DEL = ecore_event_type_new();
|
||||||
_ecore_thread_pipe = eina_array_new(8);
|
_ecore_thread_pipe = eina_array_new(8);
|
||||||
|
|
||||||
#ifdef EFL_HAVE_PTHREAD
|
#ifdef EFL_HAVE_THREADS
|
||||||
del_handler = ecore_event_handler_add(ECORE_THREAD_PIPE_DEL, _ecore_thread_pipe_del, NULL);
|
del_handler = ecore_event_handler_add(ECORE_THREAD_PIPE_DEL, _ecore_thread_pipe_del, NULL);
|
||||||
main_loop_thread = PHS();
|
main_loop_thread = PHS();
|
||||||
have_main_loop_thread = 1;
|
have_main_loop_thread = 1;
|
||||||
|
@ -487,7 +599,7 @@ _ecore_thread_shutdown(void)
|
||||||
Eina_Array_Iterator it;
|
Eina_Array_Iterator it;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
#ifdef EFL_HAVE_PTHREAD
|
#ifdef EFL_HAVE_THREADS
|
||||||
Ecore_Pthread_Worker *work;
|
Ecore_Pthread_Worker *work;
|
||||||
Ecore_Pthread_Data *pth;
|
Ecore_Pthread_Data *pth;
|
||||||
|
|
||||||
|
@ -579,7 +691,7 @@ ecore_thread_run(Ecore_Thread_Cb func_blocking,
|
||||||
const void *data)
|
const void *data)
|
||||||
{
|
{
|
||||||
Ecore_Pthread_Worker *work;
|
Ecore_Pthread_Worker *work;
|
||||||
#ifdef EFL_HAVE_PTHREAD
|
#ifdef EFL_HAVE_THREADS
|
||||||
Ecore_Pthread_Data *pth = NULL;
|
Ecore_Pthread_Data *pth = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -601,7 +713,7 @@ ecore_thread_run(Ecore_Thread_Cb func_blocking,
|
||||||
work->kill = EINA_FALSE;
|
work->kill = EINA_FALSE;
|
||||||
work->data = data;
|
work->data = data;
|
||||||
|
|
||||||
#ifdef EFL_HAVE_PTHREAD
|
#ifdef EFL_HAVE_THREADS
|
||||||
work->hash = NULL;
|
work->hash = NULL;
|
||||||
CDI(work->cond);
|
CDI(work->cond);
|
||||||
LKI(work->mutex);
|
LKI(work->mutex);
|
||||||
|
@ -687,7 +799,7 @@ ecore_thread_run(Ecore_Thread_Cb func_blocking,
|
||||||
EAPI Eina_Bool
|
EAPI Eina_Bool
|
||||||
ecore_thread_cancel(Ecore_Thread *thread)
|
ecore_thread_cancel(Ecore_Thread *thread)
|
||||||
{
|
{
|
||||||
#ifdef EFL_HAVE_PTHREAD
|
#ifdef EFL_HAVE_THREADS
|
||||||
Ecore_Pthread_Worker *work = (Ecore_Pthread_Worker *)thread;
|
Ecore_Pthread_Worker *work = (Ecore_Pthread_Worker *)thread;
|
||||||
Eina_List *l;
|
Eina_List *l;
|
||||||
|
|
||||||
|
@ -807,7 +919,7 @@ EAPI Ecore_Thread *ecore_thread_feedback_run(Ecore_Thread_Cb func_heavy,
|
||||||
Eina_Bool try_no_queue)
|
Eina_Bool try_no_queue)
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef EFL_HAVE_PTHREAD
|
#ifdef EFL_HAVE_THREADS
|
||||||
Ecore_Pthread_Worker *worker;
|
Ecore_Pthread_Worker *worker;
|
||||||
Ecore_Pthread_Data *pth = NULL;
|
Ecore_Pthread_Data *pth = NULL;
|
||||||
|
|
||||||
|
@ -947,7 +1059,7 @@ ecore_thread_feedback(Ecore_Thread *thread, const void *data)
|
||||||
if (!worker) return EINA_FALSE;
|
if (!worker) return EINA_FALSE;
|
||||||
if (!worker->feedback_run) return EINA_FALSE;
|
if (!worker->feedback_run) return EINA_FALSE;
|
||||||
|
|
||||||
#ifdef EFL_HAVE_PTHREAD
|
#ifdef EFL_HAVE_THREADS
|
||||||
if (!PHE(worker->self, PHS())) return EINA_FALSE;
|
if (!PHE(worker->self, PHS())) return EINA_FALSE;
|
||||||
|
|
||||||
worker->u.feedback_run.send++;
|
worker->u.feedback_run.send++;
|
||||||
|
@ -970,7 +1082,7 @@ ecore_thread_feedback(Ecore_Thread *thread, const void *data)
|
||||||
EAPI int
|
EAPI int
|
||||||
ecore_thread_active_get(void)
|
ecore_thread_active_get(void)
|
||||||
{
|
{
|
||||||
#ifdef EFL_HAVE_PTHREAD
|
#ifdef EFL_HAVE_THREADS
|
||||||
return _ecore_thread_count;
|
return _ecore_thread_count;
|
||||||
#else
|
#else
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -987,7 +1099,7 @@ EAPI int
|
||||||
ecore_thread_pending_get(void)
|
ecore_thread_pending_get(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
#ifdef EFL_HAVE_PTHREAD
|
#ifdef EFL_HAVE_THREADS
|
||||||
LKL(_ecore_pending_job_threads_mutex);
|
LKL(_ecore_pending_job_threads_mutex);
|
||||||
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);
|
||||||
|
@ -1007,7 +1119,7 @@ EAPI int
|
||||||
ecore_thread_pending_feedback_get(void)
|
ecore_thread_pending_feedback_get(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
#ifdef EFL_HAVE_PTHREAD
|
#ifdef EFL_HAVE_THREADS
|
||||||
LKL(_ecore_pending_job_threads_mutex);
|
LKL(_ecore_pending_job_threads_mutex);
|
||||||
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);
|
||||||
|
@ -1027,7 +1139,7 @@ EAPI int
|
||||||
ecore_thread_pending_total_get(void)
|
ecore_thread_pending_total_get(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
#ifdef EFL_HAVE_PTHREAD
|
#ifdef EFL_HAVE_THREADS
|
||||||
LKL(_ecore_pending_job_threads_mutex);
|
LKL(_ecore_pending_job_threads_mutex);
|
||||||
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);
|
||||||
|
@ -1087,7 +1199,7 @@ EAPI int
|
||||||
ecore_thread_available_get(void)
|
ecore_thread_available_get(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
#ifdef EFL_HAVE_PTHREAD
|
#ifdef EFL_HAVE_THREADS
|
||||||
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);
|
||||||
|
@ -1121,7 +1233,7 @@ ecore_thread_local_data_add(Ecore_Thread *thread, const char *key, void *value,
|
||||||
|
|
||||||
if ((!thread) || (!key) || (!value))
|
if ((!thread) || (!key) || (!value))
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
#ifdef EFL_HAVE_PTHREAD
|
#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)
|
||||||
|
|
Loading…
Reference in New Issue