summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2009-05-11 10:30:32 (GMT)
committerAlexander Larsson <alexl@redhat.com>2009-05-11 10:30:32 (GMT)
commitbf8176fa017cb0a3209b92f29817fc48bbf33598 (patch)
tree270260c676d13ea614e720e0088147cdd4bd254b
parentc4c7a2e905a8b2ab31b22768190fd5baa0b0c52e (diff)
downloadgnio-bf8176fa017cb0a3209b92f29817fc48bbf33598.tar.gz
gnio-bf8176fa017cb0a3209b92f29817fc48bbf33598.tar.xz
Use a thread pool in GThreadedSocketService
-rw-r--r--gio/gthreadedsocketservice.c56
1 files changed, 50 insertions, 6 deletions
diff --git a/gio/gthreadedsocketservice.c b/gio/gthreadedsocketservice.c
index 2e2e962..ff2fe89 100644
--- a/gio/gthreadedsocketservice.c
+++ b/gio/gthreadedsocketservice.c
@@ -38,6 +38,12 @@ G_DEFINE_TYPE (GThreadedSocketService,
g_threaded_socket_service,
G_TYPE_SOCKET_SERVICE);
+struct _GThreadedSocketServicePrivate
+{
+ GThreadPool *thread_pool;
+ int max_threads;
+};
+
typedef struct
{
GThreadedSocketService *service;
@@ -45,10 +51,11 @@ typedef struct
GObject *source_object;
} GThreadedSocketServiceData;
-static gpointer
-g_threaded_socket_service_func (gpointer user_data)
+static void
+g_threaded_socket_service_func (gpointer _data,
+ gpointer user_data)
{
- GThreadedSocketServiceData *data = user_data;
+ GThreadedSocketServiceData *data = _data;
gboolean result;
g_signal_emit (data->service, g_threaded_socket_service_run_signal,
@@ -59,8 +66,6 @@ g_threaded_socket_service_func (gpointer user_data)
if (data->source_object)
g_object_unref (data->source_object);
g_slice_free (GThreadedSocketServiceData, data);
-
- return NULL;
}
static gboolean
@@ -68,8 +73,11 @@ g_threaded_socket_service_incoming (GSocketService *service,
GSocketConnection *connection,
GObject *source_object)
{
+ GThreadedSocketService *threaded;
GThreadedSocketServiceData *data;
+ threaded = G_THREADED_SOCKET_SERVICE (service);
+
data = g_slice_new (GThreadedSocketServiceData);
data->service = g_object_ref (service);
data->connection = g_object_ref (connection);
@@ -78,20 +86,56 @@ g_threaded_socket_service_incoming (GSocketService *service,
else
data->source_object = NULL;
- g_thread_create (g_threaded_socket_service_func, data, FALSE, NULL);
+ g_thread_pool_push (threaded->priv->thread_pool, data, NULL);
return FALSE;
}
static void
g_threaded_socket_service_init (GThreadedSocketService *service)
{
+ service->priv = G_TYPE_INSTANCE_GET_PRIVATE (service,
+ G_TYPE_THREADED_SOCKET_SERVICE,
+ GThreadedSocketServicePrivate);
+ service->priv->max_threads = 10;
}
static void
+g_threaded_socket_service_constructed (GObject *object)
+{
+ GThreadedSocketService *service = G_THREADED_SOCKET_SERVICE (object);
+
+ service->priv->thread_pool =
+ g_thread_pool_new (g_threaded_socket_service_func,
+ service,
+ service->priv->max_threads,
+ FALSE,
+ NULL);
+}
+
+
+static void
+g_threaded_socket_service_finalize (GObject *object)
+{
+ GThreadedSocketService *service = G_THREADED_SOCKET_SERVICE (object);
+
+ g_object_unref (service->priv->thread_pool);
+
+ G_OBJECT_CLASS (g_threaded_socket_service_parent_class)
+ ->finalize (object);
+}
+
+
+static void
g_threaded_socket_service_class_init (GThreadedSocketServiceClass *class)
{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (class);
GSocketServiceClass *ss_class = &class->parent_class;
+ g_type_class_add_private (class, sizeof (GThreadedSocketServicePrivate));
+
+ gobject_class->constructed = g_threaded_socket_service_constructed;
+ gobject_class->finalize = g_threaded_socket_service_finalize;
+
ss_class->incoming = g_threaded_socket_service_incoming;
/**