summaryrefslogtreecommitdiff
path: root/src/lib/eina
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2013-11-20 10:11:21 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2013-11-20 10:22:00 +0100
commit8a3e021298c8d7ebf8cb587554422aa6a93edcc9 (patch)
tree45cc7cf656e4b7f947bff2e5f4aeb313d0553e54 /src/lib/eina
parent4eb4307aa2b847e73924aa67a055294d2533090b (diff)
Revert "eina: fix a possible race condition during eina_file_close."
it breaks everything This reverts commit 7e8fb93206ee95945bb757267832537c13ab4287.
Diffstat (limited to 'src/lib/eina')
-rw-r--r--src/lib/eina/eina_file.c9
-rw-r--r--src/lib/eina/eina_file_common.c15
-rw-r--r--src/lib/eina/eina_file_common.h3
-rw-r--r--src/lib/eina/eina_file_win32.c7
4 files changed, 15 insertions, 19 deletions
diff --git a/src/lib/eina/eina_file.c b/src/lib/eina/eina_file.c
index 8ae5a0f4ed..6d7ee56f54 100644
--- a/src/lib/eina/eina_file.c
+++ b/src/lib/eina/eina_file.c
@@ -305,6 +305,11 @@ eina_file_real_close(Eina_File *file)
305{ 305{
306 Eina_File_Map *map; 306 Eina_File_Map *map;
307 307
308 if (file->refcount != 0) return;
309
310 eina_hash_free(file->rmap);
311 eina_hash_free(file->map);
312
308 EINA_LIST_FREE(file->dead_map, map) 313 EINA_LIST_FREE(file->dead_map, map)
309 { 314 {
310 munmap(map->map, map->length); 315 munmap(map->map, map->length);
@@ -315,6 +320,8 @@ eina_file_real_close(Eina_File *file)
315 munmap(file->global_map, file->length); 320 munmap(file->global_map, file->length);
316 321
317 if (file->fd != -1) close(file->fd); 322 if (file->fd != -1) close(file->fd);
323
324 free(file);
318} 325}
319 326
320static void 327static void
@@ -905,8 +912,6 @@ eina_file_open(const char *path, Eina_Bool shared)
905 n->shared = shared; 912 n->shared = shared;
906 eina_lock_new(&n->lock); 913 eina_lock_new(&n->lock);
907 eina_hash_direct_add(_eina_file_cache, n->filename, n); 914 eina_hash_direct_add(_eina_file_cache, n->filename, n);
908
909 EINA_MAGIC_SET(n, EINA_FILE_MAGIC);
910 } 915 }
911 else 916 else
912 { 917 {
diff --git a/src/lib/eina/eina_file_common.c b/src/lib/eina/eina_file_common.c
index f5724d70bf..7b05b3b249 100644
--- a/src/lib/eina/eina_file_common.c
+++ b/src/lib/eina/eina_file_common.c
@@ -451,26 +451,17 @@ eina_file_close(Eina_File *file)
451 451
452 EINA_SAFETY_ON_NULL_RETURN(file); 452 EINA_SAFETY_ON_NULL_RETURN(file);
453 453
454 eina_lock_take(&_eina_file_lock_cache);
455
456 eina_lock_take(&file->lock); 454 eina_lock_take(&file->lock);
457 file->refcount--; 455 file->refcount--;
458 if (file->refcount == 0) leave = EINA_FALSE; 456 if (file->refcount == 0) leave = EINA_FALSE;
459 eina_lock_release(&file->lock); 457 eina_lock_release(&file->lock);
460 if (leave) goto end; 458 if (leave) return;
461 459
462 eina_hash_del(_eina_file_cache, file->filename, file); 460 eina_lock_take(&_eina_file_lock_cache);
463 461
464 // Backend specific file resource close 462 eina_hash_del(_eina_file_cache, file->filename, file);
465 eina_file_real_close(file); 463 eina_file_real_close(file);
466 464
467 // Generic destruction of the file
468 eina_hash_free(file->rmap); file->rmap = NULL;
469 eina_hash_free(file->map); file->map = NULL;
470 EINA_MAGIC_SET(file, 0);
471 free(file);
472
473 end:
474 eina_lock_release(&_eina_file_lock_cache); 465 eina_lock_release(&_eina_file_lock_cache);
475} 466}
476 467
diff --git a/src/lib/eina/eina_file_common.h b/src/lib/eina/eina_file_common.h
index e3ee0fc553..0ac704d028 100644
--- a/src/lib/eina/eina_file_common.h
+++ b/src/lib/eina/eina_file_common.h
@@ -24,14 +24,11 @@
24#include "eina_lock.h" 24#include "eina_lock.h"
25#include "eina_list.h" 25#include "eina_list.h"
26 26
27#define EINA_FILE_MAGIC 0xFEEDBEEF
28
29typedef struct _Eina_File_Map Eina_File_Map; 27typedef struct _Eina_File_Map Eina_File_Map;
30typedef struct _Eina_Lines_Iterator Eina_Lines_Iterator; 28typedef struct _Eina_Lines_Iterator Eina_Lines_Iterator;
31 29
32struct _Eina_File 30struct _Eina_File
33{ 31{
34 EINA_MAGIC;
35 const char *filename; 32 const char *filename;
36 33
37 Eina_Hash *map; 34 Eina_Hash *map;
diff --git a/src/lib/eina/eina_file_win32.c b/src/lib/eina/eina_file_win32.c
index 8290501869..cddf2da81a 100644
--- a/src/lib/eina/eina_file_win32.c
+++ b/src/lib/eina/eina_file_win32.c
@@ -366,6 +366,9 @@ eina_file_real_close(Eina_File *file)
366{ 366{
367 Eina_File_Map *map; 367 Eina_File_Map *map;
368 368
369 eina_hash_free(file->rmap);
370 eina_hash_free(file->map);
371
369 EINA_LIST_FREE(file->dead_map, map) 372 EINA_LIST_FREE(file->dead_map, map)
370 { 373 {
371 UnmapViewOfFile(map->map); 374 UnmapViewOfFile(map->map);
@@ -377,6 +380,8 @@ eina_file_real_close(Eina_File *file)
377 380
378 if (file->fm) CloseHandle(file->fm); 381 if (file->fm) CloseHandle(file->fm);
379 if (file->handle) CloseHandle(file->handle); 382 if (file->handle) CloseHandle(file->handle);
383
384 free(file);
380} 385}
381 386
382static void 387static void
@@ -832,8 +837,6 @@ eina_file_open(const char *path, Eina_Bool shared)
832 n->shared = shared; 837 n->shared = shared;
833 eina_lock_new(&n->lock); 838 eina_lock_new(&n->lock);
834 eina_hash_direct_add(_eina_file_cache, n->filename, n); 839 eina_hash_direct_add(_eina_file_cache, n->filename, n);
835
836 EINA_MAGIC_SET(n, EINA_FILE_MAGIC);
837 } 840 }
838 else 841 else
839 { 842 {