forked from enlightenment/efl
* eina: add assert to ease tracking down efl misuse with threads.
SVN revision: 53360
This commit is contained in:
parent
625d84003e
commit
f9b8578ea6
|
@ -593,6 +593,7 @@ echo " Default mempool......: ${have_default_mempool}"
|
|||
echo " Thread Support.......: ${have_threads}"
|
||||
if test "${have_threads}" = "POSIX" ; then
|
||||
echo " spinlock...........: ${have_posix_threads_spinlock}"
|
||||
echo " debug usage........: ${have_debug_threads}"
|
||||
fi
|
||||
echo " Amalgamation.........: ${do_amalgamation}"
|
||||
echo " Iconv support........: ${have_iconv}"
|
||||
|
|
|
@ -134,11 +134,21 @@ 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])
|
||||
|
|
|
@ -52,6 +52,10 @@ static int _eina_mempool_log_dom = -1;
|
|||
#define INF(...) EINA_LOG_DOM_INFO(_eina_mempool_log_dom, __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#ifdef EFL_DEBUG_THREADS
|
||||
#include <assert.h>
|
||||
#endif
|
||||
|
||||
typedef struct _Chained_Mempool Chained_Mempool;
|
||||
struct _Chained_Mempool
|
||||
{
|
||||
|
@ -63,6 +67,9 @@ struct _Chained_Mempool
|
|||
int group_size;
|
||||
int usage;
|
||||
#ifdef EFL_HAVE_THREADS
|
||||
#ifdef EFL_DEBUG_THREADS
|
||||
pthread_t self;
|
||||
#endif
|
||||
# ifdef EFL_HAVE_POSIX_THREADS
|
||||
pthread_mutex_t mutex;
|
||||
# else
|
||||
|
@ -127,6 +134,10 @@ eina_chained_mempool_malloc(void *data, __UNUSED__ unsigned int size)
|
|||
WaitForSingleObject(pool->mutex, INFINITE);
|
||||
# endif
|
||||
}
|
||||
#ifdef EFL_DEBUG_THREADS
|
||||
else
|
||||
assert(pool->self == pthread_self());
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// look 4 pool from 2nd bucket on
|
||||
|
@ -214,12 +225,16 @@ eina_chained_mempool_free(void *data, void *ptr)
|
|||
WaitForSingleObject(pool->mutex, INFINITE);
|
||||
# endif
|
||||
}
|
||||
#ifdef EFL_DEBUG_THREADS
|
||||
else
|
||||
assert(pool->self == pthread_self());
|
||||
#endif
|
||||
#endif
|
||||
|
||||
EINA_INLIST_FOREACH(pool->first, p)
|
||||
{
|
||||
// Could the pointer be inside that pool
|
||||
if (ptr < p->limit)
|
||||
if ((unsigned char*) ptr < p->limit)
|
||||
{
|
||||
// pool mem base
|
||||
pmem = (void *)(((unsigned char *)p) + sizeof(Chained_Pool));
|
||||
|
@ -293,6 +308,9 @@ eina_chained_mempool_init(const char *context,
|
|||
mp->item_alloc = eina_mempool_alignof(item_size);
|
||||
mp->group_size = mp->item_alloc * mp->pool_size;
|
||||
mp->alloc_size = mp->group_size + eina_mempool_alignof(sizeof(Chained_Pool));
|
||||
#ifdef EFL_DEBUG_THREADS
|
||||
mp->self = pthread_self();
|
||||
#endif
|
||||
|
||||
#ifdef EFL_HAVE_THREADS
|
||||
# ifdef EFL_HAVE_POSIX_THREADS
|
||||
|
@ -328,6 +346,9 @@ eina_chained_mempool_shutdown(void *data)
|
|||
}
|
||||
|
||||
#ifdef EFL_HAVE_THREADS
|
||||
#ifdef EFL_DEBUG_THREADS
|
||||
assert(mp->self == pthread_self());
|
||||
#endif
|
||||
# ifdef EFL_HAVE_POSIX_THREADS
|
||||
pthread_mutex_destroy(&mp->mutex);
|
||||
# else
|
||||
|
|
Loading…
Reference in New Issue