forked from enlightenment/efl
eina: cleanup file destruction and reintroduce EINA_MAGIC use.
This commit is contained in:
parent
4096a18523
commit
0cfb40b7fb
|
@ -305,11 +305,6 @@ eina_file_real_close(Eina_File *file)
|
|||
{
|
||||
Eina_File_Map *map;
|
||||
|
||||
if (file->refcount != 0) return;
|
||||
|
||||
eina_hash_free(file->rmap);
|
||||
eina_hash_free(file->map);
|
||||
|
||||
EINA_LIST_FREE(file->dead_map, map)
|
||||
{
|
||||
munmap(map->map, map->length);
|
||||
|
@ -320,8 +315,6 @@ eina_file_real_close(Eina_File *file)
|
|||
munmap(file->global_map, file->length);
|
||||
|
||||
if (file->fd != -1) close(file->fd);
|
||||
|
||||
free(file);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -875,7 +868,7 @@ eina_file_open(const char *path, Eina_Bool shared)
|
|||
{
|
||||
file->delete_me = EINA_TRUE;
|
||||
eina_hash_del(_eina_file_cache, file->filename, file);
|
||||
eina_file_real_close(file);
|
||||
eina_file_clean_close(file);
|
||||
file = NULL;
|
||||
}
|
||||
|
||||
|
@ -912,6 +905,8 @@ eina_file_open(const char *path, Eina_Bool shared)
|
|||
n->shared = shared;
|
||||
eina_lock_new(&n->lock);
|
||||
eina_hash_direct_add(_eina_file_cache, n->filename, n);
|
||||
|
||||
EINA_MAGIC_SET(n, EINA_FILE_MAGIC);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -444,6 +444,21 @@ eina_file_dup(const Eina_File *f)
|
|||
return file;
|
||||
}
|
||||
|
||||
void
|
||||
eina_file_clean_close(Eina_File *file)
|
||||
{
|
||||
// Generic destruction of the file
|
||||
eina_hash_free(file->rmap); file->rmap = NULL;
|
||||
eina_hash_free(file->map); file->map = NULL;
|
||||
|
||||
// Backend specific file resource close
|
||||
eina_file_real_close(file);
|
||||
|
||||
// Final death
|
||||
EINA_MAGIC_SET(file, 0);
|
||||
free(file);
|
||||
}
|
||||
|
||||
EAPI void
|
||||
eina_file_close(Eina_File *file)
|
||||
{
|
||||
|
@ -461,9 +476,7 @@ eina_file_close(Eina_File *file)
|
|||
|
||||
eina_hash_del(_eina_file_cache, file->filename, file);
|
||||
|
||||
// Backend specific file resource close
|
||||
eina_file_real_close(file);
|
||||
|
||||
eina_file_clean_close(file);
|
||||
end:
|
||||
eina_lock_release(&_eina_file_lock_cache);
|
||||
}
|
||||
|
|
|
@ -24,11 +24,14 @@
|
|||
#include "eina_lock.h"
|
||||
#include "eina_list.h"
|
||||
|
||||
#define EINA_FILE_MAGIC 0xFEEDBEEF
|
||||
|
||||
typedef struct _Eina_File_Map Eina_File_Map;
|
||||
typedef struct _Eina_Lines_Iterator Eina_Lines_Iterator;
|
||||
|
||||
struct _Eina_File
|
||||
{
|
||||
EINA_MAGIC;
|
||||
const char *filename;
|
||||
|
||||
Eina_Hash *map;
|
||||
|
@ -121,6 +124,7 @@ struct _Eina_Lines_Iterator
|
|||
Eina_Bool eina_file_path_relative(const char *path);
|
||||
Eina_Tmpstr *eina_file_current_directory_get(const char *path, size_t len);
|
||||
char *eina_file_cleanup(Eina_Tmpstr *path);
|
||||
void eina_file_clean_close(Eina_File *file);
|
||||
void eina_file_real_close(Eina_File *file);
|
||||
void eina_file_flush(Eina_File *file, unsigned long int length);
|
||||
void eina_file_common_map_free(Eina_File *file, void *map,
|
||||
|
|
|
@ -366,9 +366,6 @@ eina_file_real_close(Eina_File *file)
|
|||
{
|
||||
Eina_File_Map *map;
|
||||
|
||||
eina_hash_free(file->rmap);
|
||||
eina_hash_free(file->map);
|
||||
|
||||
EINA_LIST_FREE(file->dead_map, map)
|
||||
{
|
||||
UnmapViewOfFile(map->map);
|
||||
|
@ -380,8 +377,6 @@ eina_file_real_close(Eina_File *file)
|
|||
|
||||
if (file->fm) CloseHandle(file->fm);
|
||||
if (file->handle) CloseHandle(file->handle);
|
||||
|
||||
free(file);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -807,7 +802,7 @@ eina_file_open(const char *path, Eina_Bool shared)
|
|||
{
|
||||
file->delete_me = EINA_TRUE;
|
||||
eina_hash_del(_eina_file_cache, file->filename, file);
|
||||
eina_file_real_close(file);
|
||||
eina_file_clean_close(file);
|
||||
file = NULL;
|
||||
}
|
||||
|
||||
|
@ -837,6 +832,8 @@ eina_file_open(const char *path, Eina_Bool shared)
|
|||
n->shared = shared;
|
||||
eina_lock_new(&n->lock);
|
||||
eina_hash_direct_add(_eina_file_cache, n->filename, n);
|
||||
|
||||
EINA_MAGIC_SET(n, EINA_FILE_MAGIC);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue