From bb76ca810093f5ca0b8a0f44d8baebc98f83284e Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Tue, 5 Oct 2010 11:44:03 +0000 Subject: [PATCH] * eio: share some code. SVN revision: 53056 --- legacy/eio/src/lib/eio_file.c | 34 +++++++--------- legacy/eio/src/lib/eio_main.c | 66 ++++++++++++++++++++++++++++++++ legacy/eio/src/lib/eio_private.h | 16 ++++++++ 3 files changed, 95 insertions(+), 21 deletions(-) diff --git a/legacy/eio/src/lib/eio_file.c b/legacy/eio/src/lib/eio_file.c index 5f99890ac1..25f831c0f0 100644 --- a/legacy/eio/src/lib/eio_file.c +++ b/legacy/eio/src/lib/eio_file.c @@ -46,16 +46,10 @@ #include #include -#include - #include "eio_private.h" #include "Eio.h" -static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; -static Eina_Trash *trash = NULL; -static int trash_count = 0; - static void _eio_file_heavy(Ecore_Thread *thread, void *data) { @@ -127,10 +121,13 @@ _eio_file_direct_heavy(Ecore_Thread *thread, void *data) { Eina_File_Direct_Info *send; - send = malloc(sizeof (Eina_File_Direct_Info)); + send = malloc(sizeof (Eina_File_Direct_Info) + sizeof (struct dirent)); if (!send) continue; memcpy(send, info, sizeof (Eina_File_Direct_Info)); + send->dirent = (struct dirent*)(send + 1); + memcpy((void*) send->dirent, info->dirent, sizeof (struct dirent)); + ecore_thread_feedback(thread, send); } @@ -194,12 +191,7 @@ _eio_file_send(Ecore_Thread *thread, Eio_File_Progress *op, off_t current, off_t if (op->progress_cb == NULL) return ; - pthread_mutex_lock(&lock); - progress = eina_trash_pop(&trash); - if (progress) trash_count--; - pthread_mutex_unlock(&lock); - - if (!progress) progress = malloc(sizeof (Eio_Progress)); + progress = eio_progress_malloc(); if (!progress) return ; progress->current = current; @@ -215,13 +207,8 @@ static void _eio_file_progress(Eio_Progress *progress, Eio_File_Progress *op) { op->progress_cb((void *) op->common.data, progress); - eina_stringshare_del(progress->source); - eina_stringshare_del(progress->dest); - pthread_mutex_lock(&lock); - eina_trash_push(&trash, progress); - trash_count++; - pthread_mutex_unlock(&lock); + eio_progress_free(progress); } #ifndef MAP_HUGETLB @@ -505,8 +492,13 @@ _eio_file_move_error(void *data) _eio_file_move_copy_error, move); - if (eio_cp) move->copy = eio_cp; - return ; + if (eio_cp) + { + move->copy = eio_cp; + + move->progress.common.thread = ((Eio_File_Progress*)move->copy)->common.thread; + return ; + } } eio_file_error(&move->progress.common); diff --git a/legacy/eio/src/lib/eio_main.c b/legacy/eio/src/lib/eio_main.c index bee296447f..4b5ed6b160 100644 --- a/legacy/eio/src/lib/eio_main.c +++ b/legacy/eio/src/lib/eio_main.c @@ -1,13 +1,39 @@ +/* EIO - EFL data type library + * Copyright (C) 2010 Enlightenment Developers: + * Cedric Bail + * + * 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 . + */ + #ifdef HAVE_CONFIG_H # include "config.h" #endif +#include + #include "eio_private.h" #include "Eio.h" static int _eio_count = 0; +/* Progress pool */ +static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; +static Eina_Trash *trash = NULL; +static int trash_count = 0; + EAPI int eio_init(void) { @@ -24,11 +50,51 @@ eio_init(void) EAPI int eio_shutdown(void) { + Eio_Progress *progress; + _eio_count--; if (_eio_count > 0) return _eio_count; + /* Cleanup progress pool */ + EINA_TRASH_CLEAN(&trash, progress) + free(progress); + trash_count = 0; + ecore_shutdown(); eina_shutdown(); return _eio_count; } + +Eio_Progress * +eio_progress_malloc(void) +{ + Eio_Progress *progress; + + pthread_mutex_lock(&lock); + progress = eina_trash_pop(&trash); + if (progress) trash_count--; + pthread_mutex_unlock(&lock); + + if (!progress) progress = malloc(sizeof (Eio_Progress)); + return progress; +} + +void +eio_progress_free(Eio_Progress *progress) +{ + eina_stringshare_del(progress->source); + eina_stringshare_del(progress->dest); + + if (trash_count >= EIO_PROGRESS_LIMIT) + { + free(progress); + } + else + { + pthread_mutex_lock(&lock); + eina_trash_push(&trash, progress); + trash_count++; + pthread_mutex_unlock(&lock); + } +} diff --git a/legacy/eio/src/lib/eio_private.h b/legacy/eio/src/lib/eio_private.h index 618656e0fd..865bb0a630 100644 --- a/legacy/eio/src/lib/eio_private.h +++ b/legacy/eio/src/lib/eio_private.h @@ -9,6 +9,9 @@ #include "Eio.h" +/* Keeping 32 Eio_File_Progress alive should be enought */ +#define EIO_PROGRESS_LIMIT 32 + /* Huge TLB == 16M on most system */ #define EIO_PACKET_SIZE 65536 #define EIO_PACKET_COUNT 256 @@ -22,6 +25,8 @@ typedef struct _Eio_File_Stat Eio_File_Stat; typedef struct _Eio_File_Progress Eio_File_Progress; typedef struct _Eio_File_Move Eio_File_Move; +typedef struct _Eio_Dir_Copy Eio_Dir_Copy; + struct _Eio_File { Ecore_Thread *thread; @@ -97,6 +102,14 @@ struct _Eio_File_Move Eio_File *copy; }; +struct _Eio_Dir_Copy +{ + Eio_File_Progress progress; + + Eina_List *files; + Eina_List *dirs; +}; + /* Be aware that ecore_thread_run could call cancel_cb if something goes wrong. */ Eina_Bool eio_file_set(Eio_File *common, Eio_Done_Cb done_cb, @@ -119,4 +132,7 @@ Eina_Bool eio_long_file_set(Eio_File *common, void eio_file_error(Eio_File *common); void eio_file_thread_error(Eio_File *common); +Eio_Progress *eio_progress_malloc(void); +void eio_progress_free(Eio_Progress *progress); + #endif