aboutsummaryrefslogtreecommitdiffstats
path: root/camel/camel-data-wrapper.c
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2001-11-03 07:53:36 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2001-11-03 07:53:36 +0800
commitd2e6a28e22a2352d4622265693405b3f193c6aee (patch)
tree4881b7f8f2d4c53f8bc68c20c397b33a474e2599 /camel/camel-data-wrapper.c
parentdc354f10e83c1a1aca64454ef45059af4b69279e (diff)
downloadgsoc2013-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
Diffstat (limited to 'camel/camel-data-wrapper.c')
-rw-r--r--camel/camel-data-wrapper.c36
1 files changed, 27 insertions, 9 deletions
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);
}