aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbertrand <Bertrand.Guiheneuf@aful.org>1999-09-18 07:40:06 +0800
committerBertrand Guiheneuf <bertrand@src.gnome.org>1999-09-18 07:40:06 +0800
commit445b09502f6aabb6359c18acb188e92e97da31f7 (patch)
tree47ead377e2f198570cd4819f3052a1d78d1ffc9a
parentacd6bafa58cf5fdea4814e51aac175a99894a373 (diff)
downloadgsoc2013-evolution-445b09502f6aabb6359c18acb188e92e97da31f7.tar
gsoc2013-evolution-445b09502f6aabb6359c18acb188e92e97da31f7.tar.gz
gsoc2013-evolution-445b09502f6aabb6359c18acb188e92e97da31f7.tar.bz2
gsoc2013-evolution-445b09502f6aabb6359c18acb188e92e97da31f7.tar.lz
gsoc2013-evolution-445b09502f6aabb6359c18acb188e92e97da31f7.tar.xz
gsoc2013-evolution-445b09502f6aabb6359c18acb188e92e97da31f7.tar.zst
gsoc2013-evolution-445b09502f6aabb6359c18acb188e92e97da31f7.zip
new func. Try to exec an operation in a thread or queue it if a thread is
1999-09-18 bertrand <Bertrand.Guiheneuf@aful.org> * camel/camel-folder-pt-proxy.c (_op_exec_or_plan_for_exec): new func. Try to exec an operation in a thread or queue it if a thread is already busy. * camel/camel-op-queue.c (camel_op_queue_set_service_availability): (camel_op_queue_get_service_availability): new funcs. * camel/camel-op-queue.c (camel_op_new): (camel_op_free): new funcs. Uses glib mem chunks. svn path=/trunk/; revision=1237
-rw-r--r--ChangeLog15
-rw-r--r--camel/camel-folder-pt-proxy.c28
-rw-r--r--camel/camel-op-queue.c67
-rw-r--r--camel/camel-op-queue.h11
4 files changed, 106 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 5a6d24a6cf..5762789481 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+1999-09-18 bertrand <Bertrand.Guiheneuf@aful.org>
+
+ * camel/camel-folder-pt-proxy.c (_op_exec_or_plan_for_exec):
+ new func. Try to exec an operation in a thread
+ or queue it if a thread is already busy.
+
+ * camel/camel-op-queue.c (camel_op_queue_set_service_availability):
+ (camel_op_queue_get_service_availability):
+ new funcs.
+
+ * camel/camel-op-queue.c (camel_op_new):
+ (camel_op_free):
+ new funcs. Uses glib mem chunks.
+
+
1999-09-17 bertrand <Bertrand.Guiheneuf@aful.org>
* camel/camel-folder-pt-proxy.c (_init_with_store):
diff --git a/camel/camel-folder-pt-proxy.c b/camel/camel-folder-pt-proxy.c
index d8031fb398..b87f19382d 100644
--- a/camel/camel-folder-pt-proxy.c
+++ b/camel/camel-folder-pt-proxy.c
@@ -138,8 +138,6 @@ camel_folder_proxy_class_init (CamelFolderPtProxyClass *camel_folder_pt_proxy_cl
static void
camel_folder_proxy_init (CamelFolderPtProxy *folder_pt_proxy)
{
-
-
folder_pt_proxy->op_queue = camel_op_queue_new ();
}
@@ -187,9 +185,17 @@ _finalize (GtkObject *object)
static void
-_plan_op_for_exec (CamelOp *op)
+_op_exec_or_plan_for_exec (CamelFolderPtProxy *proxy_folder, CamelOp *op)
{
-
+ CamelOpQueue *op_queue;
+ pthread_t thread;
+
+ op_queue = proxy_folder->op_queue;
+
+ if (op_queue->service_available) {
+ op_queue->service_available = FALSE;
+ pthread_create (&thread, NULL , (thread_call_func)(op->func), op->param);
+ }
}
@@ -229,6 +235,7 @@ _init_with_store (CamelFolder *folder, CamelStore *parent_store)
_InitStoreParam *param;
pthread_t init_store_thread;
int filedes[2];
+ CamelOp *op;
#warning Notify io_channel initialization should be elsewhere
/* it can not be in camel_folder_proxy_init
@@ -244,18 +251,17 @@ _init_with_store (CamelFolder *folder, CamelStore *parent_store)
proxy_folder->pipe_client_fd = filedes [0];
proxy_folder->pipe_server_fd = filedes [1];
proxy_folder->notify_source = g_io_channel_unix_new (filedes [0]);
-
+
+ op = camel_op_new ();
/* param will be freed in _async_init_with_store */
param = g_new (_InitStoreParam, 1);
param->folder = folder;
param->parent_store = parent_store;
- /*
- * call _async_init_with_store in a separate thread
- * the thread may block on a mutex, but not the main
- * thread.
- */
- pthread_create (&init_store_thread, NULL , (thread_call_func)_async_init_with_store, param);
+ op->func = async_init_with_store;
+ op->param = param;
+
+
}
diff --git a/camel/camel-op-queue.c b/camel/camel-op-queue.c
index c58ade9958..d943b8e80b 100644
--- a/camel/camel-op-queue.c
+++ b/camel/camel-op-queue.c
@@ -21,7 +21,8 @@
#include "camel-op-queue.h"
-
+#define NB_OP_CHUNKS 20
+static GMemChunk *op_chunk=NULL;
/**
* camel_op_queue_new: create a new operation queue
@@ -34,6 +35,11 @@ CamelOpQueue *
camel_op_queue_new ()
{
CamelOpQueue *op_queue;
+ if (!op_chunk)
+ op_chunk = g_mem_chunk_create (CamelOp,
+ NB_OP_CHUNKS,
+ G_ALLOC_AND_FREE);
+
op_queue = g_new (CamelOpQueue, 1);
op_queue->ops_tail = NULL;
op_queue->ops_head = NULL;
@@ -104,7 +110,64 @@ camel_op_queue_run_next_op (CamelOpQueue *queue)
if (!op) return FALSE;
/* run the operation */
- op->op_func (op->param);
+ op->func (op->param);
return FALSE;
}
+
+/**
+ * camel_op_queue_set_service_availability: set the service availability for an operation queue
+ * @queue: queue object
+ * @available: availability flag
+ *
+ * set the service availability
+ **/
+void
+camel_op_queue_set_service_availability (CamelOpQueue *queue, gboolean available)
+{
+ queue->service_available = available;
+}
+
+/**
+ * camel_op_queue_get_service_availability: determine if an operation queue service is available
+ * @queue: queue object
+ *
+ * Determine if the service associated to an operation queue is available.
+ *
+ * Return value: service availability.
+ **/
+gboolean
+camel_op_queue_get_service_availability (CamelOpQueue *queue)
+{
+ return queue->service_available;
+}
+
+/**
+ * camel_op_new: return a new CamelOp object
+ *
+ * The obtained object must be destroyed with
+ * camel_op_free ()
+ *
+ * Return value: the newly allocated CamelOp object
+ **/
+CamelOp *
+camel_op_new ()
+{
+ return g_chunk_new (CamelOp, op_chunk);
+}
+
+/**
+ * camel_op_free: free a CamelOp object allocated with camel_op_new
+ * @op: CamelOp object to free
+ *
+ * Free a CamelOp object allocated with camel_op_new ()
+ * this routine won't work with CamelOp objects allocated
+ * with other allocators.
+ **/
+void
+camel_op_free (CamelOp *op)
+{
+ g_chunk_free (op, op_chunk);
+}
+
+
diff --git a/camel/camel-op-queue.h b/camel/camel-op-queue.h
index e99d785b93..672413d562 100644
--- a/camel/camel-op-queue.h
+++ b/camel/camel-op-queue.h
@@ -34,7 +34,7 @@ extern "C" {
typedef void (CamelOpFunc)(gpointer param);
typedef struct {
- CamelOpFunc *op_func;
+ CamelOpFunc *func;
gpointer param;
} CamelOp;
@@ -44,7 +44,8 @@ typedef struct
{
GList *ops_head;
GList *ops_tail;
- gint pending_ops;
+ gboolean service_available;
+
} CamelOpQueue;
@@ -53,6 +54,12 @@ CamelOpQueue *camel_op_queue_new ();
void camel_op_queue_push_op (CamelOpQueue *queue, CamelOp *op);
CamelOp *camel_op_queue_pop_op (CamelOpQueue *queue);
gboolean camel_op_queue_run_next_op (CamelOpQueue *queue);
+gboolean camel_op_queue_get_service_availability (CamelOpQueue *queue);
+CamelOp *camel_op_new ();
+
+CamelOp *camel_op_new ();
+void camel_op_free (CamelOp *op);
+
#ifdef __cplusplus
}