]> git.proxmox.com Git - libgit2.git/blobdiff - src/pool.h
New upstream version 1.4.3+dfsg.1
[libgit2.git] / src / pool.h
index 1cae48fd3be92182b9b0e300f5253c07b7293523..cecb84665fffb963c1481cc2fa0d4d6912d7ccee 100644 (file)
@@ -8,6 +8,7 @@
 #define INCLUDE_pool_h__
 
 #include "common.h"
+
 #include "vector.h"
 
 typedef struct git_pool_page git_pool_page;
@@ -31,10 +32,12 @@ typedef struct git_pool_page git_pool_page;
  */
 typedef struct {
        git_pool_page *pages; /* allocated pages */
-       uint32_t item_size;  /* size of single alloc unit in bytes */
-       uint32_t page_size;  /* size of page in bytes */
+       size_t item_size;  /* size of single alloc unit in bytes */
+       size_t page_size;  /* size of page in bytes */
 } git_pool;
 
+#define GIT_POOL_INIT { NULL, 0, 0 }
+
 #else
 
 /**
@@ -54,9 +57,12 @@ typedef struct {
  */
 typedef struct {
        git_vector allocations;
-       uint32_t item_size;
-       uint32_t page_size;
+       size_t item_size;
+       size_t page_size;
 } git_pool;
+
+#define GIT_POOL_INIT { GIT_VECTOR_INIT, 0, 0 }
+
 #endif
 
 /**
@@ -75,7 +81,7 @@ typedef struct {
  * Of course, you can use this in other ways, but those are the
  * two most common patterns.
  */
-extern void git_pool_init(git_pool *pool, uint32_t item_size);
+extern int git_pool_init(git_pool *pool, size_t item_size);
 
 /**
  * Free all items in pool
@@ -90,8 +96,8 @@ extern void git_pool_swap(git_pool *a, git_pool *b);
 /**
  * Allocate space for one or more items from a pool.
  */
-extern void *git_pool_malloc(git_pool *pool, uint32_t items);
-extern void *git_pool_mallocz(git_pool *pool, uint32_t items);
+extern void *git_pool_malloc(git_pool *pool, size_t items);
+extern void *git_pool_mallocz(git_pool *pool, size_t items);
 
 /**
  * Allocate space and duplicate string data into it.
@@ -124,9 +130,17 @@ extern char *git_pool_strcat(git_pool *pool, const char *a, const char *b);
 /*
  * Misc utilities
  */
-#ifndef _DEBUG_POOL
+#ifndef GIT_DEBUG_POOL
 extern uint32_t git_pool__open_pages(git_pool *pool);
 #endif
 extern bool git_pool__ptr_in_pool(git_pool *pool, void *ptr);
 
+/**
+ * This function is being called by our global setup routines to
+ * initialize the system pool size.
+ *
+ * @return 0 on success, <0 on failure
+ */
+extern int git_pool_global_init(void);
+
 #endif