diff --git a/legacy/eina/ChangeLog b/legacy/eina/ChangeLog index 13e66e4b6d..b68181b2b5 100644 --- a/legacy/eina/ChangeLog +++ b/legacy/eina/ChangeLog @@ -42,13 +42,17 @@ * Add Simple XML parser API. -2011-05-11 Cedric Bail +2011-04-11 Cedric Bail * Add eina_inlist_sort. * Add eina_mempool_repack. * Add Eina_Object API. -2011-05-13 Cedric Bail & Vincent Torri +2011-04-13 Cedric Bail & Vincent Torri * Add Eina_File API. +2011-04-22 Vincent Torri + + * Add Eina_Lock API + diff --git a/legacy/eina/configure.ac b/legacy/eina/configure.ac index c260d0393f..a8374594cd 100644 --- a/legacy/eina/configure.ac +++ b/legacy/eina/configure.ac @@ -110,6 +110,12 @@ EFL_CHECK_THREADS( [have_threads="no"]) EFL_CHECK_SPINLOCK([have_posix_threads_spinlock="yes"], [have_posix_threads_spinlock="no"]) +if ! test "x${have_threads}" = "xno" ; then + EINA_CONFIGURE_HAVE_THREADS="#define EINA_HAVE_THREADS" +fi +AC_SUBST(EINA_CONFIGURE_HAVE_THREADS) +AM_CONDITIONAL([EINA_HAVE_THREADS], [! test "x${have_threads}" = "xno"]) + ### Additional options to configure # Magic debug @@ -364,6 +370,7 @@ AC_C_INLINE AC_C___ATTRIBUTE__ AC_PROG_CC_STDC +have_wince="no" have_win32="no" EINA_CPPFLAGS="" EINA_CFLAGS="" @@ -372,6 +379,7 @@ case "$host_os" in EINA_CPPFLAGS="-D_WIN32_WCE=0x0420" EINA_CFLAGS="${EVIL_CFLAGS}" have_win32="yes" + have_wince="yes" ;; mingw*) EINA_CPPFLAGS="-D_WIN32_WINNT=0x0501" @@ -379,6 +387,7 @@ case "$host_os" in have_win32="yes" ;; esac +AM_CONDITIONAL([EINA_HAVE_WINCE], [test "x$have_wince" = "xyes"]) AM_CONDITIONAL([EINA_HAVE_WIN32], [test "x$have_win32" = "xyes"]) m4_ifdef([v_mic], diff --git a/legacy/eina/src/include/Eina.h b/legacy/eina/src/include/Eina.h index 7c2dfc2b9b..efeefc4c23 100644 --- a/legacy/eina/src/include/Eina.h +++ b/legacy/eina/src/include/Eina.h @@ -159,6 +159,7 @@ extern "C" { #include "eina_quadtree.h" #include "eina_simple_xml_parser.h" #include "eina_object.h" +#include "eina_lock.h" #ifdef __cplusplus } diff --git a/legacy/eina/src/include/Makefile.am b/legacy/eina/src/include/Makefile.am index 5bfbab1c45..5da8fe843a 100644 --- a/legacy/eina/src/include/Makefile.am +++ b/legacy/eina/src/include/Makefile.am @@ -54,7 +54,22 @@ eina_ustrbuf.h \ eina_unicode.h \ eina_quadtree.h \ eina_simple_xml_parser.h \ -eina_object.h +eina_object.h \ +eina_lock.h + +if EINA_HAVE_THREADS +if EINA_HAVE_WINCE +EINAHEADERS += eina_inline_lock_wince.x +else +if EINA_HAVE_WIN32 +EINAHEADERS += eina_inline_lock_win32.x +else +EINAHEADERS += eina_inline_lock_posix.x +endif +endif +else +EINAHEADERS += eina_inline_lock_void.x +endif installed_mainheaderdir = $(includedir)/eina-@VMAJ@ dist_installed_mainheader_DATA = Eina.h eina_config.h diff --git a/legacy/eina/src/include/eina_config.h.in b/legacy/eina/src/include/eina_config.h.in index 56331bb288..6a94f95604 100644 --- a/legacy/eina/src/include/eina_config.h.in +++ b/legacy/eina/src/include/eina_config.h.in @@ -44,6 +44,11 @@ #endif @EINA_CONFIGURE_HAVE_STDINT_H@ +#ifdef EINA_HAVE_THREADS +# undef EINA_HAVE_THREADS +#endif +@EINA_CONFIGURE_HAVE_THREADS@ + #ifdef EINA_SIZEOF_WCHAR_T # undef EINA_SIZEOF_WCHAR_T #endif diff --git a/legacy/eina/src/include/eina_inline_lock_posix.x b/legacy/eina/src/include/eina_inline_lock_posix.x new file mode 100644 index 0000000000..8151a2896d --- /dev/null +++ b/legacy/eina/src/include/eina_inline_lock_posix.x @@ -0,0 +1,58 @@ +/* EINA - EFL data type library + * Copyright (C) 2011 Vincent Torri + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ + +#ifndef EINA_INLINE_LOCK_POSIX_X_ +#define EINA_INLINE_LOCK_POSIX_X_ + +#include + + +typedef pthread_mutex_t Eina_Lock; + +static inline Eina_Bool +eina_lock_new(Eina_Lock *mutex) +{ + return (pthread_mutex_init(mutex, NULL) == 0) ? EINA_TRUE : EINA_FALSE; +} + +static inline void +eina_lock_free(Eina_Lock mutex) +{ + pthread_mutex_destroy(&mutex); +} + +static inline Eina_Bool +eina_lock_take(Eina_Lock mutex) +{ + return (pthread_mutex_lock(&mutex) == 0) ? EINA_TRUE : EINA_FALSE; +} + +static inline Eina_Bool +eina_lock_take_try(Eina_Lock mutex) +{ + return (pthread_mutex_trylock(&mutex) == 0) ? EINA_TRUE : EINA_FALSE; +} + +static inline Eina_Bool +eina_lock_release(Eina_Lock mutex) +{ + return (pthread_mutex_unlock(&mutex) == 0) ? EINA_TRUE : EINA_FALSE; +} + + +#endif diff --git a/legacy/eina/src/include/eina_inline_lock_void.x b/legacy/eina/src/include/eina_inline_lock_void.x new file mode 100644 index 0000000000..2d605a4b27 --- /dev/null +++ b/legacy/eina/src/include/eina_inline_lock_void.x @@ -0,0 +1,131 @@ +/* EINA - EFL data type library + * Copyright (C) 2011 Vincent Torri + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ + +#ifndef EINA_INLINE_LOCK_VOID_X_ +#define EINA_INLINE_LOCK_VOID_X_ + + +/** + * @addtogroup Eina_Lock_Group Lock + * + * @brief These functions provide Mutual Exclusion objects management. + * + * @note On Windows XP, critical sections are used, while on Windows + * CE, standard Mutex objects are used. + * + * @{ + */ + +/** + * @typedef Eina_Lock + * Abtract type for a mutual exclusive object. + */ +typedef void *Eina_Lock; + +/** + * @brief Create a new #Eina_Lock. + * + * @param mutex A pointer to the lock object. + * @return #EINA_TRUE on success, #EINA_FALSE otherwise. + * + * This function creates a new #Eina_Lock object and stores it in the + * @p mutex buffer. On success, this function returns #EINA_TRUE and + * #EINA_FALSE otherwise. To free the resources allocated by this + * function, use eina_lock_free(). For performance reasons, no check + * is done on @p mutex. + */ +static inline Eina_Bool +eina_lock_new(Eina_Lock *mutex) +{ + return EINA_FALSE; +} + +/** + * @brief Free the ressources of the given lock object. + * + * @param mutex The lock object to free. + * + * This function frees the resources of @p mutex allocated by + * eina_lock_new(). For performance reasons, no check is done on + * @p mutex. + */ +static inline void +eina_lock_free(Eina_Lock mutex) +{ +} + +/** + * @brief Lock the given mutual exclusion object. + * + * @param mutex The lock object to lock. + * @return #EINA_TRUE on success, #EINA_FALSE otherwise. + * + * This function locks @p mutex. @p mutex must have been created by + * eina_lock_new(). On success, this function returns #EINA_TRUE and + * #EINA_FALSE otherwise. For performance reasons, no check is done on + * @p mutex. + */ +static inline Eina_Bool +eina_lock_take(Eina_Lock mutex) +{ + return EINA_FALSE; +} + +/** + * @brief Try to lock the given mutual exclusion object. + * + * @param mutex The lock object to try to lock. + * @return #EINA_TRUE on success, #EINA_FALSE otherwise. + * + * This function tries to lock @p mutex. @p mutex must have been created by + * eina_lock_new(). If @p mutex can be locked, this function returns + * #EINA_TRUE; if @p mutex can not be locked, or is already locked, it + * returns #EINA_FALSE. This function does not block and returns + * immediatly. For performance reasons, no check is done on + * @p mutex. + * + * @note On Windows CE, this function is actually eina_lock_take(). + */ +static inline Eina_Bool +eina_lock_take_try(Eina_Lock mutex) +{ + return EINA_FALSE; +} + +/** + * @brief Unlock the given mutual exclusion object. + * + * @param mutex The lock object to unlock. + * @return #EINA_TRUE on success, #EINA_FALSE otherwise. + * + * This function unlocks @p mutex. @p mutex must have been created by + * eina_lock_new(). On success, this function returns #EINA_TRUE and + * #EINA_FALSE otherwise. For performance reasons, no check is done on + * @p mutex. + */ +static inline Eina_Bool +eina_lock_release(Eina_Lock mutex) +{ + return EINA_FALSE; +} + +/** + * @} + */ + +#endif diff --git a/legacy/eina/src/include/eina_inline_lock_win32.x b/legacy/eina/src/include/eina_inline_lock_win32.x new file mode 100644 index 0000000000..65bc177327 --- /dev/null +++ b/legacy/eina/src/include/eina_inline_lock_win32.x @@ -0,0 +1,64 @@ +/* EINA - EFL data type library + * Copyright (C) 2011 Vincent Torri + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ + +#ifndef EINA_INLINE_LOCK_WIN32_X_ +#define EINA_INLINE_LOCK_WIN32_X_ + +#include + + +typedef CRITICAL_SECTION Eina_Lock; + +static inline Eina_Bool +eina_lock_new(Eina_Lock *mutex) +{ + InitializeCriticalSection(m); + + return EINA_TRUE; +} + +static inline void +eina_lock_free(Eina_Lock mutex) +{ + DeleteCriticalSection(&mutex); +} + +static inline Eina_Bool +eina_lock_take(Eina_Lock mutex) +{ + EnterCriticalSection(&mutex); + + return EINA_TRUE; +} + +static inline Eina_Bool +eina_lock_take_try(Eina_Lock mutex) +{ + return TryEnterCriticalSection(&mutex) == 0 ? EINA_FALSE : EINA_TRUE; +} + +static inline Eina_Bool +eina_lock_release(Eina_Lock mutex) +{ + LeaveCriticalSection(&mutex); + + return EINA_TRUE; +} + + +#endif diff --git a/legacy/eina/src/include/eina_inline_lock_wince.x b/legacy/eina/src/include/eina_inline_lock_wince.x new file mode 100644 index 0000000000..c9ab082584 --- /dev/null +++ b/legacy/eina/src/include/eina_inline_lock_wince.x @@ -0,0 +1,64 @@ +/* EINA - EFL data type library + * Copyright (C) 2011 Vincent Torri + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ + +#ifndef EINA_INLINE_LOCK_WIN32_X_ +#define EINA_INLINE_LOCK_WIN32_X_ + +#include + + +typedef HANDLE Eina_Lock; + +static inline Eina_Bool +eina_lock_new(Eina_Lock *mutex) +{ + Eina_Lock m; + + m = CreateMutex(NULL, FALSE, NULL); + if (m) *mutex = m; + return (m != NULL); +} + +static inline void +eina_lock_free(Eina_Lock mutex) +{ + CloseHandle(mutex); +} + +static inline Eina_Bool +eina_lock_take(Eina_Lock mutex) +{ + DWORD res; + + res = WaitForSingleObject(mutex, INFINITE); + if ((res == WAIT_ABANDONED) || (res == WAIT_FAILED)) + return EINA_FALSE; + + return EINA_TRUE; +} + +#define eina_lock_take_try(m) eina_lock_take(m) + +static inline Eina_Bool +eina_lock_release(Eina_Lock mutex) +{ + return ReleaseMutex(mutex); +} + + +#endif diff --git a/legacy/eina/src/include/eina_lock.h b/legacy/eina/src/include/eina_lock.h new file mode 100644 index 0000000000..45133fce9d --- /dev/null +++ b/legacy/eina/src/include/eina_lock.h @@ -0,0 +1,56 @@ +/* EINA - EFL data type library + * Copyright (C) 2011 Vincent Torri + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ + +#ifndef EINA_ARRAY_H_ +#define EINA_ARRAY_H_ + +#include "eina_config.h" + +/** + * @addtogroup Eina_Tools_Group Tools + * + * @{ + */ + +/** + * @defgroup Eina_File_Group File + * + * @{ + */ + +#ifdef EINA_HAVE_THREADS +# ifdef _WIN32_WCE +# include "eina_inline_lock_wince.x" +# elif _WIN32 +# include "eina_inline_lock_win32.x" +# else +# include "eina_inline_lock_posix.x" +# endif +#else +# include "eina_inline_lock_void.x" +#endif + +/** + * @} + */ + +/** + * @} + */ + +#endif