summaryrefslogtreecommitdiff
path: root/src/lib/eina
diff options
context:
space:
mode:
authorCedric Bail <cedric.bail@samsung.com>2013-11-20 20:06:50 +0900
committerCedric Bail <cedric.bail@samsung.com>2013-11-20 20:08:44 +0900
commit0cfb40b7fb03a96973fe27542b4a5a739eca4386 (patch)
tree5eccbd29cb2b096c80d4f15aff5cb3b339df49ff /src/lib/eina
parent4096a185232ce685db92b391d8a8cc241a090b2c (diff)
eina: cleanup file destruction and reintroduce EINA_MAGIC use.
Diffstat (limited to 'src/lib/eina')
-rw-r--r--src/lib/eina/eina_file.c11
-rw-r--r--src/lib/eina/eina_file_common.c19
-rw-r--r--src/lib/eina/eina_file_common.h4
-rw-r--r--src/lib/eina/eina_file_win32.c9
4 files changed, 26 insertions, 17 deletions
diff --git a/src/lib/eina/eina_file.c b/src/lib/eina/eina_file.c
index 6d7ee56f54..1ae3681f80 100644
--- a/src/lib/eina/eina_file.c
+++ b/src/lib/eina/eina_file.c
@@ -305,11 +305,6 @@ 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
313 EINA_LIST_FREE(file->dead_map, map) 308 EINA_LIST_FREE(file->dead_map, map)
314 { 309 {
315 munmap(map->map, map->length); 310 munmap(map->map, map->length);
@@ -320,8 +315,6 @@ eina_file_real_close(Eina_File *file)
320 munmap(file->global_map, file->length); 315 munmap(file->global_map, file->length);
321 316
322 if (file->fd != -1) close(file->fd); 317 if (file->fd != -1) close(file->fd);
323
324 free(file);
325} 318}
326 319
327static void 320static void
@@ -875,7 +868,7 @@ eina_file_open(const char *path, Eina_Bool shared)
875 { 868 {
876 file->delete_me = EINA_TRUE; 869 file->delete_me = EINA_TRUE;
877 eina_hash_del(_eina_file_cache, file->filename, file); 870 eina_hash_del(_eina_file_cache, file->filename, file);
878 eina_file_real_close(file); 871 eina_file_clean_close(file);
879 file = NULL; 872 file = NULL;
880 } 873 }
881 874
@@ -912,6 +905,8 @@ eina_file_open(const char *path, Eina_Bool shared)
912 n->shared = shared; 905 n->shared = shared;
913 eina_lock_new(&n->lock); 906 eina_lock_new(&n->lock);
914 eina_hash_direct_add(_eina_file_cache, n->filename, n); 907 eina_hash_direct_add(_eina_file_cache, n->filename, n);
908
909 EINA_MAGIC_SET(n, EINA_FILE_MAGIC);
915 } 910 }
916 else 911 else
917 { 912 {
diff --git a/src/lib/eina/eina_file_common.c b/src/lib/eina/eina_file_common.c
index 7f83c87774..7952190328 100644
--- a/src/lib/eina/eina_file_common.c
+++ b/src/lib/eina/eina_file_common.c
@@ -444,6 +444,21 @@ eina_file_dup(const Eina_File *f)
444 return file; 444 return file;
445} 445}
446 446
447void
448eina_file_clean_close(Eina_File *file)
449{
450 // Generic destruction of the file
451 eina_hash_free(file->rmap); file->rmap = NULL;
452 eina_hash_free(file->map); file->map = NULL;
453
454 // Backend specific file resource close
455 eina_file_real_close(file);
456
457 // Final death
458 EINA_MAGIC_SET(file, 0);
459 free(file);
460}
461
447EAPI void 462EAPI void
448eina_file_close(Eina_File *file) 463eina_file_close(Eina_File *file)
449{ 464{
@@ -461,9 +476,7 @@ eina_file_close(Eina_File *file)
461 476
462 eina_hash_del(_eina_file_cache, file->filename, file); 477 eina_hash_del(_eina_file_cache, file->filename, file);
463 478
464 // Backend specific file resource close 479 eina_file_clean_close(file);
465 eina_file_real_close(file);
466
467 end: 480 end:
468 eina_lock_release(&_eina_file_lock_cache); 481 eina_lock_release(&_eina_file_lock_cache);
469} 482}
diff --git a/src/lib/eina/eina_file_common.h b/src/lib/eina/eina_file_common.h
index 0ac704d028..62ad2b21ac 100644
--- a/src/lib/eina/eina_file_common.h
+++ b/src/lib/eina/eina_file_common.h
@@ -24,11 +24,14 @@
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
27typedef struct _Eina_File_Map Eina_File_Map; 29typedef struct _Eina_File_Map Eina_File_Map;
28typedef struct _Eina_Lines_Iterator Eina_Lines_Iterator; 30typedef struct _Eina_Lines_Iterator Eina_Lines_Iterator;
29 31
30struct _Eina_File 32struct _Eina_File
31{ 33{
34 EINA_MAGIC;
32 const char *filename; 35 const char *filename;
33 36
34 Eina_Hash *map; 37 Eina_Hash *map;
@@ -121,6 +124,7 @@ struct _Eina_Lines_Iterator
121Eina_Bool eina_file_path_relative(const char *path); 124Eina_Bool eina_file_path_relative(const char *path);
122Eina_Tmpstr *eina_file_current_directory_get(const char *path, size_t len); 125Eina_Tmpstr *eina_file_current_directory_get(const char *path, size_t len);
123char *eina_file_cleanup(Eina_Tmpstr *path); 126char *eina_file_cleanup(Eina_Tmpstr *path);
127void eina_file_clean_close(Eina_File *file);
124void eina_file_real_close(Eina_File *file); 128void eina_file_real_close(Eina_File *file);
125void eina_file_flush(Eina_File *file, unsigned long int length); 129void eina_file_flush(Eina_File *file, unsigned long int length);
126void eina_file_common_map_free(Eina_File *file, void *map, 130void eina_file_common_map_free(Eina_File *file, void *map,
diff --git a/src/lib/eina/eina_file_win32.c b/src/lib/eina/eina_file_win32.c
index cddf2da81a..7cb108d2a5 100644
--- a/src/lib/eina/eina_file_win32.c
+++ b/src/lib/eina/eina_file_win32.c
@@ -366,9 +366,6 @@ 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
372 EINA_LIST_FREE(file->dead_map, map) 369 EINA_LIST_FREE(file->dead_map, map)
373 { 370 {
374 UnmapViewOfFile(map->map); 371 UnmapViewOfFile(map->map);
@@ -380,8 +377,6 @@ eina_file_real_close(Eina_File *file)
380 377
381 if (file->fm) CloseHandle(file->fm); 378 if (file->fm) CloseHandle(file->fm);
382 if (file->handle) CloseHandle(file->handle); 379 if (file->handle) CloseHandle(file->handle);
383
384 free(file);
385} 380}
386 381
387static void 382static void
@@ -807,7 +802,7 @@ eina_file_open(const char *path, Eina_Bool shared)
807 { 802 {
808 file->delete_me = EINA_TRUE; 803 file->delete_me = EINA_TRUE;
809 eina_hash_del(_eina_file_cache, file->filename, file); 804 eina_hash_del(_eina_file_cache, file->filename, file);
810 eina_file_real_close(file); 805 eina_file_clean_close(file);
811 file = NULL; 806 file = NULL;
812 } 807 }
813 808
@@ -837,6 +832,8 @@ eina_file_open(const char *path, Eina_Bool shared)
837 n->shared = shared; 832 n->shared = shared;
838 eina_lock_new(&n->lock); 833 eina_lock_new(&n->lock);
839 eina_hash_direct_add(_eina_file_cache, n->filename, n); 834 eina_hash_direct_add(_eina_file_cache, n->filename, n);
835
836 EINA_MAGIC_SET(n, EINA_FILE_MAGIC);
840 } 837 }
841 else 838 else
842 { 839 {