[eio] add check on some functions (will be used later) and

add native win32 mutex code.

Question: with pthread, if a mutex is initialized with
PTHREAD_MUTEX_INITIALIZER, should it be destroyed  with
pthread_mutex_destroy() ?

SVN revision: 53772
This commit is contained in:
Vincent Torri 2010-10-22 16:44:30 +00:00
parent 318a56c004
commit 9c5ce8345e
2 changed files with 53 additions and 22 deletions

View File

@ -59,6 +59,11 @@ AC_SUBST(VMAJ)
dnl we just have set the version info, then:
AC_SUBST(version_info)
AC_PROG_CC
# pkg-config
PKG_PROG_PKG_CONFIG
# Check whether pkg-config supports Requires.private
if $PKG_CONFIG --atleast-pkgconfig-version 0.22; then
pkgconfig_requires_private="Requires.private"
@ -67,18 +72,18 @@ else
fi
AC_SUBST(pkgconfig_requires_private)
AC_PROG_CC
requirements_eio="eina >= 1.0.0 ecore >= 1.0.0"
PKG_CHECK_MODULES([EIO], [eina >= 1.0.0 ecore >= 1.0.0])
AC_SUBST(requirements_eio)
# doxygen program for documentation building
EFL_CHECK_DOXYGEN([build_doc="yes"], [build_doc="no"])
### Checks for libraries
requirements_eio="eina >= 1.0.0 ecore >= 1.0.0"
PKG_CHECK_MODULES([EIO], [${requirements_eio}])
### Checks for header files
AC_HEADER_ASSERT
AC_HEADER_DIRENT
@ -135,21 +140,23 @@ esac
AC_SUBST(EFL_EIO_BUILD)
### Checks for library functions
AC_CHECK_FUNCS([fchmod])
AC_CHECK_FUNCS([fchmod chown getpwnam getgrnam])
have_splice="no"
AC_TRY_LINK([
AC_TRY_LINK(
[
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
# include <unistd.h>
#endif
#include <fcntl.h>],
[long ret = splice(0,0,1,0,400,0);],
have_splice=yes,
have_splice=no)
#include <fcntl.h>
],
[long ret = splice(0,0,1,0,400,0);],
[have_splice="yes"],
[have_splice="no"])
AC_MSG_CHECKING([whether to use splice for file copy])
AC_MSG_RESULT(${have_splice})
AC_MSG_RESULT([${have_splice}])
if test "x${have_splice}" = "xyes"; then
if test "x${have_splice}" = "xyes" ; then
AC_DEFINE([EFL_HAVE_SPLICE], [1], [Define to mention that splice syscall is supported])
fi

View File

@ -27,6 +27,24 @@
* @cond LOCAL
*/
#ifdef EFL_HAVE_POSIX_THREADS
# define EIO_MUTEX_TYPE pthread_mutex_t
# define EIO_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
# define EIO_MUTEX_INIT(Pool)
# define EIO_MUTEX_LOCK(Pool) pthread_mutex_lock(&Pool->lock)
# define EIO_MUTEX_UNLOCK(Pool) pthread_mutex_unlock(&Pool->lock)
# define EIO_MUTEX_DESTROY(Pool)
#endif
#ifdef EFL_HAVE_WIN32_THREADS
# define EIO_MUTEX_TYPE HANDLE
# define EIO_MUTEX_INITIALIZER NULL
# define EIO_MUTEX_INIT(Pool) Pool.lock = CreateMutex(NULL, FALSE, NULL)
# define EIO_MUTEX_LOCK(Pool) WaitForSingleObject(Pool->lock, INFINITE)
# define EIO_MUTEX_UNLOCK(Pool) ReleaseMutex(Pool->lock)
# define EIO_MUTEX_DESTROY(Pool) CloseHandle(Pool.lock)
#endif
/* Progress pool */
typedef struct _Eio_Alloc_Pool Eio_Alloc_Pool;
@ -35,13 +53,13 @@ struct _Eio_Alloc_Pool
int count;
Eina_Trash *trash;
pthread_mutex_t lock;
EIO_MUTEX_TYPE lock;
};
static int _eio_count = 0;
static Eio_Alloc_Pool progress = { 0, NULL, PTHREAD_MUTEX_INITIALIZER };
static Eio_Alloc_Pool direct_info = { 0, NULL, PTHREAD_MUTEX_INITIALIZER };
static Eio_Alloc_Pool progress = { 0, NULL, EIO_MUTEX_INITIALIZER };
static Eio_Alloc_Pool direct_info = { 0, NULL, EIO_MUTEX_INITIALIZER };
static void *
_eio_pool_malloc(Eio_Alloc_Pool *pool, size_t sz)
@ -50,10 +68,10 @@ _eio_pool_malloc(Eio_Alloc_Pool *pool, size_t sz)
if (pool->count)
{
pthread_mutex_lock(&pool->lock);
EIO_MUTEX_LOCK(pool);
result = eina_trash_pop(&pool->trash);
if (result) pool->count--;
pthread_mutex_unlock(&pool->lock);
EIO_MUTEX_UNLOCK(pool);
}
if (!result) result = malloc(sz);
@ -69,10 +87,10 @@ _eio_pool_free(Eio_Alloc_Pool *pool, void *data)
}
else
{
pthread_mutex_lock(&pool->lock);
EIO_MUTEX_LOCK(pool);
eina_trash_push(&pool->trash, data);
pool->count++;
pthread_mutex_unlock(&pool->lock);
EIO_MUTEX_UNLOCK(pool);
}
}
@ -165,6 +183,9 @@ eio_init(void)
eina_init();
ecore_init();
EIO_MUTEX_INIT(progress);
EIO_MUTEX_INIT(direct_info);
return _eio_count;
}
@ -182,6 +203,9 @@ eio_shutdown(void)
if (_eio_count > 0) return _eio_count;
EIO_MUTEX_DESTROY(direct_info);
EIO_MUTEX_DESTROY(progress);
/* Cleanup pool */
EINA_TRASH_CLEAN(&progress.trash, pg)
free(pg);