Re: [evolution-patches] CamelObject with gslice



On Tue, 2006-10-17 at 21:41 -0400, Matthew Barnes wrote:
> On Wed, 2006-10-18 at 02:58 +0200, Philip Van Hoof wrote: 

> Since you and I are working on similar enhancements for Camel and
> Evolution-Data-Server, perhaps it would be more productive to forward
> (or at least CC) relevant patches directly to me.  Then I can
> integrate them into CVS HEAD and get them into Bugzilla in a form that
> the upstream guys are more likely to approve.
> 
> I can also get the patches into Fedora Rawhide quickly so that they
> get more widespread testing before upstream even sees them.
> 
> Patches in this mailing list are just too hard to track.  I think the
> mailing list is best used as a means of calling attention to Bugzilla
> bugs containing patches that need reviewed.

Hey Matthew,

I will keep the evolution-patches mailing list in CC until they ask me
not to do that anymore. It's changes to their project, so in my opinion
they have the right to get all work related to that project. They aren't
obligated to receive or accept it, of course. 

However ;)

I wrote next to the copyright reassignment contract which I (had to)
sign with Novell (a few years ago, when I did a bounty for Evolution)
that I ONLY accept copyright reassignment for work and patches that I
have sent to specifically the evolution- patches mailing list 'myself'.

For any other patch, for example any patch that you can find online or a
set of changes which you can derive from a forked version of Camel, I
have not (emphasis "not") yet agreed on 'any' copyright reassignment as
required by Novell to get the changes in their main repository.

It's a second reason why I submit these "counterproductive" patches:
It's my official way of telling Novell: you are allowed to transfer the
copyright of "this specific work" to yourself. Usually I allow all my
work on Evolution to be copyright reassigned to Novell. I do, however,
want to keep control over that "myself".

So .. I hereby send you patches to replace EMemChunk with g_slice_* in
camel-object.c and camel-folder-summary.c/h. I added the evolution
patches mailing list in CC which means that Novell is allowed (by the
contract that I signed with them) to transfer the copyright.

The camel-folder-summary.c/h might not immediately apply on your version
because the offsets in the diff will differ between your and my version.
That file has indeed been changed intensively by the mmap patch that is
of course applied to my version (and probably not yet to yours).

But feel free to try (I'm guessing that with the extra lines of the
unified diff format, it will automatically find most of the locations)
and if you need assistance, just ask.



-- 
Philip Van Hoof, software developer
home: me at pvanhoof dot be
gnome: pvanhoof at gnome dot org
work: vanhoof at x-tend dot be
blog: http://pvanhoof.be/blog
--- /home/pvanhoof/repos/gnome/cvs/evolution-data-server/camel/camel-object.c	2006-08-28 19:24:59.000000000 +0200
+++ camel-object.c	2006-10-18 13:43:24.000000000 +0200
@@ -52,7 +52,7 @@
 
 /* A 'locked' hooklist, that is only allocated on demand */
 typedef struct _CamelHookList {
-	EMutex *lock;
+	GStaticRecMutex lock;
 
 	unsigned int depth:30;	/* recursive event depth */
 	unsigned int flags:2;	/* flags, see below */
@@ -125,7 +125,8 @@
 static void camel_object_free_hooks(CamelObject *o);
 static void camel_object_bag_remove_unlocked(CamelObjectBag *inbag, CamelObject *o, CamelHookList *hooks);
 
-#define camel_object_unget_hooks(o) (e_mutex_unlock((CAMEL_OBJECT(o)->hooks->lock)))
+#define camel_object_unget_hooks(o) \
+	(g_static_rec_mutex_unlock(&CAMEL_OBJECT(o)->hooks->lock))
 
 
 /* ********************************************************************** */
@@ -137,12 +138,11 @@
 static unsigned int pair_id = 1;
 
 /* type-lock must be recursive, for atomically creating classes */
-static EMutex *type_lock;
+static GStaticRecMutex type_lock = G_STATIC_REC_MUTEX_INIT;
 /* ref-lock must be global :-(  for object bags to work */
 static GMutex *ref_lock;
 
 static GHashTable *type_table;
-static EMemChunk *type_chunks;
 
 /* fundamental types are accessed via global */
 CamelType camel_object_type;
@@ -150,12 +150,12 @@
 
 #define P_LOCK(l) (pthread_mutex_lock(&l))
 #define P_UNLOCK(l) (pthread_mutex_unlock(&l))
-#define E_LOCK(l) (e_mutex_lock(l))
-#define E_UNLOCK(l) (e_mutex_unlock(l))
 #define CLASS_LOCK(k) (g_mutex_lock((((CamelObjectClass *)k)->lock)))
 #define CLASS_UNLOCK(k) (g_mutex_unlock((((CamelObjectClass *)k)->lock)))
 #define REF_LOCK() (g_mutex_lock(ref_lock))
 #define REF_UNLOCK() (g_mutex_unlock(ref_lock))
+#define TYPE_LOCK() (g_static_rec_mutex_lock(&type_lock))
+#define TYPE_UNLOCK() (g_static_rec_mutex_unlock(&type_lock))
 
 static struct _CamelHookPair *
 pair_alloc(void)
@@ -163,7 +163,7 @@
 	CamelHookPair *pair;
 
 	P_LOCK(chunks_lock);
-	pair = e_memchunk_alloc(pair_chunks);
+	pair = g_slice_new (CamelHookPair);
 	pair->id = pair_id++;
 	if (pair_id == 0)
 		pair_id = 1;
@@ -175,10 +175,8 @@
 static void
 pair_free(CamelHookPair *pair)
 {
-	g_assert(pair_chunks != NULL);
-
 	P_LOCK(chunks_lock);
-	e_memchunk_free(pair_chunks, pair);
+	g_slice_free (CamelHookPair, pair);
 	P_UNLOCK(chunks_lock);
 }
 
@@ -188,7 +186,7 @@
 	CamelHookList *hooks;
 
 	P_LOCK(chunks_lock);
-	hooks = e_memchunk_alloc(hook_chunks);
+	hooks = g_slice_new (CamelHookList);
 	P_UNLOCK(chunks_lock);
 
 	return hooks;
@@ -197,10 +195,8 @@
 static void
 hooks_free(CamelHookList *hooks)
 {
-	g_assert(hook_chunks != NULL);
-
 	P_LOCK(chunks_lock);
-	e_memchunk_free(hook_chunks, hooks);
+	g_slice_free (CamelHookList, hooks);
 	P_UNLOCK(chunks_lock);
 }
 
@@ -214,10 +210,6 @@
 		return;
 
 	init = TRUE;
-	pair_chunks = e_memchunk_new(16, sizeof(CamelHookPair));
-	hook_chunks = e_memchunk_new(16, sizeof(CamelHookList));
-	type_lock = e_mutex_new(E_MUTEX_REC);
-	type_chunks = e_memchunk_new(32, sizeof(CamelType));
 	type_table = g_hash_table_new(NULL, NULL);
 	ref_lock = g_mutex_new();
 }
@@ -471,7 +463,7 @@
 			switch(argv->argv[argv->argc].tag & CAMEL_ARG_TYPE) {
 			case CAMEL_ARG_INT:
 			case CAMEL_ARG_BOO:
-				if (camel_file_util_decode_uint32(fp, &argv->argv[argv->argc].ca_int) == -1)
+				if (camel_file_util_decode_uint32(fp, (guint32*) &argv->argv[argv->argc].ca_int) == -1)
 					goto cleanup;
 				break;
 			case CAMEL_ARG_STR:
@@ -580,7 +572,7 @@
 
 	res = 0;
 abort:
-	for (i=0;i<argv->argc;i++) {
+/*	for (i=0;i<argv->argc;i++) {
 		CamelArg *arg = &argv->argv[i];
 
 		if ((argv->argv[i].tag & CAMEL_ARG_TYPE) == CAMEL_ARG_STR)
@@ -595,7 +587,7 @@
 
 	if (meta)
 		camel_object_free(obj, CAMEL_OBJECT_METADATA, meta);
-
+*/
 	return res;
 }
 
@@ -723,7 +715,7 @@
 	/*int offset;
 	  size_t size;*/
 
-	E_LOCK(type_lock);
+	TYPE_LOCK();
 
 	/* Have to check creation, it might've happened in another thread before we got here */
 	klass = g_hash_table_lookup(type_table, name);
@@ -734,7 +726,7 @@
 			g_warning("camel_type_register: Trying to re-register class '%s'", name);
 			klass = NULL;
 		}
-		E_UNLOCK(type_lock);
+		TYPE_UNLOCK();
 		return klass;
 	}
 
@@ -758,16 +750,16 @@
 	if (parent
 	    && klass_size < parent->klass_size) {
 		g_warning("camel_type_register: '%s' has smaller class size than parent '%s'", name, parent->name);
-		E_UNLOCK(type_lock);
+		TYPE_UNLOCK();
 		return NULL;
 	}
 
-	klass = g_malloc0(klass_size);
+	klass = g_slice_alloc (klass_size);
 	klass->klass_size = klass_size;
 	klass->object_size = object_size;
 	klass->lock = g_mutex_new();
-	klass->instance_chunks = e_memchunk_new(8, object_size);
-	
+	klass->hooks = NULL;
+
 	klass->parent = parent;
 	if (parent) {
 		klass->next = parent->child;
@@ -789,7 +781,7 @@
 
 	camel_type_class_init(klass, klass);
 
-	E_UNLOCK(type_lock);
+	TYPE_UNLOCK();
 
 	return klass;
 }
@@ -848,15 +840,7 @@
 
 	CLASS_LOCK(type);
 
-	o = e_memchunk_alloc0(type->instance_chunks);
-
-#ifdef CAMEL_OBJECT_TRACK_INSTANCES
-	if (type->instances)
-		type->instances->prev = o;
-	o->next = type->instances;
-	o->prev = NULL;
-	type->instances = o;
-#endif
+	o = g_slice_alloc0 (type->object_size);
 
 	CLASS_UNLOCK(type);
 
@@ -890,7 +874,6 @@
 	CamelHookList *hooks = NULL;
 
 	g_return_if_fail(CAMEL_IS_OBJECT(o));
-	
 	klass = o->klass;
 
 	if (o->hooks)
@@ -932,15 +915,8 @@
 	o->magic = CAMEL_OBJECT_FINALISED_MAGIC;
 
 	CLASS_LOCK(klass);
-#ifdef CAMEL_OBJECT_TRACK_INSTANCES
-	if (o->prev)
-		o->prev->next = o->next;
-	else
-		klass->instances = o->next;
-	if (o->next)
-		o->next->prev = o->prev;
-#endif
-	e_memchunk_free(klass->instance_chunks, o);
+
+	g_slice_free1 (klass->object_size, o);
 	CLASS_UNLOCK(klass);
 }
 
@@ -1254,7 +1230,7 @@
 			pair_free(pair);
 			pair = next;
 		}
-		e_mutex_destroy(o->hooks->lock);
+		g_static_rec_mutex_free(&o->hooks->lock);
 		hooks_free(o->hooks);
 		o->hooks = NULL;
 	}
@@ -1273,7 +1249,7 @@
 		pthread_mutex_lock(&lock);
 		if (o->hooks == NULL) {
 			hooks = hooks_alloc();
-			hooks->lock = e_mutex_new(E_MUTEX_REC);
+			g_static_rec_mutex_init(&hooks->lock);
 			hooks->flags = 0;
 			hooks->depth = 0;
 			hooks->list_length = 0;
@@ -1283,7 +1259,7 @@
 		pthread_mutex_unlock(&lock);
 	}
 	
-	e_mutex_lock(o->hooks->lock);
+	g_static_rec_mutex_lock(&o->hooks->lock);
 	
 	return o->hooks;	
 }
@@ -1896,9 +1872,6 @@
 object_class_dump_tree_rec(CamelType root, int depth)
 {
 	char *p;
-#ifdef CAMEL_OBJECT_TRACK_INSTANCES
-	struct _CamelObject *o;
-#endif
 
 	p = alloca(depth*2+1);
 	memset(p, ' ', depth*2);
@@ -1916,22 +1889,7 @@
 				pair = pair->next;
 			}
 		}
-#ifdef CAMEL_OBJECT_TRACK_INSTANCES
-		o = root->instances;
-		while (o) {
-			printf("%s instance %p [%d]\n", p, o, o->ref_count);
-			/* todo: should lock hooks while it scans them */
-			if (o->hooks) {
-				CamelHookPair *pair = o->hooks->list;
-
-				while (pair) {
-					printf("%s  hook '%s' func %p data %p\n", p, pair->name, pair->func.event, pair->data);
-					pair = pair->next;
-				}
-			}
-			o = o->next;
-		}
-#endif
+
 		CLASS_UNLOCK(root);
 
 		if (root->child)
Index: camel-folder-summary.h
===================================================================
--- camel-folder-summary.h	(revision 1034)
+++ camel-folder-summary.h	(working copy)
@@ -224,7 +224,6 @@
 	guint32 content_info_size;
 
 	/* memory allocators (setup automatically) */
-	struct _EMemChunk *message_info_chunks;
 	struct _EMemChunk *content_info_chunks;
 
 	char *summary_path;
Index: camel-folder-summary.h
===================================================================
--- camel-folder-summary.h	(revision 1033)
+++ camel-folder-summary.h	(working copy)
@@ -224,7 +224,6 @@
 	guint32 content_info_size;
 
 	/* memory allocators (setup automatically) */
-	struct _EMemChunk *message_info_chunks;
 	struct _EMemChunk *content_info_chunks;
 
 	char *summary_path;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]