X-Git-Url: http://geeqie.org/cgi-bin/gitweb.cgi?p=geeqie.git;a=blobdiff_plain;f=src%2Ffiledata.c;h=6adafc2464588ad491c16031dacfcf1a8e72e36f;hp=bc9685c09604246b3e8f45d7f1fda92b3cf78128;hb=1ea92516e2f91b7f99b1d41d44853f941d98e114;hpb=710b009f5c61e7d1643a2a474e5020c760bf6462 diff --git a/src/filedata.c b/src/filedata.c index bc9685c0..6adafc24 100644 --- a/src/filedata.c +++ b/src/filedata.c @@ -532,6 +532,7 @@ static void file_data_free(FileData *fd) { g_assert(fd->magick == FD_MAGICK); g_assert(fd->ref == 0); + g_assert(!fd->locked); metadata_cache_free(fd); g_hash_table_remove(file_data_pool, fd->original_path); @@ -630,10 +631,12 @@ void file_data_unref(FileData *fd) /** * \brief Lock the FileData in memory. * - * This allows the caller to prevent a FileData from being freed, even - * after its refcount is zero. + * This allows the caller to prevent a FileData from being freed, even after its refcount is zero. + * This is intended to be used in cases where a FileData _should_ stay in memory as an optimization, + * even if the code would continue to function properly even if the FileData were freed. Code that + * _requires_ the FileData to remain in memory should continue to use file_data_(un)ref. *

- * This differs from file_data_ref in that the behavior is reentrant -- after N calls to + * Note: This differs from file_data_ref in that the behavior is reentrant -- after N calls to * file_data_lock, a single call to file_data_unlock will unlock the FileData. */ void file_data_lock(FileData *fd) @@ -666,6 +669,42 @@ void file_data_unlock(FileData *fd) file_data_consider_free(fd); } +/** + * \brief Lock all of the FileDatas in the provided list + * + * \see file_data_lock(FileData) + */ +void file_data_lock_list(GList *list) +{ + GList *work; + + work = list; + while (work) + { + FileData *fd = work->data; + work = work->next; + file_data_lock(fd); + } +} + +/** + * \brief Unlock all of the FileDatas in the provided list + * + * \see file_data_unlock(FileData) + */ +void file_data_unlock_list(GList *list) +{ + GList *work; + + work = list; + while (work) + { + FileData *fd = work->data; + work = work->next; + file_data_unlock(fd); + } +} + /* *----------------------------------------------------------------------------- * sidecar file info struct