mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-19 23:28:54 +02:00
Make GIOSchedulerJobFunc return boolean Keep calling io jobs until they
2008-01-25 Matthias Clasen <mclasen@redhat.com> * gioscheduler.h: Make GIOSchedulerJobFunc return boolean * gioscheduler.c: Keep calling io jobs until they return FALSE; this allows big jobs to be executed in chunks, instead of blocking the main loop for a long time. * gsimpleasyncresult.c: * giofile.c: Adapt callers. svn path=/trunk/; revision=6375
This commit is contained in:
committed by
Matthias Clasen
parent
06d957d95d
commit
8228f7f94b
@@ -1,3 +1,13 @@
|
|||||||
|
2008-01-25 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
|
* gioscheduler.h: Make GIOSchedulerJobFunc return boolean
|
||||||
|
* gioscheduler.c: Keep calling io jobs until they return FALSE;
|
||||||
|
this allows big jobs to be executed in chunks, instead of blocking
|
||||||
|
the main loop for a long time.
|
||||||
|
|
||||||
|
* gsimpleasyncresult.c:
|
||||||
|
* giofile.c: Adapt callers.
|
||||||
|
|
||||||
2008-01-25 Alexander Larsson <alexl@redhat.com>
|
2008-01-25 Alexander Larsson <alexl@redhat.com>
|
||||||
|
|
||||||
* gdesktopappinfo.c:
|
* gdesktopappinfo.c:
|
||||||
|
12
gio/gfile.c
12
gio/gfile.c
@@ -4273,8 +4273,8 @@ mainloop_barrier (gpointer user_data)
|
|||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
copy_async_progress_callback (goffset current_num_bytes,
|
copy_async_progress_callback (goffset current_num_bytes,
|
||||||
goffset total_num_bytes,
|
goffset total_num_bytes,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
CopyAsyncData *data = user_data;
|
CopyAsyncData *data = user_data;
|
||||||
@@ -4291,10 +4291,10 @@ copy_async_progress_callback (goffset current_num_bytes,
|
|||||||
g_free);
|
g_free);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static gboolean
|
||||||
copy_async_thread (GIOSchedulerJob *job,
|
copy_async_thread (GIOSchedulerJob *job,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *res;
|
GSimpleAsyncResult *res;
|
||||||
CopyAsyncData *data;
|
CopyAsyncData *data;
|
||||||
@@ -4327,6 +4327,8 @@ copy_async_thread (GIOSchedulerJob *job,
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_simple_async_result_complete_in_idle (res);
|
g_simple_async_result_complete_in_idle (res);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@@ -152,45 +152,54 @@ remove_active_job (GIOSchedulerJob *job)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
io_job_thread (gpointer data,
|
job_destroy (gpointer data)
|
||||||
gpointer user_data)
|
|
||||||
{
|
{
|
||||||
GIOSchedulerJob *job = data;
|
GIOSchedulerJob *job = data;
|
||||||
|
|
||||||
if (job->cancellable)
|
|
||||||
g_cancellable_push_current (job->cancellable);
|
|
||||||
job->job_func (job, job->cancellable, job->data);
|
|
||||||
if (job->cancellable)
|
|
||||||
g_cancellable_pop_current (job->cancellable);
|
|
||||||
|
|
||||||
if (job->destroy_notify)
|
if (job->destroy_notify)
|
||||||
job->destroy_notify (job->data);
|
job->destroy_notify (job->data);
|
||||||
|
|
||||||
remove_active_job (job);
|
remove_active_job (job);
|
||||||
g_io_job_free (job);
|
g_io_job_free (job);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
io_job_thread (gpointer data,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GIOSchedulerJob *job = data;
|
||||||
|
gboolean result;
|
||||||
|
|
||||||
|
if (job->cancellable)
|
||||||
|
g_cancellable_push_current (job->cancellable);
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
result = job->job_func (job, job->cancellable, job->data);
|
||||||
|
}
|
||||||
|
while (result);
|
||||||
|
|
||||||
|
if (job->cancellable)
|
||||||
|
g_cancellable_pop_current (job->cancellable);
|
||||||
|
|
||||||
|
job_destroy (job);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
run_job_at_idle (gpointer data)
|
run_job_at_idle (gpointer data)
|
||||||
{
|
{
|
||||||
GIOSchedulerJob *job = data;
|
GIOSchedulerJob *job = data;
|
||||||
|
gboolean result;
|
||||||
|
|
||||||
if (job->cancellable)
|
if (job->cancellable)
|
||||||
g_cancellable_push_current (job->cancellable);
|
g_cancellable_push_current (job->cancellable);
|
||||||
|
|
||||||
job->job_func (job, job->cancellable, job->data);
|
result = job->job_func (job, job->cancellable, job->data);
|
||||||
|
|
||||||
if (job->cancellable)
|
if (job->cancellable)
|
||||||
g_cancellable_pop_current (job->cancellable);
|
g_cancellable_pop_current (job->cancellable);
|
||||||
|
|
||||||
if (job->destroy_notify)
|
return result;
|
||||||
job->destroy_notify (job->data);
|
|
||||||
|
|
||||||
remove_active_job (job);
|
|
||||||
g_io_job_free (job);
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -249,7 +258,7 @@ g_io_scheduler_push_job (GIOSchedulerJobFunc job_func,
|
|||||||
*/
|
*/
|
||||||
job->idle_tag = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE + 1 + io_priority / 10,
|
job->idle_tag = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE + 1 + io_priority / 10,
|
||||||
run_job_at_idle,
|
run_job_at_idle,
|
||||||
job, NULL);
|
job, job_destroy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -53,10 +53,13 @@ typedef struct _GIOSchedulerJob GIOSchedulerJob;
|
|||||||
*
|
*
|
||||||
* Long-running jobs should periodically check the @cancellable
|
* Long-running jobs should periodically check the @cancellable
|
||||||
* to see if they have been cancelled.
|
* to see if they have been cancelled.
|
||||||
|
*
|
||||||
|
* Returns: %TRUE if this function should be called again to
|
||||||
|
* complete the job, %FALSE if the job is complete (or cancelled)
|
||||||
**/
|
**/
|
||||||
typedef void (*GIOSchedulerJobFunc) (GIOSchedulerJob *job,
|
typedef gboolean (*GIOSchedulerJobFunc) (GIOSchedulerJob *job,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
|
||||||
void g_io_scheduler_push_job (GIOSchedulerJobFunc job_func,
|
void g_io_scheduler_push_job (GIOSchedulerJobFunc job_func,
|
||||||
gpointer user_data,
|
gpointer user_data,
|
||||||
|
@@ -595,10 +595,10 @@ typedef struct {
|
|||||||
GSimpleAsyncThreadFunc func;
|
GSimpleAsyncThreadFunc func;
|
||||||
} RunInThreadData;
|
} RunInThreadData;
|
||||||
|
|
||||||
static void
|
static gboolean
|
||||||
run_in_thread (GIOSchedulerJob *job,
|
run_in_thread (GIOSchedulerJob *job,
|
||||||
GCancellable *c,
|
GCancellable *c,
|
||||||
gpointer _data)
|
gpointer _data)
|
||||||
{
|
{
|
||||||
RunInThreadData *data = _data;
|
RunInThreadData *data = _data;
|
||||||
GSimpleAsyncResult *simple = data->simple;
|
GSimpleAsyncResult *simple = data->simple;
|
||||||
@@ -617,6 +617,8 @@ run_in_thread (GIOSchedulerJob *job,
|
|||||||
g_simple_async_result_complete_in_idle (data->simple);
|
g_simple_async_result_complete_in_idle (data->simple);
|
||||||
g_object_unref (data->simple);
|
g_object_unref (data->simple);
|
||||||
g_free (data);
|
g_free (data);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user