eet: use eina_lock.
authorcedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sat, 14 May 2011 09:07:51 +0000 (09:07 +0000)
committercedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sat, 14 May 2011 09:07:51 +0000 (09:07 +0000)
git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/eet@59378 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

configure.ac
m4/efl_threads.m4 [deleted file]
src/lib/Makefile.am
src/lib/eet_lib.c
src/tests/eet_suite.c

index 006b3e7..465d033 100644 (file)
@@ -331,22 +331,6 @@ fi
 AC_MSG_CHECKING(whether to activate signature support in eet)
 AC_MSG_RESULT(${have_signature})
 
-# pthread library
-
-EFL_CHECK_THREADS(["no"],
-   [
-    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 header files
 
 AC_CHECK_HEADER([zlib.h],
@@ -472,7 +456,6 @@ if test "x${have_gnutls}" = "xyes" || test "x${have_openssl}" = "xyes" ; then
    echo "    Cipher support.....: ${have_cipher}"
    echo "    Signature..........: ${have_signature}"
 fi
-echo "  Thread Support.......: ${have_threads}"
 echo
 echo "  Old eet file format..: ${old_eet_file_format}"
 echo
diff --git a/m4/efl_threads.m4 b/m4/efl_threads.m4
deleted file mode 100644 (file)
index 7c1a0b6..0000000
+++ /dev/null
@@ -1,189 +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 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_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)
-
-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])
-
-])
index 9f8bcab..83489e8 100644 (file)
@@ -150,9 +150,9 @@ else
 libeet_la_SOURCES = $(base_sources)
 endif
 
-libeet_la_CFLAGS = @EET_CFLAGS@ @DEBUG_CFLAGS@ @EFL_PTHREAD_CFLAGS@
+libeet_la_CFLAGS = @EET_CFLAGS@ @DEBUG_CFLAGS@
 libeet_la_LIBADD = @GNUTLS_LIBS@ @OPENSSL_LIBS@ @EFL_COVERAGE_LIBS@ @EET_LIBS@ @EINA_LIBS@ @EVIL_LIBS@ -lz -ljpeg -lm
-libeet_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -version-info @version_info@ @release_info@ @EFL_PTHREAD_LIBS@
+libeet_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -version-info @version_info@ @release_info@
 
 EXTRA_DIST = Eet_private.h
 
index 4c694e5..7206ed9 100644 (file)
@@ -46,6 +46,8 @@ void *    alloca (size_t);
 # include <Evil.h>
 #endif /* ifdef HAVE_EVIL */
 
+#include <Eina.h>
+
 #ifdef HAVE_GNUTLS
 # include <gnutls/gnutls.h>
 # include <gcrypt.h>
@@ -56,14 +58,11 @@ void *    alloca (size_t);
 # include <openssl/evp.h>
 #endif /* ifdef HAVE_OPENSSL */
 
-#ifdef EFL_HAVE_POSIX_THREADS
-# include <pthread.h>
+#ifdef EINA_HAVE_THREADS
 # ifdef HAVE_GNUTLS
 GCRY_THREAD_OPTION_PTHREAD_IMPL;
 # endif /* ifdef HAVE_GNUTLS */
-#endif /* ifdef EFL_HAVE_POSIX_THREADS */
-
-#include <Eina.h>
+#endif /* ifdef EINA_HAVE_THREADS */
 
 #include "Eet.h"
 #include "Eet_private.h"
@@ -108,13 +107,7 @@ struct _Eet_File
 
    time_t               mtime;
 
-#ifdef EFL_HAVE_THREADS
-# ifdef EFL_HAVE_POSIX_THREADS
-   pthread_mutex_t      file_lock;
-# else /* ifdef EFL_HAVE_POSIX_THREADS */
-   HANDLE               file_lock;
-# endif /* ifdef EFL_HAVE_POSIX_THREADS */
-#endif /* ifdef EFL_HAVE_THREADS */
+   Eina_Lock            file_lock;
 
    unsigned char        writes_pending : 1;
    unsigned char        delete_me_now : 1;
@@ -244,45 +237,15 @@ static int                read_data_from_disk(Eet_File      *ef,
 
 static Eet_Error          eet_internal_close(Eet_File *ef, Eina_Bool locked);
 
-#ifdef EFL_HAVE_THREADS
-
-# ifdef EFL_HAVE_POSIX_THREADS
-
-static pthread_mutex_t eet_cache_lock = PTHREAD_MUTEX_INITIALIZER;
-
-#  define LOCK_CACHE   pthread_mutex_lock(&eet_cache_lock)
-#  define UNLOCK_CACHE pthread_mutex_unlock(&eet_cache_lock)
-
-#  define INIT_FILE(File)    pthread_mutex_init(&File->file_lock, NULL)
-#  define LOCK_FILE(File)    pthread_mutex_lock(&File->file_lock)
-#  define UNLOCK_FILE(File)  pthread_mutex_unlock(&File->file_lock)
-#  define DESTROY_FILE(File) pthread_mutex_destroy(&File->file_lock)
-
-# else /* EFL_HAVE_WIN32_THREADS */
+static Eina_Lock          eet_cache_lock;
 
-static HANDLE eet_cache_lock = NULL;
+#define LOCK_CACHE        eina_lock_take(&eet_cache_lock)
+#define UNLOCK_CACHE      eina_lock_release(&eet_cache_lock)
 
-#  define LOCK_CACHE   WaitForSingleObject(eet_cache_lock, INFINITE)
-#  define UNLOCK_CACHE ReleaseMutex(eet_cache_lock)
-
-#  define INIT_FILE(File)    File->file_lock = CreateMutex(NULL, FALSE, NULL)
-#  define LOCK_FILE(File)    WaitForSingleObject(File->file_lock, INFINITE)
-#  define UNLOCK_FILE(File)  ReleaseMutex(File->file_lock)
-#  define DESTROY_FILE(File) CloseHandle(File->file_lock)
-
-# endif /* EFL_HAVE_WIN32_THREADS */
-
-#else /* ifdef EFL_HAVE_THREADS */
-
-# define LOCK_CACHE   do {} while (0)
-# define UNLOCK_CACHE do {} while (0)
-
-# define INIT_FILE(File)    do {} while (0)
-# define LOCK_FILE(File)    do {} while (0)
-# define UNLOCK_FILE(File)  do {} while (0)
-# define DESTROY_FILE(File) do {} while (0)
-
-#endif /* EFL_HAVE_THREADS */
+#define INIT_FILE(File)    eina_lock_new(&File->file_lock)
+#define LOCK_FILE(File)    eina_lock_take(&File->file_lock)
+#define UNLOCK_FILE(File)  eina_lock_release(&File->file_lock)
+#define DESTROY_FILE(File) eina_lock_free(&File->file_lock)
 
 /* cache. i don't expect this to ever be large, so arrays will do */
 static int eet_writers_num = 0;
@@ -717,6 +680,8 @@ eet_init(void)
         goto shutdown_eina;
      }
 
+   eina_lock_new(&eet_cache_lock);
+
    if (!eet_node_init())
      {
         EINA_LOG_ERR("Eet: Eet_Node mempool creation failed");
@@ -743,12 +708,12 @@ eet_init(void)
               "BIG FAT WARNING: I AM UNABLE TO REQUEST SECMEM, Cryptographic operation are at risk !");
      }
 
-# ifdef EFL_HAVE_POSIX_THREADS
+# ifdef EINA_HAVE_THREADS
    if (gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread))
       WRN(
          "YOU ARE USING PTHREADS, BUT I CANNOT INITIALIZE THREADSAFE GCRYPT OPERATIONS!");
 
-# endif /* ifdef EFL_HAVE_POSIX_THREADS */
+# endif /* ifdef EINA_HAVE_THREADS */
    if (gnutls_global_init())
       goto shutdown_eet;
 
@@ -762,7 +727,7 @@ eet_init(void)
 
 #ifdef HAVE_GNUTLS
 shutdown_eet:
-#endif   
+#endif
    eet_node_shutdown();
 unregister_log_domain:
    eina_log_domain_unregister(_eet_log_dom_global);
@@ -780,6 +745,9 @@ eet_shutdown(void)
 
    eet_clearcache();
    eet_node_shutdown();
+
+   eina_lock_free(&eet_cache_lock);
+
 #ifdef HAVE_GNUTLS
    gnutls_global_deinit();
 #endif /* ifdef HAVE_GNUTLS */
index af96a91..ce49db5 100644 (file)
 #include <fcntl.h>
 #include <unistd.h>
 
-#ifdef EFL_HAVE_POSIX_THREADS
+#include <Eina.h>
+
+#ifdef EINA_HAVE_THREADS
+#if ((!defined(_WIN32_WCE)) && (!defined(_WIN32)))
 # include <pthread.h>
-#endif /* ifdef EFL_HAVE_POSIX_THREADS */
+# define _EET_INCLUDED_PTHREAD
+#endif
+#endif /* ifdef EINA_HAVE_THREADS */
 
 #include <check.h>
 
-#include <Eina.h>
-
 #include "eet_suite.h"
 
 START_TEST(eet_test_init)
@@ -1838,11 +1841,11 @@ START_TEST(eet_cipher_decipher_simple)
 
 END_TEST
 
-#ifdef EFL_HAVE_THREADS
+#ifdef EINA_HAVE_THREADS
 
 static Eina_Bool open_worker_stop;
 
-# ifdef EFL_HAVE_POSIX_THREADS
+# ifdef _EET_INCLUDED_PTHREAD
 
 static void *
 open_close_worker(void * path)
@@ -1863,7 +1866,7 @@ open_close_worker(void * path)
    pthread_exit(NULL);
 } /* open_close_worker */
 
-# else /* ifdef EFL_HAVE_POSIX_THREADS */
+# else /* ifdef _EET_INCLUDED_PTHREAD */
 
 static unsigned int __stdcall
 open_close_worker(void * path)
@@ -1884,7 +1887,7 @@ open_close_worker(void * path)
    _endthreadex(0);
 } /* open_close_worker */
 
-# endif /* ifdef EFL_HAVE_POSIX_THREADS */
+# endif /* ifdef _EET_INCLUDED_PTHREAD */
 
 START_TEST(eet_cache_concurrency)
 {
@@ -1893,15 +1896,16 @@ START_TEST(eet_cache_concurrency)
    Eet_File * ef;
    void * thread_ret;
    unsigned int n;
-# ifdef EFL_HAVE_POSIX_THREADS
+# ifdef _EET_INCLUDED_PTHREAD
    pthread_t thread;
-# else /* ifdef EFL_HAVE_POSIX_THREADS */
+# else /* ifdef _EET_INCLUDED_PTHREAD */
    uintptr_t thread;
    unsigned int thread_id;
    DWORD ret;
-# endif /* ifdef EFL_HAVE_POSIX_THREADS */
+# endif /* ifdef _EET_INCLUDED_PTHREAD */
 
    eet_init();
+   eina_threads_init();
 
    /* create a file to test with */
    fail_if(!(file = tmpnam(file)));
@@ -1911,11 +1915,11 @@ START_TEST(eet_cache_concurrency)
 
    /* start a thread that repeatedly opens and closes a file */
    open_worker_stop = 0;
-# ifdef EFL_HAVE_POSIX_THREADS
+# ifdef _EET_INCLUDED_PTHREAD
    pthread_create(&thread, NULL, open_close_worker, file);
-# else /* ifdef EFL_HAVE_POSIX_THREADS */
+# else /* ifdef _EET_INCLUDED_PTHREAD */
    thread = _beginthreadex(NULL, 0, open_close_worker, file, 0, &thread_id);
-# endif /* ifdef EFL_HAVE_POSIX_THREADS */
+# endif /* ifdef _EET_INCLUDED_PTHREAD */
    /* clear the cache repeatedly in this thread */
    for (n = 0; n < 50000; ++n)
      {
@@ -1924,22 +1928,24 @@ START_TEST(eet_cache_concurrency)
 
    /* join the other thread, and fail if it returned an error message */
    open_worker_stop = 1;
-# ifdef EFL_HAVE_POSIX_THREADS
+# ifdef _EET_INCLUDED_PTHREAD
    fail_if(pthread_join(thread, &thread_ret) != 0);
    fail_unless(thread_ret == NULL, (char const *)thread_ret);
-# else /* ifdef EFL_HAVE_POSIX_THREADS */
+# else /* ifdef _EET_INCLUDED_PTHREAD */
    ret = WaitForSingleObject((HANDLE)thread, INFINITE);
    fail_if(ret != WAIT_OBJECT_0);
    fail_if(GetExitCodeThread((HANDLE)thread, &ret) == FALSE);
    fail_if(ret != 0);
-# endif /* ifdef EFL_HAVE_POSIX_THREADS */
+# endif /* ifdef _EET_INCLUDED_PTHREAD */
 
    fail_if(unlink(file) != 0);
+
+   eina_threads_shutdown();
    eet_shutdown();
 }
 END_TEST
 
-#endif /* EFL_HAVE_THREADS */
+#endif /* EINA_HAVE_THREADS */
 
 typedef struct _Eet_Connection_Data   Eet_Connection_Data;
 struct _Eet_Connection_Data
@@ -2716,7 +2722,7 @@ eet_suite(void)
    suite_add_tcase(s, tc);
 #endif /* ifdef HAVE_CIPHER */
 
-#ifdef EFL_HAVE_THREADS
+#ifdef EINA_HAVE_THREADS
    tc = tcase_create("Eet Cache");
    tcase_add_test(tc, eet_cache_concurrency);
    suite_add_tcase(s, tc);