[dovecot-cvs] dovecot/src/lib-index mail-index-view-private.h, 1.7, 1.8 mail-index-view-sync.c, 1.18, 1.19 mail-index-view.c, 1.18, 1.19

cras at dovecot.org cras at dovecot.org
Sat Sep 4 11:51:11 EEST 2004


Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv25137/lib-index

Modified Files:
	mail-index-view-private.h mail-index-view-sync.c 
	mail-index-view.c 
Log Message:
Refcounting fixes for index mappings.



Index: mail-index-view-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-view-private.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- mail-index-view-private.h	22 Jun 2004 07:36:33 -0000	1.7
+++ mail-index-view-private.h	4 Sep 2004 08:51:08 -0000	1.8
@@ -28,6 +28,7 @@
 	unsigned int indexid;
 	struct mail_index_map *map;
 	struct mail_index_map *new_map;
+	buffer_t *map_refs;
 
 	struct mail_index_header tmp_hdr_copy;
 	uint32_t messages_count; /* last synced one, map may be different */
@@ -49,6 +50,7 @@
 			   const struct mail_index_view *src);
 int mail_index_view_lock(struct mail_index_view *view);
 int mail_index_view_lock_head(struct mail_index_view *view, int update_index);
+void mail_index_view_unref_maps(struct mail_index_view *view);
 void mail_index_view_add_synced_transaction(struct mail_index_view *view,
 					    uint32_t log_file_seq,
 					    uoff_t log_file_offset);

Index: mail-index-view-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-view-sync.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- mail-index-view-sync.c	26 Jul 2004 18:52:07 -0000	1.18
+++ mail-index-view-sync.c	4 Sep 2004 08:51:08 -0000	1.19
@@ -140,6 +140,7 @@
 		view->map = map;
 	}
 
+	mail_index_view_unref_maps(view);
 	view->syncing = TRUE;
 
 	*ctx_r = ctx;

Index: mail-index-view.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-view.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- mail-index-view.c	24 Jun 2004 11:10:41 -0000	1.18
+++ mail-index-view.c	4 Sep 2004 08:51:08 -0000	1.19
@@ -31,6 +31,9 @@
 	if (view->log_syncs != NULL)
 		buffer_free(view->log_syncs);
 	mail_index_unmap(view->index, view->map);
+	mail_index_view_unref_maps(view);
+	if (view->map_refs != NULL)
+		buffer_free(view->map_refs);
 	i_free(view);
 }
 
@@ -140,6 +143,46 @@
 	view->transactions--;
 }
 
+static void mail_index_view_ref_map(struct mail_index_view *view,
+				    struct mail_index_map *map)
+{
+	const struct mail_index_map *const *maps;
+	size_t i, size;
+
+	if (view->map_refs != NULL) {
+		maps = buffer_get_data(view->map_refs, &size);
+		size /= sizeof(*maps);
+
+		for (i = 0; i < size; i++) {
+			if (maps[i] == map)
+				return;
+		}
+	} else {
+		view->map_refs =
+			buffer_create_dynamic(default_pool, 128, (size_t)-1);
+	}
+
+	map->refcount++;
+	buffer_append(view->map_refs, &map, sizeof(map));
+}
+
+void mail_index_view_unref_maps(struct mail_index_view *view)
+{
+	struct mail_index_map **maps;
+	size_t i, size;
+
+	if (view->map_refs == NULL)
+		return;
+
+	maps = buffer_get_modifyable_data(view->map_refs, &size);
+	size /= sizeof(*maps);
+
+	for (i = 0; i < size; i++)
+		mail_index_unmap(view->index, maps[i]);
+
+	buffer_set_used_size(view->map_refs, 0);
+}
+
 static uint32_t _view_get_message_count(struct mail_index_view *view)
 {
 	return view->messages_count;
@@ -189,13 +232,14 @@
 		return -1;
 
 	/* look for it in the head mapping */
-	*map_r = map = view->index->map;
+	map = view->index->map;
 
 	uid = rec->uid;
 	if (seq > view->index->hdr->messages_count)
 		seq = view->index->hdr->messages_count;
 
 	if (seq == 0) {
+		*map_r = view->map;
 		*rec_r = rec;
 		return 0;
 	}
@@ -209,9 +253,12 @@
 	} while (seq > 0);
 
 	if (n_rec->uid == uid) {
+		mail_index_view_ref_map(view, view->index->map);
+		*map_r = view->index->map;
 		*rec_r = n_rec;
 		return 1;
 	} else {
+		*map_r = view->map;
 		*rec_r = rec;
 		return 0;
 	}



More information about the dovecot-cvs mailing list