From 448c9ebb9313ffaebb237b73cd4ac5f0c394e325 Mon Sep 17 00:00:00 2001 From: bertrand Date: Fri, 17 Sep 1999 23:40:06 +0000 Subject: [PATCH] new func. Try to exec an operation in a thread or queue it if a thread is 1999-09-18 bertrand * 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. --- camel/camel-folder-pt-proxy.c | 28 +++++++++++------- camel/camel-op-queue.c | 67 +++++++++++++++++++++++++++++++++++++++++-- camel/camel-op-queue.h | 11 +++++-- 3 files changed, 91 insertions(+), 15 deletions(-) diff --git a/camel/camel-folder-pt-proxy.c b/camel/camel-folder-pt-proxy.c index d8031fb..b87f193 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 c58ade9..d943b8e 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 e99d785..672413d 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 } -- 2.7.4