mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-26 15:36:14 +01:00
GTask: new GAsyncResult implementation / threaded task manager
GTask is a replacement for GSimpleAsyncResult and GIOScheduler, that also allows for making cancellable wrappers around non-cancellable functions (as in GThreadedResolver). https://bugzilla.gnome.org/show_bug.cgi?id=661767
This commit is contained in:
parent
132c4cee4f
commit
4aeefa70a1
@ -42,6 +42,7 @@
|
|||||||
<xi:include href="xml/gasyncresult.xml"/>
|
<xi:include href="xml/gasyncresult.xml"/>
|
||||||
<xi:include href="xml/gioscheduler.xml"/>
|
<xi:include href="xml/gioscheduler.xml"/>
|
||||||
<xi:include href="xml/gsimpleasyncresult.xml"/>
|
<xi:include href="xml/gsimpleasyncresult.xml"/>
|
||||||
|
<xi:include href="xml/gtask.xml"/>
|
||||||
</chapter>
|
</chapter>
|
||||||
<chapter id="conversion">
|
<chapter id="conversion">
|
||||||
<title>Data conversion</title>
|
<title>Data conversion</title>
|
||||||
|
@ -3921,3 +3921,56 @@ g_test_dbus_unset
|
|||||||
g_test_dbus_get_type
|
g_test_dbus_get_type
|
||||||
g_test_dbus_flags_get_type
|
g_test_dbus_flags_get_type
|
||||||
</SECTION>
|
</SECTION>
|
||||||
|
|
||||||
|
<SECTION>
|
||||||
|
<FILE>gtask</FILE>
|
||||||
|
<TITLE>GTask</TITLE>
|
||||||
|
GTask
|
||||||
|
g_task_new
|
||||||
|
g_task_set_task_data
|
||||||
|
g_task_set_priority
|
||||||
|
g_task_set_check_cancellable
|
||||||
|
g_task_set_return_on_cancel
|
||||||
|
g_task_set_source_tag
|
||||||
|
<SUBSECTION>
|
||||||
|
g_task_report_error
|
||||||
|
g_task_report_new_error
|
||||||
|
<SUBSECTION>
|
||||||
|
g_task_get_task_data
|
||||||
|
g_task_get_priority
|
||||||
|
g_task_get_cancellable
|
||||||
|
g_task_get_check_cancellable
|
||||||
|
g_task_get_return_on_cancel
|
||||||
|
g_task_get_context
|
||||||
|
g_task_get_source_object
|
||||||
|
g_task_get_source_tag
|
||||||
|
<SUBSECTION>
|
||||||
|
g_task_return_boolean
|
||||||
|
g_task_return_int
|
||||||
|
g_task_return_pointer
|
||||||
|
g_task_return_error
|
||||||
|
g_task_return_new_error
|
||||||
|
g_task_return_error_if_cancelled
|
||||||
|
<SUBSECTION>
|
||||||
|
g_task_propagate_boolean
|
||||||
|
g_task_propagate_int
|
||||||
|
g_task_propagate_pointer
|
||||||
|
g_task_had_error
|
||||||
|
<SUBSECTION>
|
||||||
|
g_task_run_in_thread
|
||||||
|
g_task_run_in_thread_sync
|
||||||
|
GTaskThreadFunc
|
||||||
|
g_task_attach_source
|
||||||
|
<SUBSECTION>
|
||||||
|
g_task_is_valid
|
||||||
|
<SUBSECTION Standard>
|
||||||
|
GTaskClass
|
||||||
|
GTaskPrivate
|
||||||
|
G_TYPE_TASK
|
||||||
|
G_TASK
|
||||||
|
G_IS_TASK
|
||||||
|
G_TASK_CLASS
|
||||||
|
G_IS_TASK_CLASS
|
||||||
|
G_TASK_GET_CLASS
|
||||||
|
g_task_get_type
|
||||||
|
</SECTION>
|
||||||
|
@ -135,3 +135,4 @@ g_menu_get_type
|
|||||||
g_menu_item_get_type
|
g_menu_item_get_type
|
||||||
g_test_dbus_get_type
|
g_test_dbus_get_type
|
||||||
g_test_dbus_flags_get_type
|
g_test_dbus_flags_get_type
|
||||||
|
g_task_get_type
|
||||||
|
@ -430,6 +430,7 @@ libgio_2_0_la_SOURCES = \
|
|||||||
gproxyaddressenumerator.c \
|
gproxyaddressenumerator.c \
|
||||||
gsocketservice.c \
|
gsocketservice.c \
|
||||||
gsrvtarget.c \
|
gsrvtarget.c \
|
||||||
|
gtask.c \
|
||||||
gtcpconnection.c \
|
gtcpconnection.c \
|
||||||
gtcpwrapperconnection.c \
|
gtcpwrapperconnection.c \
|
||||||
gthreadedsocketservice.c\
|
gthreadedsocketservice.c\
|
||||||
@ -599,6 +600,7 @@ gio_headers = \
|
|||||||
gsocketlistener.h \
|
gsocketlistener.h \
|
||||||
gsocketservice.h \
|
gsocketservice.h \
|
||||||
gsrvtarget.h \
|
gsrvtarget.h \
|
||||||
|
gtask.h \
|
||||||
gtcpconnection.h \
|
gtcpconnection.h \
|
||||||
gtcpwrapperconnection.h \
|
gtcpwrapperconnection.h \
|
||||||
gthreadedsocketservice.h\
|
gthreadedsocketservice.h\
|
||||||
|
@ -122,6 +122,7 @@
|
|||||||
#include <gio/gsocketlistener.h>
|
#include <gio/gsocketlistener.h>
|
||||||
#include <gio/gsocketservice.h>
|
#include <gio/gsocketservice.h>
|
||||||
#include <gio/gsrvtarget.h>
|
#include <gio/gsrvtarget.h>
|
||||||
|
#include <gio/gtask.h>
|
||||||
#include <gio/gtcpconnection.h>
|
#include <gio/gtcpconnection.h>
|
||||||
#include <gio/gtcpwrapperconnection.h>
|
#include <gio/gtcpwrapperconnection.h>
|
||||||
#include <gio/gtestdbus.h>
|
#include <gio/gtestdbus.h>
|
||||||
|
@ -1767,3 +1767,34 @@ g_test_dbus_down
|
|||||||
g_test_dbus_stop
|
g_test_dbus_stop
|
||||||
g_test_dbus_up
|
g_test_dbus_up
|
||||||
g_test_dbus_unset
|
g_test_dbus_unset
|
||||||
|
g_task_attach_source
|
||||||
|
g_task_get_cancellable
|
||||||
|
g_task_get_check_cancellable
|
||||||
|
g_task_get_context
|
||||||
|
g_task_get_priority
|
||||||
|
g_task_get_return_on_cancel
|
||||||
|
g_task_get_source_object
|
||||||
|
g_task_get_source_tag
|
||||||
|
g_task_get_task_data
|
||||||
|
g_task_get_type
|
||||||
|
g_task_had_error
|
||||||
|
g_task_is_valid
|
||||||
|
g_task_new
|
||||||
|
g_task_propagate_boolean
|
||||||
|
g_task_propagate_int
|
||||||
|
g_task_propagate_pointer
|
||||||
|
g_task_run_in_thread
|
||||||
|
g_task_run_in_thread_sync
|
||||||
|
g_task_set_check_cancellable
|
||||||
|
g_task_set_priority
|
||||||
|
g_task_set_return_on_cancel
|
||||||
|
g_task_set_source_tag
|
||||||
|
g_task_set_task_data
|
||||||
|
g_task_report_error
|
||||||
|
g_task_report_new_error
|
||||||
|
g_task_return_boolean
|
||||||
|
g_task_return_error
|
||||||
|
g_task_return_error_if_cancelled
|
||||||
|
g_task_return_int
|
||||||
|
g_task_return_new_error
|
||||||
|
g_task_return_pointer
|
||||||
|
@ -199,6 +199,7 @@ typedef struct _GSocketAddress GSocketAddress;
|
|||||||
typedef struct _GSocketAddressEnumerator GSocketAddressEnumerator;
|
typedef struct _GSocketAddressEnumerator GSocketAddressEnumerator;
|
||||||
typedef struct _GSocketConnectable GSocketConnectable;
|
typedef struct _GSocketConnectable GSocketConnectable;
|
||||||
typedef struct _GSrvTarget GSrvTarget;
|
typedef struct _GSrvTarget GSrvTarget;
|
||||||
|
typedef struct _GTask GTask;
|
||||||
/**
|
/**
|
||||||
* GTcpConnection:
|
* GTcpConnection:
|
||||||
*
|
*
|
||||||
|
1805
gio/gtask.c
Normal file
1805
gio/gtask.c
Normal file
File diff suppressed because it is too large
Load Diff
160
gio/gtask.h
Normal file
160
gio/gtask.h
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
/* GIO - GLib Input, Output and Streaming Library
|
||||||
|
*
|
||||||
|
* Copyright 2011 Red Hat, Inc.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General
|
||||||
|
* Public License along with this library; if not, write to the
|
||||||
|
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||||||
|
* Boston, MA 02111-1307, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
|
||||||
|
#error "Only <gio/gio.h> can be included directly."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __G_TASK_H__
|
||||||
|
#define __G_TASK_H__
|
||||||
|
|
||||||
|
#include <gio/giotypes.h>
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
#define G_TYPE_TASK (g_task_get_type ())
|
||||||
|
#define G_TASK(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_TASK, GTask))
|
||||||
|
#define G_TASK_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_TASK, GTaskClass))
|
||||||
|
#define G_IS_TASK(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_TASK))
|
||||||
|
#define G_IS_TASK_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_TASK))
|
||||||
|
#define G_TASK_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_TYPE_TASK, GTaskClass))
|
||||||
|
|
||||||
|
typedef struct _GTaskClass GTaskClass;
|
||||||
|
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
GType g_task_get_type (void) G_GNUC_CONST;
|
||||||
|
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
GTask *g_task_new (gpointer source_object,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer callback_data);
|
||||||
|
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
void g_task_report_error (gpointer source_object,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer callback_data,
|
||||||
|
gpointer source_tag,
|
||||||
|
GError *error);
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
void g_task_report_new_error (gpointer source_object,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer callback_data,
|
||||||
|
gpointer source_tag,
|
||||||
|
GQuark domain,
|
||||||
|
gint code,
|
||||||
|
const char *format,
|
||||||
|
...);
|
||||||
|
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
void g_task_set_task_data (GTask *task,
|
||||||
|
gpointer task_data,
|
||||||
|
GDestroyNotify task_data_destroy);
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
void g_task_set_priority (GTask *task,
|
||||||
|
gint priority);
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
void g_task_set_check_cancellable (GTask *task,
|
||||||
|
gboolean check_cancellable);
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
void g_task_set_source_tag (GTask *task,
|
||||||
|
gpointer source_tag);
|
||||||
|
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
gpointer g_task_get_source_object (GTask *task);
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
gpointer g_task_get_task_data (GTask *task);
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
gint g_task_get_priority (GTask *task);
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
GMainContext *g_task_get_context (GTask *task);
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
GCancellable *g_task_get_cancellable (GTask *task);
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
gboolean g_task_get_check_cancellable (GTask *task);
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
gpointer g_task_get_source_tag (GTask *task);
|
||||||
|
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
gboolean g_task_is_valid (gpointer result,
|
||||||
|
gpointer source_object);
|
||||||
|
|
||||||
|
|
||||||
|
typedef void (*GTaskThreadFunc) (GTask *task,
|
||||||
|
gpointer source_object,
|
||||||
|
gpointer task_data,
|
||||||
|
GCancellable *cancellable);
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
void g_task_run_in_thread (GTask *task,
|
||||||
|
GTaskThreadFunc task_func);
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
void g_task_run_in_thread_sync (GTask *task,
|
||||||
|
GTaskThreadFunc task_func);
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
gboolean g_task_set_return_on_cancel (GTask *task,
|
||||||
|
gboolean return_on_cancel);
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
gboolean g_task_get_return_on_cancel (GTask *task);
|
||||||
|
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
void g_task_attach_source (GTask *task,
|
||||||
|
GSource *source,
|
||||||
|
GSourceFunc callback);
|
||||||
|
|
||||||
|
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
void g_task_return_pointer (GTask *task,
|
||||||
|
gpointer result,
|
||||||
|
GDestroyNotify result_destroy);
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
void g_task_return_boolean (GTask *task,
|
||||||
|
gboolean result);
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
void g_task_return_int (GTask *task,
|
||||||
|
gssize result);
|
||||||
|
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
void g_task_return_error (GTask *task,
|
||||||
|
GError *error);
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
void g_task_return_new_error (GTask *task,
|
||||||
|
GQuark domain,
|
||||||
|
gint code,
|
||||||
|
const char *format,
|
||||||
|
...) G_GNUC_PRINTF (4, 5);
|
||||||
|
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
gboolean g_task_return_error_if_cancelled (GTask *task);
|
||||||
|
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
gpointer g_task_propagate_pointer (GTask *task,
|
||||||
|
GError **error);
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
gboolean g_task_propagate_boolean (GTask *task,
|
||||||
|
GError **error);
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
gssize g_task_propagate_int (GTask *task,
|
||||||
|
GError **error);
|
||||||
|
GLIB_AVAILABLE_IN_2_36
|
||||||
|
gboolean g_task_had_error (GTask *task);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif /* __G_TASK_H__ */
|
1
gio/tests/.gitignore
vendored
1
gio/tests/.gitignore
vendored
@ -96,6 +96,7 @@ socket
|
|||||||
socket-client
|
socket-client
|
||||||
socket-server
|
socket-server
|
||||||
srvtarget
|
srvtarget
|
||||||
|
task
|
||||||
test.mo
|
test.mo
|
||||||
test.gresource
|
test.gresource
|
||||||
test_resources.c
|
test_resources.c
|
||||||
|
@ -62,6 +62,7 @@ TEST_PROGS += \
|
|||||||
proxy-test \
|
proxy-test \
|
||||||
inet-address \
|
inet-address \
|
||||||
permission \
|
permission \
|
||||||
|
task \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
if HAVE_DBUS_DAEMON
|
if HAVE_DBUS_DAEMON
|
||||||
@ -469,6 +470,9 @@ inet_address_LDADD = $(progs_ldadd)
|
|||||||
permission_SOURCES = permission.c
|
permission_SOURCES = permission.c
|
||||||
permission_LDADD = $(progs_ldadd)
|
permission_LDADD = $(progs_ldadd)
|
||||||
|
|
||||||
|
task_SOURCES = task.c
|
||||||
|
task_LDADD = $(progs_ldadd)
|
||||||
|
|
||||||
schema_tests = \
|
schema_tests = \
|
||||||
schema-tests/array-default-not-in-choices.gschema.xml \
|
schema-tests/array-default-not-in-choices.gschema.xml \
|
||||||
schema-tests/bad-choice.gschema.xml \
|
schema-tests/bad-choice.gschema.xml \
|
||||||
|
1668
gio/tests/task.c
Normal file
1668
gio/tests/task.c
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user