[anjuta/libgit2-glib: 4/5] libanjuta: Implement AnjutaThreadPoolTask



commit 72a8ecb9b86c26c14e046b69d7909822ac1bd178
Author: James Liggett <jrliggett cox net>
Date:   Sun Jun 30 20:01:25 2013 -0700

    libanjuta: Implement AnjutaThreadPoolTask

 libanjuta/Makefile.am               |    4 +-
 libanjuta/anjuta-thread-pool-task.c |  108 +++++++++++++++++++++++++++++++++++
 libanjuta/anjuta-thread-pool-task.h |   60 +++++++++++++++++++
 3 files changed, 171 insertions(+), 1 deletions(-)
---
diff --git a/libanjuta/Makefile.am b/libanjuta/Makefile.am
index 5fd0d09..14f1dc4 100644
--- a/libanjuta/Makefile.am
+++ b/libanjuta/Makefile.am
@@ -142,7 +142,9 @@ libanjuta_3_la_SOURCES= \
        anjuta-task.c \
        anjuta-task.h \
        anjuta-async-task.c \
-       anjuta-async-task.h
+       anjuta-async-task.h \
+       anjuta-thread-pool-task.c \
+       anjuta-thread-pool-task.h
 
 # Glade module
 if ENABLE_GLADE_CATALOG
diff --git a/libanjuta/anjuta-thread-pool-task.c b/libanjuta/anjuta-thread-pool-task.c
new file mode 100644
index 0000000..9013ac3
--- /dev/null
+++ b/libanjuta/anjuta-thread-pool-task.c
@@ -0,0 +1,108 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*-  */
+/*
+ * anjuta-thread-pool-task.c
+ * Copyright (C) 2013 James Liggett <jrliggett cox net>
+ *
+ * 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-task.h"
+
+struct _AnjutaThreadPoolTaskPrivate
+{
+       GMutex waiting_mutex;
+       gboolean waiting;
+};
+
+
+G_DEFINE_TYPE (AnjutaThreadPoolTask, anjuta_thread_pool_task, ANJUTA_TYPE_ASYNC_TASK);
+
+static void
+anjuta_thread_pool_task_init (AnjutaThreadPoolTask *self)
+{
+       self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, ANJUTA_TYPE_THREAD_POOL_TASK, 
AnjutaThreadPoolTaskPrivate);
+
+       g_mutex_init (&self->priv->waiting_mutex);
+}
+
+static void
+anjuta_thread_pool_task_finalize (GObject *object)
+{
+       AnjutaThreadPoolTask *self;
+
+       self = ANJUTA_THREAD_POOL_TASK (object);
+
+       g_mutex_clear (&self->priv->waiting_mutex);
+
+       G_OBJECT_CLASS (anjuta_thread_pool_task_parent_class)->finalize (object);
+}
+
+static void
+start (AnjutaTask *task)
+{
+       AnjutaThreadPoolTask *self;
+
+       self = ANJUTA_THREAD_POOL_TASK (task);
+
+       if (anjuta_thread_pool_task_is_ready (self))
+       {
+               g_mutex_lock (&self->priv->waiting_mutex);
+               self->priv->waiting = FALSE;
+               g_mutex_unlock (&self->priv->waiting_mutex);
+
+               ANJUTA_TASK_CLASS (anjuta_thread_pool_task_parent_class)->start (task);
+               ANJUTA_TASK_GET_CLASS (self)->run (task);
+       }
+}
+
+static void
+anjuta_thread_pool_task_class_init (AnjutaThreadPoolTaskClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       AnjutaTaskClass *task_class = ANJUTA_TASK_CLASS (klass);
+
+       g_type_class_add_private (klass, sizeof (AnjutaThreadPoolTaskPrivate));
+
+       object_class->finalize = anjuta_thread_pool_task_finalize;
+       task_class->start = start;
+}
+
+
+gboolean
+anjuta_thread_pool_task_is_ready (AnjutaThreadPoolTask *self)
+{
+       return !anjuta_task_is_running (ANJUTA_TASK (self)) &&
+                  !anjuta_thread_pool_task_is_waiting (self);
+}
+
+gboolean
+anjuta_thread_pool_task_is_waiting (AnjutaThreadPoolTask *self)
+{
+       gboolean waiting;
+
+       g_mutex_lock (&self->priv->waiting_mutex);
+       waiting = self->priv->waiting;
+       g_mutex_unlock (&self->priv->waiting_mutex);
+
+       return waiting;
+}
+
+void
+anjuta_thread_pool_task_notify_waiting (AnjutaThreadPoolTask *self)
+{
+       g_mutex_lock (&self->priv->waiting_mutex);
+       self->priv->waiting = TRUE;
+       g_mutex_unlock (&self->priv->waiting_mutex);
+}
+
diff --git a/libanjuta/anjuta-thread-pool-task.h b/libanjuta/anjuta-thread-pool-task.h
new file mode 100644
index 0000000..f151409
--- /dev/null
+++ b/libanjuta/anjuta-thread-pool-task.h
@@ -0,0 +1,60 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*-  */
+/*
+ * anjuta-thread-pool-task.h
+ * Copyright (C) 2013 James Liggett <jrliggett cox net>
+ *
+ * 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_TASK_H_
+#define _ANJUTA_THREAD_POOL_TASK_H_
+
+#include <glib-object.h>
+#include "anjuta-async-task.h"
+
+G_BEGIN_DECLS
+
+#define ANJUTA_TYPE_THREAD_POOL_TASK             (anjuta_thread_pool_task_get_type ())
+#define ANJUTA_THREAD_POOL_TASK(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
ANJUTA_TYPE_THREAD_POOL_TASK, AnjutaThreadPoolTask))
+#define ANJUTA_THREAD_POOL_TASK_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), 
ANJUTA_TYPE_THREAD_POOL_TASK, AnjutaThreadPoolTaskClass))
+#define ANJUTA_IS_THREAD_POOL_TASK(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
ANJUTA_TYPE_THREAD_POOL_TASK))
+#define ANJUTA_IS_THREAD_POOL_TASK_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), 
ANJUTA_TYPE_THREAD_POOL_TASK))
+#define ANJUTA_THREAD_POOL_TASK_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), 
ANJUTA_TYPE_THREAD_POOL_TASK, AnjutaThreadPoolTaskClass))
+
+typedef struct _AnjutaThreadPoolTaskClass AnjutaThreadPoolTaskClass;
+typedef struct _AnjutaThreadPoolTask AnjutaThreadPoolTask;
+typedef struct _AnjutaThreadPoolTaskPrivate AnjutaThreadPoolTaskPrivate;
+
+
+struct _AnjutaThreadPoolTaskClass
+{
+       AnjutaAsyncTaskClass parent_class;
+};
+
+struct _AnjutaThreadPoolTask
+{
+       AnjutaAsyncTask parent_instance;
+
+       AnjutaThreadPoolTaskPrivate *priv;
+};
+
+GType anjuta_thread_pool_task_get_type (void) G_GNUC_CONST;
+gboolean anjuta_thread_pool_task_is_ready (AnjutaThreadPoolTask *self);
+gboolean anjuta_thread_pool_task_is_waiting (AnjutaThreadPoolTask *self);
+void anjuta_thread_pool_task_notify_waiting (AnjutaThreadPoolTask *self);
+
+G_END_DECLS
+
+#endif /* _ANJUTA_THREAD_POOL_TASK_H_ */
+


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