summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2009-12-03 15:35:04 +0000
committerCedric BAIL <cedric.bail@free.fr>2009-12-03 15:35:04 +0000
commitaf13fe5496052e9a0793fad812334b2c2c749041 (patch)
treeaf0056c075feb7cc85c1715a0a6127b85c78676b
parent7de1f120c2c4f744b12e5779449d41b85f3864fd (diff)
* eet: All operation on Eet_File should be thread safe. This should
make use of all eet primitive thread safe now. Please any bug or lock that you find. SVN revision: 44172
-rw-r--r--legacy/eet/configure.ac4
-rw-r--r--legacy/eet/m4/efl_pthread.m471
-rw-r--r--legacy/eet/src/lib/eet_lib.c157
3 files changed, 196 insertions, 36 deletions
diff --git a/legacy/eet/configure.ac b/legacy/eet/configure.ac
index 9099406c48..868cc8a0b5 100644
--- a/legacy/eet/configure.ac
+++ b/legacy/eet/configure.ac
@@ -175,11 +175,12 @@ AC_SUBST(pkgconfig_requires_private)
175 175
176EFL_CHECK_DOXYGEN([build_doc="yes"], [build_doc="no"]) 176EFL_CHECK_DOXYGEN([build_doc="yes"], [build_doc="no"])
177 177
178
179### Checks for libraries 178### Checks for libraries
180 179
181# Evil library for compilation on Windows 180# Evil library for compilation on Windows
182 181
182EFL_CHECK_PTHREAD([have_pthread="yes"], [have_pthread="no"])
183
183EFL_EET_BUILD="" 184EFL_EET_BUILD=""
184case "$host_os" in 185case "$host_os" in
185 mingw* | cegcc*) 186 mingw* | cegcc*)
@@ -417,6 +418,7 @@ echo " Gnutls...............: ${have_gnutls}"
417echo " Openssl..............: ${have_openssl}" 418echo " Openssl..............: ${have_openssl}"
418echo " Cipher support.....: ${have_cipher}" 419echo " Cipher support.....: ${have_cipher}"
419echo " Signature..........: ${have_signature}" 420echo " Signature..........: ${have_signature}"
421echo " Thread Support.......: ${have_pthread}"
420echo 422echo
421echo " Amalgamation.........: ${do_amalgamation}" 423echo " Amalgamation.........: ${do_amalgamation}"
422echo " Documentation........: ${build_doc}" 424echo " Documentation........: ${build_doc}"
diff --git a/legacy/eet/m4/efl_pthread.m4 b/legacy/eet/m4/efl_pthread.m4
new file mode 100644
index 0000000000..7bd341c709
--- /dev/null
+++ b/legacy/eet/m4/efl_pthread.m4
@@ -0,0 +1,71 @@
1dnl Copyright (C) 2008 Vincent Torri <vtorri at univ-evry dot fr>
2dnl That code is public domain and can be freely used or copied.
3
4dnl Macro that check if several ASM instruction sets are available or not.
5
6dnl Usage: EFL_CHECK_EFL_CHECK_PTHREAD([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
7dnl Call AC_SUBST(EFL_PTHREAD_FLAGS)
8dnl Define EFL_HAVE_PTHREAD
9
10AC_DEFUN([EFL_CHECK_PTHREAD],
11[
12
13dnl configure option
14
15AC_ARG_ENABLE([pthread],
16 [AC_HELP_STRING([--disable-pthread], [enable POSIX threads code @<:@default=yes@:>@])],
17 [
18 if test "x${enableval}" = "xyes" ; then
19 _efl_enable_pthread="yes"
20 else
21 _efl_enable_pthread="no"
22 fi
23 ],
24 [_efl_enable_pthread="yes"])
25
26AC_MSG_CHECKING([whether to build POSIX threads code])
27AC_MSG_RESULT([${_efl_enable_pthread}])
28
29dnl check if the compiler supports pthreads
30
31_efl_have_pthread="no"
32
33if test "x${_efl_enable_pthread}" = "xyes" ; then
34 AC_CHECK_HEADER(pthread.h,
35 [_efl_have_pthread="yes"],
36 [_efl_have_pthread="no"])
37fi
38
39AC_MSG_CHECKING([whether system support POSIX threads])
40AC_MSG_RESULT([${_efl_enable_pthread}])
41
42if test "x${_efl_have_pthread}" = "xyes" ; then
43 case "$host_os" in
44 mingw*)
45 EFL_PTHREAD_CFLAGS="-mthreads"
46 EFL_PTHREAD_LIBS="-mthreads -lpthreadGC2"
47 ;;
48 solaris*)
49 EFL_PTHREAD_CFLAGS="-mt"
50 EFL_PTHREAD_LIBS="-mt"
51 ;;
52 *)
53 EFL_PTHREAD_CFLAGS="-pthread"
54 EFL_PTHREAD_LIBS="-pthread"
55 ;;
56 esac
57fi
58
59AC_SUBST(EFL_PTHREAD_CFLAGS)
60AC_SUBST(EFL_PTHREAD_LIBS)
61
62if test "x${_efl_have_pthread}" = "xyes" ; then
63 AC_DEFINE(EFL_HAVE_PTHREAD, 1, [Define to mention that POSIX threads are supported])
64fi
65
66if test "x${_efl_have_pthread}" = "xyes" ; then
67 ifelse([$1], , :, [$1])
68else
69 ifelse([$2], , :, [$2])
70fi
71])
diff --git a/legacy/eet/src/lib/eet_lib.c b/legacy/eet/src/lib/eet_lib.c
index 82d1773357..b40ea93105 100644
--- a/legacy/eet/src/lib/eet_lib.c
+++ b/legacy/eet/src/lib/eet_lib.c
@@ -60,6 +60,23 @@ void *alloca (size_t);
60# include <openssl/evp.h> 60# include <openssl/evp.h>
61#endif 61#endif
62 62
63#ifdef EFL_HAVE_PTHREAD
64# ifdef _WIN32
65# define WIN32_LEAN_AND_MEAN
66# include <windows.h>
67# elif defined (__SUNPRO_C)
68# include <unistd.h>
69# elif defined (__FreeBSD__) || defined (__OpenBSD__) || defined (__NetBSD__) || defined (__DragonFly__) || defined (__MacOSX__) || ( defined (__MACH__) && defined (__APPLE__))
70# include <unistd.h>
71# include <sys/param.h>
72# include <sys/sysctl.h>
73# elif defined (__linux__)
74# define _GNU_SOURCE
75# include <sched.h>
76# endif
77# include <pthread.h>
78#endif
79
63#include <Eina.h> 80#include <Eina.h>
64 81
65#include "Eet.h" 82#include "Eet.h"
@@ -103,6 +120,10 @@ struct _Eet_File
103 120
104 time_t mtime; 121 time_t mtime;
105 122
123#ifdef EFL_HAVE_PTHREAD
124 pthread_mutex_t file_lock;
125#endif
126
106 unsigned char writes_pending : 1; 127 unsigned char writes_pending : 1;
107 unsigned char delete_me_now : 1; 128 unsigned char delete_me_now : 1;
108}; 129};
@@ -210,6 +231,29 @@ static Eet_Error eet_flush2(Eet_File *ef);
210static Eet_File_Node *find_node_by_name(Eet_File *ef, const char *name); 231static Eet_File_Node *find_node_by_name(Eet_File *ef, const char *name);
211static int read_data_from_disk(Eet_File *ef, Eet_File_Node *efn, void *buf, int len); 232static int read_data_from_disk(Eet_File *ef, Eet_File_Node *efn, void *buf, int len);
212 233
234#ifdef EFL_HAVE_PTHREAD
235static pthread_mutex_t eet_cache_lock = PTHREAD_MUTEX_INITIALIZER;
236
237#define LOCK_CACHE pthread_mutex_lock(&eet_cache_lock);
238#define UNLOCK_CACHE pthread_mutex_unlock(&eet_cache_lock);
239
240#define INIT_FILE(File) pthread_mutex_init(&File->file_lock, NULL);
241#define LOCK_FILE(File) pthread_mutex_lock(&File->file_lock);
242#define UNLOCK_FILE(File) pthread_mutex_unlock(&File->file_lock);
243#define DESTROY_FILE(File) pthread_mutex_destroy(&File->file_lock);
244
245#else
246
247#define LOCK_CACHE ;
248#define UNLOCK_CACHE ;
249
250#define INIT_FILE(File) ;
251#define LOCK_FILE(File) ;
252#define UNLOCK_FILE(File) ;
253#define DESTROY_FILE(File) ;
254
255#endif
256
213/* cache. i don't expect this to ever be large, so arrays will do */ 257/* cache. i don't expect this to ever be large, so arrays will do */
214static int eet_writers_num = 0; 258static int eet_writers_num = 0;
215static int eet_writers_alloc = 0; 259static int eet_writers_alloc = 0;
@@ -1279,6 +1323,7 @@ eet_memopen_read(const void *data, size_t size)
1279 if (!ef) 1323 if (!ef)
1280 return NULL; 1324 return NULL;
1281 1325
1326 INIT_FILE(ef);
1282 ef->ed = NULL; 1327 ef->ed = NULL;
1283 ef->path = NULL; 1328 ef->path = NULL;
1284 ef->key = NULL; 1329 ef->key = NULL;
@@ -1311,6 +1356,7 @@ eet_open(const char *file, Eet_File_Mode mode)
1311 1356
1312 /* find the current file handle in cache*/ 1357 /* find the current file handle in cache*/
1313 ef = NULL; 1358 ef = NULL;
1359 LOCK_CACHE;
1314 if (mode == EET_FILE_MODE_READ) 1360 if (mode == EET_FILE_MODE_READ)
1315 { 1361 {
1316 ef = eet_cache_find((char *)file, eet_writers, eet_writers_num); 1362 ef = eet_cache_find((char *)file, eet_writers, eet_writers_num);
@@ -1335,6 +1381,7 @@ eet_open(const char *file, Eet_File_Mode mode)
1335 } 1381 }
1336 ef = eet_cache_find((char *)file, eet_writers, eet_writers_num); 1382 ef = eet_cache_find((char *)file, eet_writers, eet_writers_num);
1337 } 1383 }
1384 UNLOCK_CACHE;
1338 1385
1339 /* try open the file based on mode */ 1386 /* try open the file based on mode */
1340 if ((mode == EET_FILE_MODE_READ) || (mode == EET_FILE_MODE_READ_WRITE)) 1387 if ((mode == EET_FILE_MODE_READ) || (mode == EET_FILE_MODE_READ_WRITE))
@@ -1399,6 +1446,7 @@ eet_open(const char *file, Eet_File_Mode mode)
1399 return NULL; 1446 return NULL;
1400 1447
1401 /* fill some of the members */ 1448 /* fill some of the members */
1449 INIT_FILE(ef);
1402 ef->fp = fp; 1450 ef->fp = fp;
1403 ef->key = NULL; 1451 ef->key = NULL;
1404 ef->readfp = NULL; 1452 ef->readfp = NULL;
@@ -1451,11 +1499,13 @@ eet_open(const char *file, Eet_File_Mode mode)
1451 /* add to cache */ 1499 /* add to cache */
1452 if (ef->references == 1) 1500 if (ef->references == 1)
1453 { 1501 {
1502 LOCK_CACHE;
1454 if (ef->mode == EET_FILE_MODE_READ) 1503 if (ef->mode == EET_FILE_MODE_READ)
1455 eet_cache_add(ef, &eet_readers, &eet_readers_num, &eet_readers_alloc); 1504 eet_cache_add(ef, &eet_readers, &eet_readers_num, &eet_readers_alloc);
1456 else 1505 else
1457 if ((ef->mode == EET_FILE_MODE_WRITE) || (ef->mode == EET_FILE_MODE_READ_WRITE)) 1506 if ((ef->mode == EET_FILE_MODE_WRITE) || (ef->mode == EET_FILE_MODE_READ_WRITE))
1458 eet_cache_add(ef, &eet_writers, &eet_writers_num, &eet_writers_alloc); 1507 eet_cache_add(ef, &eet_writers, &eet_writers_num, &eet_writers_alloc);
1508 UNLOCK_CACHE;
1459 } 1509 }
1460 1510
1461 return ef; 1511 return ef;
@@ -1539,10 +1589,14 @@ eet_close(Eet_File *ef)
1539 return EET_ERROR_NONE; 1589 return EET_ERROR_NONE;
1540 1590
1541 /* remove from cache */ 1591 /* remove from cache */
1592 LOCK_CACHE;
1542 if (ef->mode == EET_FILE_MODE_READ) 1593 if (ef->mode == EET_FILE_MODE_READ)
1543 eet_cache_del(ef, &eet_readers, &eet_readers_num, &eet_readers_alloc); 1594 eet_cache_del(ef, &eet_readers, &eet_readers_num, &eet_readers_alloc);
1544 else if ((ef->mode == EET_FILE_MODE_WRITE) || (ef->mode == EET_FILE_MODE_READ_WRITE)) 1595 else if ((ef->mode == EET_FILE_MODE_WRITE) || (ef->mode == EET_FILE_MODE_READ_WRITE))
1545 eet_cache_del(ef, &eet_writers, &eet_writers_num, &eet_writers_alloc); 1596 eet_cache_del(ef, &eet_writers, &eet_writers_num, &eet_writers_alloc);
1597 UNLOCK_CACHE;
1598
1599 DESTROY_FILE(ef);
1546 1600
1547 /* free up data */ 1601 /* free up data */
1548 if (ef->header) 1602 if (ef->header)
@@ -1616,18 +1670,18 @@ eet_read_cipher(Eet_File *ef, const char *name, int *size_ret, const char *ciphe
1616 if (eet_check_header(ef)) 1670 if (eet_check_header(ef))
1617 return NULL; 1671 return NULL;
1618 1672
1673 LOCK_FILE(ef);
1674
1619 /* hunt hash bucket */ 1675 /* hunt hash bucket */
1620 efn = find_node_by_name(ef, name); 1676 efn = find_node_by_name(ef, name);
1621 if (!efn) 1677 if (!efn) goto on_error;
1622 return NULL;
1623 1678
1624 /* get size (uncompressed, if compressed at all) */ 1679 /* get size (uncompressed, if compressed at all) */
1625 size = efn->data_size; 1680 size = efn->data_size;
1626 1681
1627 /* allocate data */ 1682 /* allocate data */
1628 data = malloc(size); 1683 data = malloc(size);
1629 if (!data) 1684 if (!data) goto on_error;
1630 return NULL;
1631 1685
1632 /* uncompressed data */ 1686 /* uncompressed data */
1633 if (efn->compression == 0) 1687 if (efn->compression == 0)
@@ -1639,17 +1693,13 @@ eet_read_cipher(Eet_File *ef, const char *name, int *size_ret, const char *ciphe
1639 memcpy(data, efn->data, efn->size); 1693 memcpy(data, efn->data, efn->size);
1640 else 1694 else
1641 if (!read_data_from_disk(ef, efn, data, size)) 1695 if (!read_data_from_disk(ef, efn, data, size))
1642 { 1696 goto on_error;
1643 free(data);
1644 return NULL;
1645 }
1646 if (efn->ciphered && cipher_key) 1697 if (efn->ciphered && cipher_key)
1647 { 1698 {
1648 if (eet_decipher(data, size, cipher_key, strlen(cipher_key), &data_deciphered, &data_deciphered_sz)) 1699 if (eet_decipher(data, size, cipher_key, strlen(cipher_key), &data_deciphered, &data_deciphered_sz))
1649 { 1700 {
1650 free(data);
1651 if (data_deciphered) free(data_deciphered); 1701 if (data_deciphered) free(data_deciphered);
1652 return NULL; 1702 goto on_error;
1653 } 1703 }
1654 free(data); 1704 free(data);
1655 data = data_deciphered; 1705 data = data_deciphered;
@@ -1673,18 +1723,14 @@ eet_read_cipher(Eet_File *ef, const char *name, int *size_ret, const char *ciphe
1673 { 1723 {
1674 tmp_data = malloc(compr_size); 1724 tmp_data = malloc(compr_size);
1675 if (!tmp_data) 1725 if (!tmp_data)
1676 { 1726 goto on_error;
1677 free(data);
1678 return NULL;
1679 }
1680 1727
1681 free_tmp = 1; 1728 free_tmp = 1;
1682 1729
1683 if (!read_data_from_disk(ef, efn, tmp_data, compr_size)) 1730 if (!read_data_from_disk(ef, efn, tmp_data, compr_size))
1684 { 1731 {
1685 free(tmp_data); 1732 free(tmp_data);
1686 free(data); 1733 goto on_error;
1687 return NULL;
1688 } 1734 }
1689 } 1735 }
1690 1736
@@ -1692,10 +1738,9 @@ eet_read_cipher(Eet_File *ef, const char *name, int *size_ret, const char *ciphe
1692 { 1738 {
1693 if (eet_decipher(tmp_data, compr_size, cipher_key, strlen(cipher_key), &data_deciphered, &data_deciphered_sz)) 1739 if (eet_decipher(tmp_data, compr_size, cipher_key, strlen(cipher_key), &data_deciphered, &data_deciphered_sz))
1694 { 1740 {
1695 free(data);
1696 if (free_tmp) free(tmp_data); 1741 if (free_tmp) free(tmp_data);
1697 if (data_deciphered) free(data_deciphered); 1742 if (data_deciphered) free(data_deciphered);
1698 return NULL; 1743 goto on_error;
1699 } 1744 }
1700 free(tmp_data); 1745 free(tmp_data);
1701 tmp_data = data_deciphered; 1746 tmp_data = data_deciphered;
@@ -1706,10 +1751,7 @@ eet_read_cipher(Eet_File *ef, const char *name, int *size_ret, const char *ciphe
1706 dlen = size; 1751 dlen = size;
1707 if (uncompress((Bytef *)data, &dlen, 1752 if (uncompress((Bytef *)data, &dlen,
1708 tmp_data, (uLongf)compr_size)) 1753 tmp_data, (uLongf)compr_size))
1709 { 1754 goto on_error;
1710 free(data);
1711 return NULL;
1712 }
1713 1755
1714 if (free_tmp) 1756 if (free_tmp)
1715 free(tmp_data); 1757 free(tmp_data);
@@ -1719,7 +1761,14 @@ eet_read_cipher(Eet_File *ef, const char *name, int *size_ret, const char *ciphe
1719 if (size_ret) 1761 if (size_ret)
1720 *size_ret = size; 1762 *size_ret = size;
1721 1763
1764 UNLOCK_FILE(ef);
1765
1722 return data; 1766 return data;
1767
1768 on_error:
1769 UNLOCK_FILE(ef);
1770 free(data);
1771 return NULL;
1723} 1772}
1724 1773
1725EAPI void * 1774EAPI void *
@@ -1751,13 +1800,14 @@ eet_read_direct(Eet_File *ef, const char *name, int *size_ret)
1751 if (eet_check_header(ef)) 1800 if (eet_check_header(ef))
1752 return NULL; 1801 return NULL;
1753 1802
1803 LOCK_FILE(ef);
1804
1754 /* hunt hash bucket */ 1805 /* hunt hash bucket */
1755 efn = find_node_by_name(ef, name); 1806 efn = find_node_by_name(ef, name);
1756 if (!efn) 1807 if (!efn) goto on_error;
1757 return NULL;
1758 1808
1759 if (efn->offset < 0 && efn->data == NULL) 1809 if (efn->offset < 0 && efn->data == NULL)
1760 return NULL; 1810 goto on_error;
1761 1811
1762 /* get size (uncompressed, if compressed at all) */ 1812 /* get size (uncompressed, if compressed at all) */
1763 size = efn->data_size; 1813 size = efn->data_size;
@@ -1774,7 +1824,13 @@ eet_read_direct(Eet_File *ef, const char *name, int *size_ret)
1774 if (size_ret) 1824 if (size_ret)
1775 *size_ret = size; 1825 *size_ret = size;
1776 1826
1827 UNLOCK_FILE(ef);
1828
1777 return data; 1829 return data;
1830
1831 on_error:
1832 UNLOCK_FILE(ef);
1833 return NULL;
1778} 1834}
1779 1835
1780EAPI int 1836EAPI int
@@ -1795,25 +1851,35 @@ eet_write_cipher(Eet_File *ef, const char *name, const void *data, int size, int
1795 (ef->mode != EET_FILE_MODE_READ_WRITE)) 1851 (ef->mode != EET_FILE_MODE_READ_WRITE))
1796 return 0; 1852 return 0;
1797 1853
1854 LOCK_FILE(ef);
1855
1798 if (!ef->header) 1856 if (!ef->header)
1799 { 1857 {
1800 /* allocate header */ 1858 /* allocate header */
1801 ef->header = calloc(1, sizeof(Eet_File_Header)); 1859 ef->header = calloc(1, sizeof(Eet_File_Header));
1802 if (!ef->header) 1860 if (!ef->header)
1803 return 0; 1861 goto on_error;
1804 1862
1805 ef->header->magic = EET_MAGIC_FILE_HEADER; 1863 ef->header->magic = EET_MAGIC_FILE_HEADER;
1806 /* allocate directory block in ram */ 1864 /* allocate directory block in ram */
1807 ef->header->directory = calloc(1, sizeof(Eet_File_Directory)); 1865 ef->header->directory = calloc(1, sizeof(Eet_File_Directory));
1808 if (!ef->header->directory) 1866 if (!ef->header->directory)
1809 return 0; 1867 {
1868 free(ef->header);
1869 ef->header = NULL;
1870 goto on_error;
1871 }
1810 1872
1811 /* 8 bit hash table (256 buckets) */ 1873 /* 8 bit hash table (256 buckets) */
1812 ef->header->directory->size = 8; 1874 ef->header->directory->size = 8;
1813 /* allocate base hash table */ 1875 /* allocate base hash table */
1814 ef->header->directory->nodes = calloc(1, sizeof(Eet_File_Node *) * (1 << ef->header->directory->size)); 1876 ef->header->directory->nodes = calloc(1, sizeof(Eet_File_Node *) * (1 << ef->header->directory->size));
1815 if (!ef->header->directory->nodes) 1877 if (!ef->header->directory->nodes)
1816 return 0; 1878 {
1879 free(ef->header->directory);
1880 ef->header = NULL;
1881 goto on_error;
1882 }
1817 } 1883 }
1818 1884
1819 /* figure hash bucket */ 1885 /* figure hash bucket */
@@ -1824,8 +1890,7 @@ eet_write_cipher(Eet_File *ef, const char *name, const void *data, int size, int
1824 if (compress || !cipher_key) 1890 if (compress || !cipher_key)
1825 { 1891 {
1826 data2 = malloc(data_size); 1892 data2 = malloc(data_size);
1827 if (!data2) 1893 if (!data2) goto on_error;
1828 return 0;
1829 } 1894 }
1830 1895
1831 /* if we want to compress */ 1896 /* if we want to compress */
@@ -1905,7 +1970,7 @@ eet_write_cipher(Eet_File *ef, const char *name, const void *data, int size, int
1905 if (!efn) 1970 if (!efn)
1906 { 1971 {
1907 free(data2); 1972 free(data2);
1908 return 0; 1973 goto on_error;
1909 } 1974 }
1910 efn->name = strdup(name); 1975 efn->name = strdup(name);
1911 efn->name_size = strlen(efn->name) + 1; 1976 efn->name_size = strlen(efn->name) + 1;
@@ -1923,7 +1988,12 @@ eet_write_cipher(Eet_File *ef, const char *name, const void *data, int size, int
1923 1988
1924 /* flags that writes are pending */ 1989 /* flags that writes are pending */
1925 ef->writes_pending = 1; 1990 ef->writes_pending = 1;
1991 UNLOCK_FILE(ef);
1926 return data_size; 1992 return data_size;
1993
1994 on_error:
1995 UNLOCK_FILE(ef);
1996 return 0;
1927} 1997}
1928 1998
1929EAPI int 1999EAPI int
@@ -1953,6 +2023,8 @@ eet_delete(Eet_File *ef, const char *name)
1953 if (eet_check_header(ef)) 2023 if (eet_check_header(ef))
1954 return 0; 2024 return 0;
1955 2025
2026 LOCK_FILE(ef);
2027
1956 /* figure hash bucket */ 2028 /* figure hash bucket */
1957 hash = _eet_hash_gen(name, ef->header->directory->size); 2029 hash = _eet_hash_gen(name, ef->header->directory->size);
1958 2030
@@ -1982,6 +2054,8 @@ eet_delete(Eet_File *ef, const char *name)
1982 if (exists_already) 2054 if (exists_already)
1983 ef->writes_pending = 1; 2055 ef->writes_pending = 1;
1984 2056
2057 UNLOCK_FILE(ef);
2058
1985 /* update access time */ 2059 /* update access time */
1986 return exists_already; 2060 return exists_already;
1987} 2061}
@@ -2016,6 +2090,8 @@ eet_list(Eet_File *ef, const char *glob, int *count_ret)
2016 return NULL; 2090 return NULL;
2017 } 2091 }
2018 2092
2093 LOCK_FILE(ef);
2094
2019 /* loop through all entries */ 2095 /* loop through all entries */
2020 num = (1 << ef->header->directory->size); 2096 num = (1 << ef->header->directory->size);
2021 for (i = 0; i < num; i++) 2097 for (i = 0; i < num; i++)
@@ -2042,10 +2118,7 @@ eet_list(Eet_File *ef, const char *glob, int *count_ret)
2042 { 2118 {
2043 free(list_ret); 2119 free(list_ret);
2044 2120
2045 if (count_ret) 2121 goto on_error;
2046 *count_ret = 0;
2047
2048 return NULL;
2049 } 2122 }
2050 list_ret = new_list; 2123 list_ret = new_list;
2051 } 2124 }
@@ -2056,11 +2129,21 @@ eet_list(Eet_File *ef, const char *glob, int *count_ret)
2056 } 2129 }
2057 } 2130 }
2058 2131
2132 UNLOCK_FILE(ef);
2133
2059 /* return count and list */ 2134 /* return count and list */
2060 if (count_ret) 2135 if (count_ret)
2061 *count_ret = list_count; 2136 *count_ret = list_count;
2062 2137
2063 return list_ret; 2138 return list_ret;
2139
2140 on_error:
2141 UNLOCK_FILE(ef);
2142
2143 if (count_ret)
2144 *count_ret = 0;
2145
2146 return NULL;
2064} 2147}
2065 2148
2066EAPI int 2149EAPI int
@@ -2075,6 +2158,8 @@ eet_num_entries(Eet_File *ef)
2075 (ef->mode != EET_FILE_MODE_READ_WRITE))) 2158 (ef->mode != EET_FILE_MODE_READ_WRITE)))
2076 return -1; 2159 return -1;
2077 2160
2161 LOCK_FILE(ef);
2162
2078 /* loop through all entries */ 2163 /* loop through all entries */
2079 num = (1 << ef->header->directory->size); 2164 num = (1 << ef->header->directory->size);
2080 for (i = 0; i < num; i++) 2165 for (i = 0; i < num; i++)
@@ -2083,6 +2168,8 @@ eet_num_entries(Eet_File *ef)
2083 ret++; 2168 ret++;
2084 } 2169 }
2085 2170
2171 UNLOCK_FILE(ef);
2172
2086 return ret; 2173 return ret;
2087} 2174}
2088 2175