Jabber WindowGram Client (JWGC)

Introduction Screenshots Installation Downloads
Documentation Browse Source Resources Project Site

Stable Version
-none-

Latest Version
beta5



Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

pool.c File Reference

#include "libxode.h"
#include "config.h"

Go to the source code of this file.

Data Structures

struct  xode_pool_free

Defines

#define _xode_pool__malloc   malloc
#define _xode_pool__free   free

Functions

xode_pool _xode_pool_new (void)
void _xode_pool_heapfree (void *arg)
void _xode_pool_cleanup_append (xode_pool p, struct xode_pool_free *pf)
xode_pool_free_xode_pool_free (xode_pool p, xode_pool_cleaner f, void *arg)
xode_pool_heap_xode_pool_heap (xode_pool p, int size)
xode_pool _xode_pool_newheap (int bytes)
void * xode_pool_malloc (xode_pool p, int size)
void * xode_pool_mallocx (xode_pool p, int size, char c)
void * xode_pool_malloco (xode_pool p, int size)
char * xode_pool_strdup (xode_pool p, const char *src)
char * xode_pool_strdupx (xode_pool p, const char *src)
int xode_pool_size (xode_pool p)
void xode_pool_free (xode_pool p)
void xode_pool_cleanup (xode_pool p, xode_pool_cleaner f, void *arg)
xode_pool xode_pool_new (void)
xode_pool xode_pool_heap (const int bytes)


Define Documentation

#define _xode_pool__free   free
 

Definition at line 44 of file pool.c.

Referenced by _xode_pool_heapfree(), xode_pool_free(), and xode_pool_malloc().

#define _xode_pool__malloc   malloc
 

Definition at line 43 of file pool.c.

Referenced by _xode_pool_free(), _xode_pool_heap(), _xode_pool_new(), and xode_pool_malloc().


Function Documentation

void _xode_pool_cleanup_append xode_pool  p,
struct xode_pool_free pf
 

Definition at line 78 of file pool.c.

References xode_pool_struct::cleanup, xode_pool_free::next, and xode_pool.

Referenced by _xode_pool_heap(), and xode_pool_malloc().

00079 {
00080     struct xode_pool_free *cur;
00081 
00082     if(p->cleanup == NULL)
00083     {
00084         p->cleanup = pf;
00085         return;
00086     }
00087 
00088     /* fast forward to end of list */
00089     for(cur = p->cleanup; cur->next != NULL; cur = cur->next);
00090 
00091     cur->next = pf;
00092 }

struct xode_pool_free* _xode_pool_free xode_pool  p,
xode_pool_cleaner  f,
void *  arg
 

Definition at line 95 of file pool.c.

References _xode_pool__malloc, xode_pool_free::arg, xode_pool_free::f, xode_pool_free::next, and xode_pool.

Referenced by _xode_pool_heap(), xode_pool_cleanup(), and xode_pool_malloc().

00096 {
00097     struct xode_pool_free *ret;
00098 
00099     /* make the storage for the tracker */
00100     while((ret = _xode_pool__malloc(sizeof(struct xode_pool_free))) == NULL) sleep(1);
00101     ret->f = f;
00102     ret->arg = arg;
00103     ret->next = NULL;
00104 
00105     return ret;
00106 }

struct xode_pool_heap* _xode_pool_heap xode_pool  p,
int  size
 

Definition at line 109 of file pool.c.

References _xode_pool__malloc, _xode_pool_cleanup_append(), _xode_pool_free(), _xode_pool_heapfree(), xode_pool_heap::block, xode_pool_free::heap, xode_pool_struct::size, xode_pool_heap::size, xode_pool_heap::used, and xode_pool.

Referenced by _xode_pool_newheap(), and xode_pool_malloc().

00110 {
00111     struct xode_pool_heap *ret;
00112     struct xode_pool_free *clean;
00113 
00114     /* make the return heap */
00115     while((ret = _xode_pool__malloc(sizeof(struct xode_pool_heap))) == NULL) sleep(1);
00116     while((ret->block = _xode_pool__malloc(size)) == NULL) sleep(1);
00117     ret->size = size;
00118     p->size += size;
00119     ret->used = 0;
00120 
00121     /* append to the cleanup list */
00122     clean = _xode_pool_free(p, _xode_pool_heapfree, (void *)ret);
00123     clean->heap = ret; /* for future use in finding used mem for pstrdup */
00124     _xode_pool_cleanup_append(p, clean);
00125 
00126     return ret;
00127 }

void _xode_pool_heapfree void *  arg  ) 
 

Definition at line 69 of file pool.c.

References _xode_pool__free, and xode_pool_heap::block.

Referenced by _xode_pool_heap().

00070 {
00071     struct xode_pool_heap *h = (struct xode_pool_heap *)arg;
00072 
00073     _xode_pool__free(h->block);
00074     _xode_pool__free(h);
00075 }

xode_pool _xode_pool_new void   ) 
 

Definition at line 57 of file pool.c.

References _xode_pool, _xode_pool__malloc, xode_pool_struct::cleanup, xode_pool_struct::heap, xode_pool_struct::size, and xode_pool.

Referenced by _xode_pool_newheap(), and xode_pool_new().

00058 {
00059     xode_pool p;
00060     while((p = _xode_pool__malloc(sizeof(_xode_pool))) == NULL) sleep(1);
00061     p->cleanup = NULL;
00062     p->heap = NULL;
00063     p->size = 0;
00064 
00065     return p;
00066 }

xode_pool _xode_pool_newheap int  bytes  ) 
 

Definition at line 129 of file pool.c.

References _xode_pool_heap(), _xode_pool_new(), xode_pool_struct::heap, and xode_pool.

Referenced by xode_pool_heap().

00130 {
00131     xode_pool p;
00132     p = _xode_pool_new();
00133     p->heap = _xode_pool_heap(p,bytes);
00134     return p;
00135 }

void xode_pool_cleanup xode_pool  p,
xode_pool_cleaner  f,
void *  arg
 

Definition at line 232 of file pool.c.

References _xode_pool_free(), xode_pool_struct::cleanup, xode_pool_free::next, and xode_pool.

Referenced by xode_stream_new().

00233 {
00234     struct xode_pool_free *clean;
00235 
00236     clean = _xode_pool_free(p, f, arg);
00237     clean->next = p->cleanup;
00238     p->cleanup = clean;
00239 }

void xode_pool_free xode_pool  p  ) 
 

Definition at line 213 of file pool.c.

References _xode_pool__free, xode_pool_free::arg, xode_pool_struct::cleanup, xode_pool_free::f, xode_pool_free::next, and xode_pool.

Referenced by jab_delete(), jid_nodescan(), jwg_delete(), xode_free(), and xode_spool_free().

00214 {
00215     struct xode_pool_free *cur, *stub;
00216 
00217     if(p == NULL) return;
00218 
00219     cur = p->cleanup;
00220     while(cur != NULL)
00221     {
00222         (*cur->f)(cur->arg);
00223         stub = cur->next;
00224         _xode_pool__free(cur);
00225         cur = stub;
00226     }
00227 
00228     _xode_pool__free(p);
00229 }

xode_pool xode_pool_heap const int  bytes  ) 
 

Definition at line 246 of file pool.c.

References _xode_pool_newheap(), and xode_pool.

Referenced by xode_spool_new().

00247 {
00248     return _xode_pool_newheap(bytes);
00249 }

void* xode_pool_malloc xode_pool  p,
int  size
 

Definition at line 137 of file pool.c.

References _xode_pool__free, _xode_pool__malloc, _xode_pool_cleanup_append(), _xode_pool_free(), _xode_pool_heap(), xode_pool_heap::block, xode_pool_struct::heap, NULL, xode_pool_struct::size, xode_pool_heap::size, xode_pool_heap::used, and xode_pool.

Referenced by jab_auth(), jabpacket_new(), jwgpacket_new(), spool_print(), xode_insert_cdata(), xode_pool_malloco(), xode_pool_mallocx(), xode_pool_strdup(), xode_spool_add(), xode_spool_newfrompool(), xode_spool_tostr(), xode_strescape(), and xode_strunescape().

00138 {
00139     void *block;
00140 
00141     if(p == NULL)
00142     {
00143         fprintf(stderr,"Memory Leak! xode_pmalloc received NULL pool, unable to track allocation, exiting]\n");
00144         abort();
00145     }
00146 
00147     /* if there is no heap for this pool or it's a big request, just raw, I like how we clean this :) */
00148     if(p->heap == NULL || size > (p->heap->size / 2))
00149     {
00150         while((block = _xode_pool__malloc(size)) == NULL) sleep(1);
00151         p->size += size;
00152         _xode_pool_cleanup_append(p, _xode_pool_free(p, _xode_pool__free, block));
00153         return block;
00154     }
00155 
00156     /* we have to preserve boundaries, long story :) */
00157     if(size >= 4)
00158         while(p->heap->used&7) p->heap->used++;
00159 
00160     /* if we don't fit in the old heap, replace it */
00161     if(size > (p->heap->size - p->heap->used))
00162         p->heap = _xode_pool_heap(p, p->heap->size);
00163 
00164     /* the current heap has room */
00165     block = (char *)p->heap->block + p->heap->used;
00166     p->heap->used += size;
00167     return block;
00168 }

void* xode_pool_malloco xode_pool  p,
int  size
 

Definition at line 179 of file pool.c.

References xode_pool, and xode_pool_malloc().

Referenced by jid_new(), jid_user(), and xode_stream_new().

00180 {
00181     void *block = xode_pool_malloc(p, size);
00182     memset(block, 0, size);
00183     return block;
00184 }  

void* xode_pool_mallocx xode_pool  p,
int  size,
char  c
 

Definition at line 170 of file pool.c.

References xode_pool, and xode_pool_malloc().

Referenced by jab_new(), jwg_new(), and jwg_server().

00171 {
00172    void* result = xode_pool_malloc(p, size);
00173    if (result != NULL)
00174            memset(result, c, size);
00175    return result;
00176 }  

xode_pool xode_pool_new void   ) 
 

Definition at line 241 of file pool.c.

References _xode_pool_new(), and xode_pool.

Referenced by jab_new(), jid_nodescan(), jwg_new(), and jwg_server().

00242 {
00243     return _xode_pool_new();
00244 }

int xode_pool_size xode_pool  p  ) 
 

Definition at line 206 of file pool.c.

References xode_pool_struct::size, and xode_pool.

Referenced by xode_stream_eat().

00207 {
00208     if(p == NULL) return 0;
00209 
00210     return p->size;
00211 }

char* xode_pool_strdup xode_pool  p,
const char *  src
 

Definition at line 187 of file pool.c.

References xode_pool, and xode_pool_malloc().

Referenced by jab_new(), jid_new(), jid_set(), jid_xres(), xode_pool_strdupx(), xode_put_attrib(), and xode_spool_add().

00188 {
00189     char *ret;
00190 
00191     if(src == NULL)
00192         return NULL;
00193 
00194     ret = xode_pool_malloc(p,strlen(src) + 1);
00195     strcpy(ret,src);
00196 
00197     return ret;
00198 }

char* xode_pool_strdupx xode_pool  p,
const char *  src
 

Definition at line 201 of file pool.c.

References xode_pool, and xode_pool_strdup().

00202 {
00203     return xode_pool_strdup(p, src);
00204 }



Last updated at Tue Dec 18 21:07:42 PST 2007. This site and project hosted by...SourceForge.net Logo

Source Perspective by Fisheye