Skip to content

Commit

Permalink
Working out access patterns in order to get linking working.
Browse files Browse the repository at this point in the history
  • Loading branch information
xsdg committed Jul 19, 2022
1 parent b4e9ef5 commit 14d4d38
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/dupe.c
Original file line number Diff line number Diff line change
Expand Up @@ -3013,7 +3013,7 @@ void dupe_window_add_files(DupeWindow *dw, GList *list, gboolean recurse)
{
/* Add only the files, ignore the dirs when no recurse */
dw->add_files_queue = g_list_prepend(dw->add_files_queue, work_file->data);
file_data_ref((FileData *)work_file->data);
file_data_ref(static_cast<FileData *>(work_file->data));
work_file = work_file->next;
}
g_list_free(f);
Expand Down
33 changes: 25 additions & 8 deletions src/filedata.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,35 @@ const gchar *text_from_time(time_t t);
* @headerfile file_data_new_group
* scan for sidecar files - expensive
*/
FileData *file_data_new_group(const gchar *path_utf8);
FileData *file_data_new_group(const gchar *path_utf8)
{
return FileData::file_data_new_group(path_utf8);
}

/**
* @headerfile file_data_new_no_grouping
* should be used on helper files which can't have sidecars
*/
FileData *file_data_new_no_grouping(const gchar *path_utf8);
FileData *file_data_new_no_grouping(const gchar *path_utf8)
{
return FileData::file_data_new_no_grouping(path_utf8);
}

/**
* @headerfile file_data_new_dir
* should be used on dirs
*/
FileData *file_data_new_dir(const gchar *path_utf8);
FileData *file_data_new_dir(const gchar *path_utf8)
{
return FileData::file_data_new_dir(path_utf8);
}

FileData *file_data_new_simple(const gchar *path_utf8);
FileData *file_data_new_simple(const gchar *path_utf8)
{
return FileData::file_data_new_simple(path_utf8);
}

/*
#ifdef DEBUG_FILEDATA
FileData *file_data_ref_debug(const gchar *file, gint line, FileData *fd);
void file_data_unref_debug(const gchar *file, gint line, FileData *fd);
Expand All @@ -72,6 +85,7 @@ void file_data_unref_debug(const gchar *file, gint line, FileData *fd);
FileData *file_data_ref(FileData *fd);
void file_data_unref(FileData *fd);
#endif
*/

void file_data_lock(FileData *fd);
void file_data_unlock(FileData *fd);
Expand All @@ -83,7 +97,10 @@ void file_data_unlock_list(GList *list);

gboolean file_data_check_changed_files(FileData *fd);

void file_data_increment_version(FileData *fd);
void file_data_increment_version(FileData *fd)
{
fd->file_data_increment_version(fd);
}

gboolean file_data_add_change_info(FileData *fd, FileDataChangeType type, const gchar *src, const gchar *dest);
void file_data_change_info_free(FileDataChangeInfo *fdci, FileData *fd);
Expand Down Expand Up @@ -117,8 +134,8 @@ GList *filelist_recursive_full(FileData *dir_fd, SortType method, gboolean ascen

/***************** MARKS *****************/

typedef gboolean (* FileDataGetMarkFunc)(FileData *fd, gint n, gpointer data);
typedef gboolean (* FileDataSetMarkFunc)(FileData *fd, gint n, gboolean value, gpointer data);
// typedef gboolean (* FileDataGetMarkFunc)(FileData *fd, gint n, gpointer data);
// typedef gboolean (* FileDataSetMarkFunc)(FileData *fd, gint n, gboolean value, gpointer data);
gboolean file_data_register_mark_func(gint n, FileDataGetMarkFunc get_mark_func, FileDataSetMarkFunc set_mark_func, gpointer data, GDestroyNotify notify);
void file_data_get_registered_mark_func(gint n, FileDataGetMarkFunc *get_mark_func, FileDataSetMarkFunc *set_mark_func, gpointer *data);

Expand Down Expand Up @@ -190,7 +207,7 @@ void file_data_sc_free_ci_list(GList *fd_list);
GList *file_data_process_groups_in_selection(GList *list, gboolean ungroup, GList **ungrouped);


typedef void (*FileDataNotifyFunc)(FileData *fd, NotifyType type, gpointer data);
// typedef void (*FileDataNotifyFunc)(FileData *fd, NotifyType type, gpointer data);
gboolean file_data_register_notify_func(FileDataNotifyFunc func, gpointer data, NotifyPriority priority);
gboolean file_data_unregister_notify_func(FileDataNotifyFunc func, gpointer data);
void file_data_send_notification(FileData *fd, NotifyType type);
Expand Down
4 changes: 2 additions & 2 deletions src/filedata.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ FileData *file_data_new_simple(const gchar *path_utf8);
#ifdef DEBUG_FILEDATA
FileData *file_data_ref_debug(const gchar *file, gint line, FileData *fd);
void file_data_unref_debug(const gchar *file, gint line, FileData *fd);
#define file_data_ref(fd) file_data_ref_debug(__FILE__, __LINE__, fd)
#define file_data_unref(fd) file_data_unref_debug(__FILE__, __LINE__, fd)
#define file_data_ref(fd) fd->file_data_ref_debug(__FILE__, __LINE__, fd)
#define file_data_unref(fd) fd->file_data_unref_debug(__FILE__, __LINE__, fd)
#else
FileData *file_data_ref(FileData *fd);
void file_data_unref(FileData *fd);
Expand Down
12 changes: 6 additions & 6 deletions src/filedata/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
gint global_file_data_count = 0;
#endif

static GHashTable *file_data_pool = NULL;
static GHashTable *file_data_planned_change_hash = NULL;
GHashTable *file_data_pool = NULL;
GHashTable *file_data_planned_change_hash = NULL;

// private
FileData *FileData::file_data_new(const gchar *path_utf8, struct stat *st, gboolean disable_sidecars)
Expand Down Expand Up @@ -72,7 +72,7 @@ FileData *FileData::file_data_new(const gchar *path_utf8, struct stat *st, gbool
if (!isfile(fd->path))
{
file_data_ref(fd);
file_data_apply_ci(fd);
fd->file_data_apply_ci(fd);
}
else
{
Expand All @@ -85,10 +85,10 @@ FileData *FileData::file_data_new(const gchar *path_utf8, struct stat *st, gbool
{
gboolean changed;

if (disable_sidecars) file_data_disable_grouping(fd, TRUE);
if (disable_sidecars) fd->file_data_disable_grouping(fd, TRUE);


changed = file_data_check_changed_single_file(fd, st);
changed = fd->file_data_check_changed_single_file(fd, st);

DEBUG_2("file_data_pool hit: '%s' %s", fd->path, changed ? "(changed)" : "");

Expand Down Expand Up @@ -137,7 +137,7 @@ FileData *FileData::file_data_new(const gchar *path_utf8, struct stat *st, gbool

if (disable_sidecars) fd->disable_grouping = TRUE;

file_data_set_path(fd, path_utf8); /* set path, name, collate_key_*, original_path */
fd->file_data_set_path(fd, path_utf8); /* set path, name, collate_key_*, original_path */

return fd;
}
Expand Down
14 changes: 8 additions & 6 deletions src/filedata/filelist.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,22 @@ static gboolean filelist_sort_ascend = TRUE;

if (xmp_files)
{
FileDataFunctor<void, void*> callback_functor = {
this, &FileData::file_data_basename_hash_insert_cb, basename_hash};
g_list_foreach(xmp_files, v_wrapper<void, void*>, &callback_functor);
g_list_foreach(xmp_files, &FileData::file_data_basename_hash_insert_cb,
basename_hash);
g_list_free(xmp_files);
}

if (dirs) *dirs = dlist;

if (files)
{
FileDataFunctor<void, void*, void*> callback_functor = {
/* FileDataFunctor<void, void*, void*> callback_functor = {
this, &FileData::file_data_basename_hash_to_sidecars};
g_hash_table_foreach(
basename_hash, v_wrapper<void, void*, void*>, &callback_functor);
basename_hash, v_wrapper<void, void*, void*>, &callback_functor);*/
g_hash_table_foreach(basename_hash,
&FileData::file_data_basename_hash_to_sidecars,
NULL);

*files = filelist_filter_out_sidecars(flist);
}
Expand All @@ -168,7 +170,7 @@ void FileData::filelist_free(GList *list)
work = list;
while (work)
{
file_data_unref((FileData *)work->data);
file_data_unref(static_cast<FileData *>(work->data));
work = work->next;
}

Expand Down
2 changes: 1 addition & 1 deletion src/filedata/sidecar.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ GList *FileData::file_data_process_groups_in_selection(GList *list, gboolean ung

g_assert(sfd->parent == target);

file_data_increment_version(sfd); /* increments both sfd and target */
sfd->file_data_increment_version(sfd); /* increments both sfd and target */

target->sidecar_files = g_list_remove(target->sidecar_files, sfd);
sfd->parent = NULL;
Expand Down
6 changes: 2 additions & 4 deletions src/filedata/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,8 @@ const gchar *FileData::text_from_time(time_t t)

/*static*/ void FileData::file_data_basename_hash_free(GHashTable *basename_hash)
{
FileDataFunctor<void, void*, void*> callback_functor = {
this, &FileData::file_data_basename_hash_remove_list};
g_hash_table_foreach(
basename_hash, v_wrapper<void, void*, void*>, &callback_functor);
g_hash_table_foreach(
basename_hash, &FileData::file_data_basename_hash_remove_list, NULL);
g_hash_table_destroy(basename_hash);
}

Expand Down
2 changes: 1 addition & 1 deletion src/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -3836,7 +3836,7 @@ void mfd_list_free(GList *list)
while (work)
{
MatchFileData *mfd = work->data;
file_data_unref((FileData *)mfd->fd);
file_data_unref(static_cast<FileData *>(mfd->fd));
work = work->next;
}

Expand Down
3 changes: 2 additions & 1 deletion src/slideshow.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ static gboolean slideshow_step(SlideShowData *ss, gboolean forward)

if (ss->filelist)
{
ss->slide_fd = file_data_ref((FileData *)g_list_nth_data(ss->filelist, row));
ss->slide_fd = file_data_ref(
static_cast<FileData *>(g_list_nth_data(ss->filelist, row)));
if (ss->lw)
layout_set_fd(ss->lw, ss->slide_fd);
else
Expand Down
59 changes: 32 additions & 27 deletions src/typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -664,14 +664,11 @@ struct FileData {
public:

private:
// FileData *file_data_new(const gchar *path_utf8, struct stat *st, gboolean disable_sidecars);
GHashTable *file_data_pool = NULL;
GHashTable *file_data_planned_change_hash = NULL;
static GHashTable *file_data_pool; // = NULL;
static GHashTable *file_data_planned_change_hash; // = NULL;

/**** FILELIST ****/
private:
// static gboolean filelist_read_real(const gchar *dir_path, GList **files, GList **dirs,
// gboolean follow_symlinks);

/**** BULK PASTE ****/
private:
Expand All @@ -695,30 +692,38 @@ struct FileData {
static gint file_data_notify_sort(gconstpointer a, gconstpointer b);
gboolean file_data_register_notify_func(FileDataNotifyFunc func, gpointer data, NotifyPriority priority);
gboolean file_data_unregister_notify_func(FileDataNotifyFunc func, gpointer data);
gboolean file_data_send_notification_idle_cb(gpointer data);
void file_data_send_notification(FileData *fd, NotifyType type);
static gboolean file_data_send_notification_idle_cb(gpointer data);
static void file_data_send_notification(FileData *fd, NotifyType type);
void file_data_change_info_free(FileDataChangeInfo *fdci, FileData *fd);

// core.c;
FileData *file_data_new(const gchar *path_utf8, struct stat *st, gboolean disable_sidecars);
/*static*/ FileData *file_data_new_local(const gchar *path, struct stat *st, gboolean disable_sidecars);
/*static*/ FileData *file_data_new_simple(const gchar *path_utf8);
FileData *file_data_new_group(const gchar *path_utf8);
/*static*/ FileData *file_data_new_no_grouping(const gchar *path_utf8);
/*static*/ FileData *file_data_new_dir(const gchar *path_utf8);
static FileData *file_data_new(const gchar *path_utf8, struct stat *st, gboolean disable_sidecars);
/**/static/**/ FileData *file_data_new_local(const gchar *path, struct stat *st, gboolean disable_sidecars);
public:
static FileData *file_data_new_simple(const gchar *path_utf8);
static FileData *file_data_new_group(const gchar *path_utf8);
static FileData *file_data_new_no_grouping(const gchar *path_utf8);
/**/static/**/ FileData *file_data_new_dir(const gchar *path_utf8);
public:
// file_data_ref and file_data_unref are part of the public API.
FileData *file_data_ref_debug(const gchar *file, gint line, FileData *fd);
FileData *file_data_ref(FileData *fd);
private:

/*static*/ void file_data_free(FileData *fd);
/*static*/ gboolean file_data_check_has_ref(FileData *fd);
/*static*/ void file_data_consider_free(FileData *fd);
public:
void file_data_unref_debug(const gchar *file, gint line, FileData *fd);
void file_data_unref(FileData *fd);
void file_data_lock(FileData *fd);
void file_data_unlock(FileData *fd);
void file_data_lock_list(GList *list);
void file_data_unlock_list(GList *list);
// TODO(xsdg): Make metadata.c a friend class and then make
// increment_version a private method.
void file_data_increment_version(FileData *fd);
private:
/*static*/ gboolean file_data_check_changed_single_file(FileData *fd, struct stat *st);
/*static*/ gboolean file_data_check_changed_files_recursive(FileData *fd, struct stat *st);
/**static**/ gboolean file_data_check_changed_files(FileData *fd);
Expand All @@ -739,12 +744,12 @@ struct FileData {
GList *filelist_insert_sort_full(GList *list, gpointer data, SortType method, gboolean ascend, GCompareFunc cb);
GList *filelist_sort(GList *list, SortType method, gboolean ascend);
GList *filelist_insert_sort(GList *list, FileData *fd, SortType method, gboolean ascend);
/*static*/ GList *filelist_filter_out_sidecars(GList *flist);
/**/static/**/ GList *filelist_filter_out_sidecars(GList *flist);

/*static*/ gboolean filelist_read_real(const gchar *dir_path, GList **files, GList **dirs, gboolean follow_symlinks);
/**/static/**/ gboolean filelist_read_real(const gchar *dir_path, GList **files, GList **dirs, gboolean follow_symlinks);
gboolean filelist_read(FileData *dir_fd, GList **files, GList **dirs);
gboolean filelist_read_lstat(FileData *dir_fd, GList **files, GList **dirs);
void filelist_free(GList *list);
static void filelist_free(GList *list);
static gint filelist_sort_path_cb(gconstpointer a, gconstpointer b);
/*static*/ void filelist_recursive_append(GList **list, GList *dirs);
/*static*/ void filelist_recursive_append_full(GList **list, GList *dirs, SortType method, gboolean ascend);
Expand Down Expand Up @@ -789,8 +794,8 @@ struct FileData {

/*static*/ gboolean file_data_list_contains_whole_group(GList *list, FileData *fd);
/*static*/ gint sidecar_file_priority(const gchar *extension);
/*static*/ void file_data_check_sidecars(const GList *basename_list);
/*static*/ void file_data_disconnect_sidecar_file(FileData *target, FileData *sfd);
/**/static/**/ void file_data_check_sidecars(const GList *basename_list);
/**/static/**/ void file_data_disconnect_sidecar_file(FileData *target, FileData *sfd);
void file_data_disable_grouping(FileData *fd, gboolean disable);
void file_data_disable_grouping_list(GList *fd_list, gboolean disable);

Expand Down Expand Up @@ -833,18 +838,18 @@ struct FileData {
gchar *text_from_size(gint64 size);
gchar *text_from_size_abrev(gint64 size);
const gchar *text_from_time(time_t t);
/*static*/ GHashTable *file_data_basename_hash_new(void);
/**/static/**/ GHashTable *file_data_basename_hash_new(void);
gchar *file_data_get_error_string(gint error);

static gint file_data_sort_by_ext(gconstpointer a, gconstpointer b);
/*static*/ GList * file_data_basename_hash_insert(GHashTable *basename_hash, FileData *fd);
/*static*/ void file_data_basename_hash_insert_cb(gpointer fd, gpointer basename_hash);
/*static*/ void file_data_basename_hash_remove_list(gpointer key, gpointer value, gpointer data);
/*static*/ void file_data_basename_hash_free(GHashTable *basename_hash);
/*static*/ void file_data_basename_hash_to_sidecars(gpointer key, gpointer value, gpointer data);
/*static*/ gboolean is_hidden_file(const gchar *name);
/*static*/ gboolean file_data_can_write_directly(FileData *fd);
/*static*/ gboolean file_data_can_write_sidecar(FileData *fd);
/**/static/**/ GList * file_data_basename_hash_insert(GHashTable *basename_hash, FileData *fd);
/**/static/**/ void file_data_basename_hash_insert_cb(gpointer fd, gpointer basename_hash);
/**/static/**/ void file_data_basename_hash_remove_list(gpointer key, gpointer value, gpointer data);
/**/static/**/ void file_data_basename_hash_free(GHashTable *basename_hash);
/**/static/**/ void file_data_basename_hash_to_sidecars(gpointer key, gpointer value, gpointer data);
/**/static/**/ gboolean is_hidden_file(const gchar *name);
/**/static/**/ gboolean file_data_can_write_directly(FileData *fd);
/**/static/**/ gboolean file_data_can_write_sidecar(FileData *fd);
gint file_data_get_user_orientation(FileData *fd);
void file_data_set_user_orientation(FileData *fd, gint value);
void file_data_set_page_num(FileData *fd, gint page_num);
Expand Down

0 comments on commit 14d4d38

Please sign in to comment.