## GIOScheduler

GIOScheduler — I/O Scheduler

## Synopsis

    #include <gio/gio.h>

                        GIOSchedulerJob;
    gboolean            (*GIOSchedulerJobFunc)              (GIOSchedulerJob *job,
                                                             GCancellable *cancellable,
                                                             gpointer user_data);
    void                g_io_scheduler_push_job             (GIOSchedulerJobFunc job_func,
                                                             gpointer user_data,
                                                             GDestroyNotify notify,
                                                             gint io_priority,
                                                             GCancellable *cancellable);
    void                g_io_scheduler_cancel_all_jobs      (void);
    gboolean            g_io_scheduler_job_send_to_mainloop (GIOSchedulerJob *job,
                                                             GSourceFunc func,
                                                             gpointer user_data,
                                                             GDestroyNotify notify);
    void                g_io_scheduler_job_send_to_mainloop_async
                                                            (GIOSchedulerJob *job,
                                                             GSourceFunc func,
                                                             gpointer user_data,
                                                             GDestroyNotify notify);

## Description

### Note

As of GLib 2.36, the `g_io_scheduler` methods are deprecated in favor of GThreadPool and GTask.

Schedules asynchronous I/O operations. GIOScheduler integrates into the main event loop (GMainLoop) and uses threads.

## Details

### GIOSchedulerJob

    typedef struct _GIOSchedulerJob GIOSchedulerJob;

Opaque class for defining and scheduling IO jobs.

### GIOSchedulerJobFunc ()

    gboolean            (*GIOSchedulerJobFunc)              (GIOSchedulerJob *job,
                                                             GCancellable *cancellable,
                                                             gpointer user_data);

I/O Job function.

Long-running jobs should periodically check the `cancellable` to see if they have been cancelled.

`job` : | a GIOSchedulerJob.
`cancellable` : | optional GCancellable object, `NULL` to ignore.
`user_data` : | the data to pass to callback function
Returns : | `TRUE` if this function should be called again to complete the job, `FALSE` if the job is complete (or cancelled)

### g_io_scheduler_push_job ()

    void                g_io_scheduler_push_job             (GIOSchedulerJobFunc job_func,
                                                             gpointer user_data,
                                                             GDestroyNotify notify,
                                                             gint io_priority,
                                                             GCancellable *cancellable);

### Warning

`g_io_scheduler_push_job` is deprecated and should not be used in newly-written code. use GThreadPool or `g_task_run_in_thread()`

Schedules the I/O job to run in another thread.

`notify` will be called on `user_data` after `job_func` has returned, regardless whether the job was cancelled or has run to completion.

If `cancellable` is not `NULL`, it can be used to cancel the I/O job by calling `g_cancellable_cancel()` or by calling `g_io_scheduler_cancel_all_jobs()`.

`job_func` : | a GIOSchedulerJobFunc.
`user_data` : | data to pass to `job_func`
`notify` : | a GDestroyNotify for `user_data`, or `NULL`. [allow-none]
`io_priority` : | the I/O priority of the request.
`cancellable` : | optional GCancellable object, `NULL` to ignore.

### g_io_scheduler_cancel_all_jobs ()

    void                g_io_scheduler_cancel_all_jobs      (void);

### Warning

`g_io_scheduler_cancel_all_jobs` is deprecated and should not be used in newly-written code. You should never call this function, since you don't know how other libraries in your program might be making use of gioscheduler.

Cancels all cancellable I/O jobs.

A job is cancellable if a GCancellable was passed into `g_io_scheduler_push_job()`.

### g_io_scheduler_job_send_to_mainloop ()

    gboolean            g_io_scheduler_job_send_to_mainloop (GIOSchedulerJob *job,
                                                             GSourceFunc func,
                                                             gpointer user_data,
                                                             GDestroyNotify notify);

### Warning

`g_io_scheduler_job_send_to_mainloop` is deprecated and should not be used in newly-written code. Use `g_main_context_invoke()`.

Used from an I/O job to send a callback to be run in the thread that the job was started from, waiting for the result (and thus blocking the I/O job).

`job` : | a GIOSchedulerJob
`func` : | a GSourceFunc callback that will be called in the original thread
`user_data` : | data to pass to `func`
`notify` : | a GDestroyNotify for `user_data`, or `NULL`. [allow-none]
Returns : | The return value of `func`

### g_io_scheduler_job_send_to_mainloop_async ()

    void                g_io_scheduler_job_send_to_mainloop_async
                                                            (GIOSchedulerJob *job,
                                                             GSourceFunc func,
                                                             gpointer user_data,
                                                             GDestroyNotify notify);

### Warning

`g_io_scheduler_job_send_to_mainloop_async` is deprecated and should not be used in newly-written code. Use `g_main_context_invoke()`.

Used from an I/O job to send a callback to be run asynchronously in the thread that the job was started from. The callback will be run when the main loop is available, but at that time the I/O job might have finished. The return value from the callback is ignored.

Note that if you are passing the `user_data` from `g_io_scheduler_push_job()` on to this function you have to ensure that it is not freed before `func` is called, either by passing `NULL` as `notify` to `g_io_scheduler_push_job()` or by using refcounting for `user_data`.

`job` : | a GIOSchedulerJob
`func` : | a GSourceFunc callback that will be called in the original thread
`user_data` : | data to pass to `func`
`notify` : | a GDestroyNotify for `user_data`, or `NULL`. [allow-none]