diff options
author | Jeffrey Stedfast <fejj@ximian.com> | 2001-11-03 07:53:36 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2001-11-03 07:53:36 +0800 |
commit | d2e6a28e22a2352d4622265693405b3f193c6aee (patch) | |
tree | 4881b7f8f2d4c53f8bc68c20c397b33a474e2599 | |
parent | dc354f10e83c1a1aca64454ef45059af4b69279e (diff) | |
download | gsoc2013-evolution-d2e6a28e22a2352d4622265693405b3f193c6aee.tar.gz gsoc2013-evolution-d2e6a28e22a2352d4622265693405b3f193c6aee.tar.zst gsoc2013-evolution-d2e6a28e22a2352d4622265693405b3f193c6aee.zip |
Initialize our private mutex. (camel_data_wrapper_finalize): Destroy our
2001-11-02 Jeffrey Stedfast <fejj@ximian.com>
* camel-data-wrapper.c (camel_data_wrapper_init): Initialize our
private mutex.
(camel_data_wrapper_finalize): Destroy our private mutex.
(write_to_stream): Lock around camel_stream_write_to_stream() so
that we don't get 2 threads trying to read from our stream at the
same time.
svn path=/trunk/; revision=14573
-rw-r--r-- | camel/ChangeLog | 9 | ||||
-rw-r--r-- | camel/camel-data-wrapper.c | 36 | ||||
-rw-r--r-- | camel/camel-data-wrapper.h | 6 | ||||
-rw-r--r-- | camel/camel-private.h | 19 |
4 files changed, 56 insertions, 14 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog index 88f557a2a1..3a2e167524 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,12 @@ +2001-11-02 Jeffrey Stedfast <fejj@ximian.com> + + * camel-data-wrapper.c (camel_data_wrapper_init): Initialize our + private mutex. + (camel_data_wrapper_finalize): Destroy our private mutex. + (write_to_stream): Lock around camel_stream_write_to_stream() so + that we don't get 2 threads trying to read from our stream at the + same time. + 2001-11-01 <NotZed@Ximian.com> * camel-vee-folder.c (folder_changed_change): Move all searching diff --git a/camel/camel-data-wrapper.c b/camel/camel-data-wrapper.c index 541b140de1..de0e2e2cf0 100644 --- a/camel/camel-data-wrapper.c +++ b/camel/camel-data-wrapper.c @@ -32,6 +32,7 @@ #include "camel-mime-utils.h" #include "camel-stream.h" #include "camel-exception.h" +#include "camel-private.h" #define d(x) @@ -40,7 +41,6 @@ static CamelObjectClass *parent_class = NULL; /* Returns the class for a CamelDataWrapper */ #define CDW_CLASS(so) CAMEL_DATA_WRAPPER_CLASS (CAMEL_OBJECT_GET_CLASS(so)) - static int construct_from_stream(CamelDataWrapper *, CamelStream *); static int write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream); static void set_mime_type (CamelDataWrapper *data_wrapper, const gchar *mime_type); @@ -68,7 +68,12 @@ static void camel_data_wrapper_init (gpointer object, gpointer klass) { CamelDataWrapper *camel_data_wrapper = CAMEL_DATA_WRAPPER (object); - + + camel_data_wrapper->priv = g_malloc (sizeof (struct _CamelDataWrapperPrivate)); +#ifdef ENABLE_THREADS + pthread_mutex_init (&camel_data_wrapper->priv->stream_lock, NULL); +#endif + camel_data_wrapper->mime_type = header_content_type_new ("application", "octet-stream"); camel_data_wrapper->offline = FALSE; camel_data_wrapper->rawtext = FALSE; @@ -78,10 +83,15 @@ static void camel_data_wrapper_finalize (CamelObject *object) { CamelDataWrapper *camel_data_wrapper = CAMEL_DATA_WRAPPER (object); - + +#ifdef ENABLE_THREADS + pthread_mutex_destroy (&camel_data_wrapper->priv->stream_lock); +#endif + g_free (camel_data_wrapper->priv); + if (camel_data_wrapper->mime_type) header_content_type_unref (camel_data_wrapper->mime_type); - + if (camel_data_wrapper->stream) camel_object_unref (CAMEL_OBJECT (camel_data_wrapper->stream)); } @@ -107,14 +117,22 @@ camel_data_wrapper_get_type (void) static int write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) { + int ret; + if (data_wrapper->stream == NULL) { return -1; } - - if (camel_stream_reset (data_wrapper->stream) == -1) + + CAMEL_DATA_WRAPPER_LOCK (data_wrapper, stream_lock); + if (camel_stream_reset (data_wrapper->stream) == -1) { + CAMEL_DATA_WRAPPER_UNLOCK (data_wrapper, stream_lock); return -1; - - return camel_stream_write_to_stream (data_wrapper->stream, stream); + } + + ret = camel_stream_write_to_stream (data_wrapper->stream, stream); + CAMEL_DATA_WRAPPER_UNLOCK (data_wrapper, stream_lock); + + return ret; } CamelDataWrapper * @@ -173,7 +191,7 @@ camel_data_wrapper_construct_from_stream (CamelDataWrapper *data_wrapper, { g_return_val_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper), -1); g_return_val_if_fail (CAMEL_IS_STREAM (stream), -1); - + return CDW_CLASS (data_wrapper)->construct_from_stream (data_wrapper, stream); } diff --git a/camel/camel-data-wrapper.h b/camel/camel-data-wrapper.h index 329304e143..d8c7fbe50b 100644 --- a/camel/camel-data-wrapper.h +++ b/camel/camel-data-wrapper.h @@ -27,7 +27,6 @@ #ifndef CAMEL_DATA_WRAPPER_H #define CAMEL_DATA_WRAPPER_H 1 - #ifdef __cplusplus extern "C" { #pragma } @@ -44,10 +43,11 @@ extern "C" { struct _CamelDataWrapper { CamelObject parent_object; - + struct _CamelDataWrapperPrivate *priv; + CamelContentType *mime_type; CamelStream *stream; - + unsigned int offline:1; unsigned int rawtext:1; }; diff --git a/camel/camel-private.h b/camel/camel-private.h index c6a31575e0..b73ef9a36d 100644 --- a/camel/camel-private.h +++ b/camel/camel-private.h @@ -183,9 +183,24 @@ struct _CamelVeeFolderPrivate { #define CAMEL_VEE_FOLDER_UNLOCK(f, l) #endif +struct _CamelDataWrapperPrivate { +#ifdef ENABLE_THREADS + pthread_mutex_t stream_lock; +#else + gpointer dummy; +#endif +}; + +#ifdef ENABLE_THREADS +#define CAMEL_DATA_WRAPPER_LOCK(dw, l) (pthread_mutex_lock(&((CamelDataWrapper *)dw)->priv->l)) +#define CAMEL_DATA_WRAPPER_UNLOCK(dw, l) (pthread_mutex_unlock(&((CamelDataWrapper *)dw)->priv->l)) +#else +#define CAMEL_DATA_WRAPPER_LOCK(dw, l) +#define CAMEL_DATA_WRAPPER_UNLOCK(dw, l) +#endif + #ifdef __cplusplus } #endif /* __cplusplus */ -#endif /* CAMEL_H */ - +#endif /* CAMEL_PRIVATE_H */ |