[anjuta/libgit2-glib: 5/5] libanjuta: Implement AnjutaThreadPool



commit e83f6a2680f3867904ded4ad750dc391402f1ddd
Author: James Liggett <jrliggett cox net>
Date:   Sun Jun 30 23:53:16 2013 -0700

    libanjuta: Implement AnjutaThreadPool

 libanjuta/Makefile.am          |    4 ++-
 libanjuta/anjuta-thread-pool.c |   72 ++++++++++++++++++++++++++++++++++++++++
 libanjuta/anjuta-thread-pool.h |   60 +++++++++++++++++++++++++++++++++
 3 files changed, 135 insertions(+), 1 deletions(-)
---
diff --git a/libanjuta/Makefile.am b/libanjuta/Makefile.am
index 14f1dc4..4c8e984 100644
--- a/libanjuta/Makefile.am
+++ b/libanjuta/Makefile.am
@@ -144,7 +144,9 @@ libanjuta_3_la_SOURCES= \
        anjuta-async-task.c \
        anjuta-async-task.h \
        anjuta-thread-pool-task.c \
-       anjuta-thread-pool-task.h
+       anjuta-thread-pool-task.h \
+       anjuta-thread-pool.c \
+       anjuta-thread-pool.h
 
 # Glade module
 if ENABLE_GLADE_CATALOG
diff --git a/libanjuta/anjuta-thread-pool.c b/libanjuta/anjuta-thread-pool.c
new file mode 100644
index 0000000..b19e5ee
--- /dev/null
+++ b/libanjuta/anjuta-thread-pool.c
@@ -0,0 +1,72 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*-  */
+/*
+ * anjuta-thread-pool.c
+ * Copyright (C) 2013 James Liggett <jim jim-dekstop>
+ *
+ * anjuta is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * anjuta 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 General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "anjuta-thread-pool.h"
+
+struct _AnjutaThreadPoolPrivate
+{
+       GThreadPool *thread_pool;
+};
+
+
+G_DEFINE_TYPE (AnjutaThreadPool, anjuta_thread_pool, G_TYPE_OBJECT);
+
+static void
+start_task (AnjutaThreadPoolTask *task, gpointer user_data)
+{
+       anjuta_task_start (ANJUTA_TASK (task));
+}
+
+static void
+anjuta_thread_pool_init (AnjutaThreadPool *self)
+{
+       self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, ANJUTA_TYPE_THREAD_POOL, AnjutaThreadPoolPrivate);
+
+       self->priv->thread_pool = g_thread_pool_new ((GFunc) start_task,
+                                                    NULL, -1, FALSE, NULL);
+}
+
+static void
+anjuta_thread_pool_finalize (GObject *object)
+{
+       AnjutaThreadPool *self;
+
+       self = ANJUTA_THREAD_POOL (object);
+
+       g_thread_pool_free (self->priv->thread_pool, TRUE, FALSE);
+
+       G_OBJECT_CLASS (anjuta_thread_pool_parent_class)->finalize (object);
+}
+
+static void
+anjuta_thread_pool_class_init (AnjutaThreadPoolClass *klass)
+{
+       GObjectClass* object_class = G_OBJECT_CLASS (klass);
+
+       g_type_class_add_private (klass, sizeof (AnjutaThreadPoolPrivate));
+
+       object_class->finalize = anjuta_thread_pool_finalize;
+}
+
+void
+anjuta_thread_pool_push (AnjutaThreadPool *self, AnjutaThreadPoolTask *task)
+{
+       anjuta_thread_pool_task_notify_waiting (task);
+       g_thread_pool_push (self->priv->thread_pool, task, NULL);
+}
diff --git a/libanjuta/anjuta-thread-pool.h b/libanjuta/anjuta-thread-pool.h
new file mode 100644
index 0000000..2244a0e
--- /dev/null
+++ b/libanjuta/anjuta-thread-pool.h
@@ -0,0 +1,60 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*-  */
+/*
+ * anjuta-thread-pool.h
+ * Copyright (C) 2013 James Liggett <jim jim-dekstop>
+ *
+ * anjuta is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * anjuta 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 General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _ANJUTA_THREAD_POOL_H_
+#define _ANJUTA_THREAD_POOL_H_
+
+#include <glib-object.h>
+#include "anjuta-thread-pool-task.h"
+
+G_BEGIN_DECLS
+
+#define ANJUTA_TYPE_THREAD_POOL             (anjuta_thread_pool_get_type ())
+#define ANJUTA_THREAD_POOL(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), ANJUTA_TYPE_THREAD_POOL, 
AnjutaThreadPool))
+#define ANJUTA_THREAD_POOL_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), ANJUTA_TYPE_THREAD_POOL, 
AnjutaThreadPoolClass))
+#define ANJUTA_IS_THREAD_POOL(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ANJUTA_TYPE_THREAD_POOL))
+#define ANJUTA_IS_THREAD_POOL_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), ANJUTA_TYPE_THREAD_POOL))
+#define ANJUTA_THREAD_POOL_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), ANJUTA_TYPE_THREAD_POOL, 
AnjutaThreadPoolClass))
+
+typedef struct _AnjutaThreadPoolClass AnjutaThreadPoolClass;
+typedef struct _AnjutaThreadPool AnjutaThreadPool;
+typedef struct _AnjutaThreadPoolPrivate AnjutaThreadPoolPrivate;
+
+
+struct _AnjutaThreadPoolClass
+{
+       GObjectClass parent_class;
+};
+
+struct _AnjutaThreadPool
+{
+       GObject parent_instance;
+
+       AnjutaThreadPoolPrivate *priv;
+};
+
+GType anjuta_thread_pool_get_type (void) G_GNUC_CONST;
+
+void anjuta_thread_pool_push (AnjutaThreadPool *self, 
+                              AnjutaThreadPoolTask *task);
+
+G_END_DECLS
+
+#endif /* _ANJUTA_THREAD_POOL_H_ */
+


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]