mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-26 15:36:14 +01:00
Merge branch 'unix_mount_points' into 'main'
Add cache to g_unix_mount_points_get() See merge request GNOME/glib!1707
This commit is contained in:
commit
d286ea0c57
@ -1666,6 +1666,14 @@ g_unix_mount_for (const char *file_path,
|
||||
return entry;
|
||||
}
|
||||
|
||||
static gpointer
|
||||
copy_mount_point_cb (gconstpointer src,
|
||||
gpointer data)
|
||||
{
|
||||
GUnixMountPoint *src_mount_point = (GUnixMountPoint *) src;
|
||||
return g_unix_mount_point_copy (src_mount_point);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_unix_mount_points_get:
|
||||
* @time_read: (out) (optional): guint64 to contain a timestamp.
|
||||
@ -1681,10 +1689,29 @@ g_unix_mount_for (const char *file_path,
|
||||
GList *
|
||||
g_unix_mount_points_get (guint64 *time_read)
|
||||
{
|
||||
if (time_read)
|
||||
*time_read = get_mount_points_timestamp ();
|
||||
static GList *mnt_pts_last = NULL;
|
||||
static guint64 time_read_last = 0;
|
||||
GList *mnt_pts = NULL;
|
||||
guint64 time_read_now;
|
||||
G_LOCK_DEFINE_STATIC (unix_mount_points);
|
||||
|
||||
return _g_get_unix_mount_points ();
|
||||
G_LOCK (unix_mount_points);
|
||||
|
||||
time_read_now = get_mount_points_timestamp ();
|
||||
if (time_read_now != time_read_last || mnt_pts_last == NULL)
|
||||
{
|
||||
time_read_last = time_read_now;
|
||||
g_list_free_full (mnt_pts_last, (GDestroyNotify) g_unix_mount_point_free);
|
||||
mnt_pts_last = _g_get_unix_mount_points ();
|
||||
}
|
||||
mnt_pts = g_list_copy_deep (mnt_pts_last, copy_mount_point_cb, NULL);
|
||||
|
||||
G_UNLOCK (unix_mount_points);
|
||||
|
||||
if (time_read)
|
||||
*time_read = time_read_now;
|
||||
|
||||
return mnt_pts;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user