summaryrefslogtreecommitdiff
path: root/pjlib/include
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2008-07-12 09:31:34 +0000
committerBenny Prijono <bennylp@teluu.com>2008-07-12 09:31:34 +0000
commit132cbda37abce5fd5703f696ee8fb42cfd6fd41f (patch)
treeafa85b9470f660e5b0a18d9ec800602b7a58d754 /pjlib/include
parentc90da3b928fb3ee1b215abfb291a69bf2b78a3d8 (diff)
Ticket 559 (minor): Update the pool alternative API (pool_alt.h) with the latest pool API
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@2123 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib/include')
-rw-r--r--pjlib/include/pj/pool_alt.h69
1 files changed, 65 insertions, 4 deletions
diff --git a/pjlib/include/pj/pool_alt.h b/pjlib/include/pj/pool_alt.h
index 9091b854..fb923155 100644
--- a/pjlib/include/pj/pool_alt.h
+++ b/pjlib/include/pj/pool_alt.h
@@ -22,9 +22,6 @@
#define __PJ_POOL_H__
-typedef struct pj_pool_t pj_pool_t;
-
-
/**
* The type for function to receive callback from the pool when it is unable
* to allocate memory. The elegant way to handle this condition is to throw
@@ -33,6 +30,25 @@ typedef struct pj_pool_t pj_pool_t;
*/
typedef void pj_pool_callback(pj_pool_t *pool, pj_size_t size);
+struct pj_pool_mem
+{
+ struct pj_pool_mem *next;
+
+ /* data follows immediately */
+};
+
+
+typedef struct pj_pool_t
+{
+ struct pj_pool_mem *first_mem;
+ pj_pool_factory *factory;
+ char obj_name[32];
+ pj_size_t used_size;
+ pj_pool_callback *cb;
+} pj_pool_t;
+
+
+
/**
* This constant denotes the exception number that will be thrown by default
* memory factory policy when memory allocation fails.
@@ -105,8 +121,54 @@ PJ_DECL(void*) pj_pool_zalloc_imp(const char *file, int line,
pj_pool_t *pool, pj_size_t sz);
+#define PJ_POOL_ZALLOC_T(pool,type) \
+ ((type*)pj_pool_zalloc(pool, sizeof(type)))
+#define PJ_POOL_ALLOC_T(pool,type) \
+ ((type*)pj_pool_alloc(pool, sizeof(type)))
+#ifndef PJ_POOL_ALIGNMENT
+# define PJ_POOL_ALIGNMENT 4
+#endif
+
+/**
+ * This structure declares pool factory interface.
+ */
+typedef struct pj_pool_factory_policy
+{
+ /**
+ * Allocate memory block (for use by pool). This function is called
+ * by memory pool to allocate memory block.
+ *
+ * @param factory Pool factory.
+ * @param size The size of memory block to allocate.
+ *
+ * @return Memory block.
+ */
+ void* (*block_alloc)(pj_pool_factory *factory, pj_size_t size);
+
+ /**
+ * Free memory block.
+ *
+ * @param factory Pool factory.
+ * @param mem Memory block previously allocated by block_alloc().
+ * @param size The size of memory block.
+ */
+ void (*block_free)(pj_pool_factory *factory, void *mem, pj_size_t size);
+
+ /**
+ * Default callback to be called when memory allocation fails.
+ */
+ pj_pool_callback *callback;
+
+ /**
+ * Option flags.
+ */
+ unsigned flags;
+
+} pj_pool_factory_policy;
+
typedef struct pj_pool_factory
{
+ pj_pool_factory_policy policy;
int dummy;
} pj_pool_factory;
@@ -120,6 +182,5 @@ typedef struct pj_caching_pool
#define pj_caching_pool_destroy(cp)
#define pj_pool_factory_dump(pf, detail)
-
#endif /* __PJ_POOL_ALT_H__ */