From 3797918d013db678b61d62956ed14ad50e7b70e1 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Wed, 27 Jun 2001 22:43:00 +0000 Subject: Initialize the private send_lock. (camel_transport_finalize): Free the 2001-06-27 Jeffrey Stedfast * camel-transport.c (camel_transport_init): Initialize the private send_lock. (camel_transport_finalize): Free the private send_lock. (camel_transport_get_type): Set the init and finalize functions. (camel_transport_send): Lock the transport. (camel_transport_send_to): Same. * camel-private.h: Add CAMEL_TRANSPORT_(UN)LOCK macros. svn path=/trunk/; revision=10547 --- camel/ChangeLog | 11 +++++++++++ camel/camel-private.h | 14 ++++++++++++++ camel/camel-transport.c | 47 +++++++++++++++++++++++++++++++++++++++++++---- camel/camel-transport.h | 2 ++ 4 files changed, 70 insertions(+), 4 deletions(-) (limited to 'camel') diff --git a/camel/ChangeLog b/camel/ChangeLog index 7bcee459fa..dfafd7d909 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,14 @@ +2001-06-27 Jeffrey Stedfast + + * camel-transport.c (camel_transport_init): Initialize the private + send_lock. + (camel_transport_finalize): Free the private send_lock. + (camel_transport_get_type): Set the init and finalize functions. + (camel_transport_send): Lock the transport. + (camel_transport_send_to): Same. + + * camel-private.h: Add CAMEL_TRANSPORT_(UN)LOCK macros. + 2001-06-27 Jeffrey Stedfast * tests/folder/test9.c (main): Updated to match the current API. diff --git a/camel/camel-private.h b/camel/camel-private.h index fa9b50a8a0..f63a452a4c 100644 --- a/camel/camel-private.h +++ b/camel/camel-private.h @@ -73,6 +73,20 @@ struct _CamelStorePrivate { #define CAMEL_STORE_UNLOCK(f, l) #endif +struct _CamelTransportPrivate { +#ifdef ENABLE_THREADS + GMutex *send_lock; /* for locking send operations */ +#endif +}; + +#ifdef ENABLE_THREADS +#define CAMEL_TRANSPORT_LOCK(f, l) (g_mutex_lock(((CamelTransport *)f)->priv->l)) +#define CAMEL_TRANSPORT_UNLOCK(f, l) (g_mutex_unlock(((CamelTransport *)f)->priv->l)) +#else +#define CAMEL_TRANSPORT_LOCK(f, l) +#define CAMEL_TRANSPORT_UNLOCK(f, l) +#endif + struct _CamelServicePrivate { #ifdef ENABLE_THREADS EMutex *connect_lock; /* for locking connection operations */ diff --git a/camel/camel-transport.c b/camel/camel-transport.c index 5d902ddd33..0338f5dcc0 100644 --- a/camel/camel-transport.c +++ b/camel/camel-transport.c @@ -30,10 +30,33 @@ #include "camel-transport.h" #include "camel-exception.h" +#include "camel-private.h" /* Returns the class for a CamelTransport */ #define CT_CLASS(so) CAMEL_TRANSPORT_CLASS (CAMEL_OBJECT_GET_CLASS(so)) +static void +camel_transport_init (gpointer object, gpointer klass) +{ + CamelTransport *xport = object; + + xport->priv = g_malloc0 (sizeof (struct _CamelTransportPrivate)); +#ifdef ENABLE_THREADS + xport->priv->send_lock = g_mutex_new (); +#endif +} + +static void +camel_transport_finalize (CamelObject *object) +{ + CamelTransport *xport = CAMEL_TRANSPORT (object); + +#ifdef ENABLE_THREADS + g_mutex_free (xport->priv->send_lock); +#endif + g_free (xport->priv); +} + CamelType camel_transport_get_type (void) { @@ -45,8 +68,8 @@ camel_transport_get_type (void) sizeof (CamelTransportClass), NULL, NULL, - NULL, - NULL); + (CamelObjectInitFunc) camel_transport_init, + (CamelObjectFinalizeFunc) camel_transport_finalize); } return camel_transport_type; @@ -84,7 +107,15 @@ gboolean camel_transport_send (CamelTransport *transport, CamelMedium *message, CamelException *ex) { - return CT_CLASS (transport)->send (transport, message, ex); + gboolean sent; + + g_return_val_if_fail (CAMEL_IS_TRANSPORT (transport), FALSE); + + CAMEL_TRANSPORT_LOCK (transport, send_lock); + sent = CT_CLASS (transport)->send (transport, message, ex); + CAMEL_TRANSPORT_UNLOCK (transport, send_lock); + + return sent; } /** @@ -103,6 +134,14 @@ gboolean camel_transport_send_to (CamelTransport *transport, CamelMedium *message, GList *recipients, CamelException *ex) { - return CT_CLASS (transport)->send_to (transport, message, + gboolean sent; + + g_return_val_if_fail (CAMEL_IS_TRANSPORT (transport), FALSE); + + CAMEL_TRANSPORT_LOCK (transport, send_lock); + sent = CT_CLASS (transport)->send_to (transport, message, recipients, ex); + CAMEL_TRANSPORT_UNLOCK (transport, send_lock); + + return sent; } diff --git a/camel/camel-transport.h b/camel/camel-transport.h index ae6ca50f40..a4693bdab3 100644 --- a/camel/camel-transport.h +++ b/camel/camel-transport.h @@ -47,6 +47,8 @@ struct _CamelTransport { CamelService parent_object; + struct _CamelTransportPrivate *priv; + gboolean supports_8bit; }; -- cgit