[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59171] trunk/blender/source/blender/ blenlib: add support for mempool/linklist functions.

Campbell Barton ideasman42 at gmail.com
Fri Aug 16 07:50:00 CEST 2013


Revision: 59171
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59171
Author:   campbellbarton
Date:     2013-08-16 05:50:00 +0000 (Fri, 16 Aug 2013)
Log Message:
-----------
add support for mempool/linklist functions.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_linklist.h
    trunk/blender/source/blender/blenlib/intern/BLI_linklist.c

Modified: trunk/blender/source/blender/blenlib/BLI_linklist.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_linklist.h	2013-08-16 05:21:40 UTC (rev 59170)
+++ trunk/blender/source/blender/blenlib/BLI_linklist.h	2013-08-16 05:50:00 UTC (rev 59171)
@@ -36,6 +36,7 @@
  */
 
 struct MemArena;
+struct BLI_mempool;
 
 typedef void (*LinkNodeFreeFP)(void *link);
 typedef void (*LinkNodeApplyFP)(void *link, void *userdata);
@@ -56,10 +57,14 @@
 void    BLI_linklist_prepend(struct LinkNode **listp, void *ptr);
 void    BLI_linklist_append(struct LinkNode **listp, void *ptr);
 void    BLI_linklist_prepend_arena(struct LinkNode **listp, void *ptr, struct MemArena *ma);
+void    BLI_linklist_prepend_pool(struct LinkNode **listp, void *ptr, struct BLI_mempool *mempool);
+void   *BLI_linklist_pop(struct LinkNode **listp);
+void   *BLI_linklist_pop_pool(struct LinkNode **listp, struct BLI_mempool *mempool);
 void    BLI_linklist_insert_after(struct LinkNode **listp, void *ptr);
 
 void    BLI_linklist_free(struct LinkNode *list, LinkNodeFreeFP freefunc);
 void    BLI_linklist_freeN(struct LinkNode *list);
+void    BLI_linklist_free_pool(LinkNode *list, LinkNodeFreeFP freefunc, struct BLI_mempool *mempool);
 void    BLI_linklist_apply(struct LinkNode *list, LinkNodeApplyFP applyfunc, void *userdata);
 
 #endif

Modified: trunk/blender/source/blender/blenlib/intern/BLI_linklist.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/BLI_linklist.c	2013-08-16 05:21:40 UTC (rev 59170)
+++ trunk/blender/source/blender/blenlib/intern/BLI_linklist.c	2013-08-16 05:50:00 UTC (rev 59171)
@@ -34,6 +34,7 @@
 #include "MEM_guardedalloc.h"
 #include "BLI_linklist.h"
 #include "BLI_memarena.h"
+#include "BLI_mempool.h"
 
 int BLI_linklist_length(LinkNode *list)
 {
@@ -125,6 +126,39 @@
 	*listp = nlink;
 }
 
+void BLI_linklist_prepend_pool(LinkNode **listp, void *ptr, BLI_mempool *mempool)
+{
+	LinkNode *nlink = BLI_mempool_alloc(mempool);
+	nlink->link = ptr;
+
+	nlink->next = *listp;
+	*listp = nlink;
+}
+
+void *BLI_linklist_pop(struct LinkNode **listp)
+{
+	/* intentionally no NULL check */
+	void *link = (*listp)->link;
+	void *next = (*listp)->next;
+
+	MEM_freeN((*listp));
+
+	*listp = next;
+	return link;
+}
+
+void *BLI_linklist_pop_pool(struct LinkNode **listp, struct BLI_mempool *mempool)
+{
+	/* intentionally no NULL check */
+	void *link = (*listp)->link;
+	void *next = (*listp)->next;
+
+	BLI_mempool_free(mempool, (*listp));
+
+	*listp = next;
+	return link;
+}
+
 void BLI_linklist_insert_after(LinkNode **listp, void *ptr)
 {
 	LinkNode *nlink = MEM_mallocN(sizeof(*nlink), "nlink");
@@ -155,6 +189,19 @@
 	}
 }
 
+void BLI_linklist_free_pool(LinkNode *list, LinkNodeFreeFP freefunc, struct BLI_mempool *mempool)
+{
+	while (list) {
+		LinkNode *next = list->next;
+
+		if (freefunc)
+			freefunc(list->link);
+		BLI_mempool_free(mempool, list);
+
+		list = next;
+	}
+}
+
 void BLI_linklist_freeN(LinkNode *list)
 {
 	while (list) {




More information about the Bf-blender-cvs mailing list