BLOG | DOCUMENTATION | GITHUB

Home --> Documentations --> PJLIB Reference

pool.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
3 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include <pj/list.h>
21
22/* See if we use pool's alternate API.
23 * The alternate API is used e.g. to implement pool debugging.
24 */
25#if PJ_HAS_POOL_ALT_API
26# include <pj/pool_alt.h>
27#endif
28
29
30#ifndef __PJ_POOL_H__
31#define __PJ_POOL_H__
32
39
290typedef void pj_pool_callback(pj_pool_t *pool, pj_size_t size);
291
296typedef struct pj_pool_block
297{
299 unsigned char *buf;
300 unsigned char *cur;
301 unsigned char *end;
303
304
310{
315
318
321
324
327
330
333
334};
335
336
340#define PJ_POOL_SIZE (sizeof(struct pj_pool_t))
341
345#ifndef PJ_POOL_ALIGNMENT
346# define PJ_POOL_ALIGNMENT 4
347#endif
348
377 const char *name,
378 pj_size_t initial_size,
379 pj_size_t increment_size,
380 pj_pool_callback *callback);
381
388
389
396
397
405
406
414PJ_IDECL(const char *) pj_pool_getobjname( const pj_pool_t *pool );
415
425PJ_DECL(void) pj_pool_reset( pj_pool_t *pool );
426
427
439
448
462
475 pj_size_t elem);
476
477
489{
490 return pj_pool_calloc(pool, 1, size);
491}
492
493
505#define PJ_POOL_ALLOC_T(pool,type) \
506 ((type*)pj_pool_alloc(pool, sizeof(type)))
507
519#define PJ_POOL_ZALLOC_T(pool,type) \
520 ((type*)pj_pool_zalloc(pool, sizeof(type)))
521
522/*
523 * Internal functions
524 */
528PJ_DECL(void*) pj_pool_allocate_find(pj_pool_t *pool, pj_size_t size);
529
530
531
536/* **************************************************************************/
585/* We unfortunately don't have support for factory policy options as now,
586 so we keep this commented at the moment.
587enum PJ_POOL_FACTORY_OPTION
588{
589 PJ_POOL_FACTORY_SERIALIZE = 1
590};
591*/
592
597{
607 void* (*block_alloc)(pj_pool_factory *factory, pj_size_t size);
608
616 void (*block_free)(pj_pool_factory *factory, void *mem, pj_size_t size);
617
622
626 unsigned flags;
627
629
636PJ_DECL_DATA(int) PJ_NO_MEMORY_EXCEPTION;
637
641PJ_DECL(int) pj_NO_MEMORY_EXCEPTION(void);
642
653
654
661
662
667{
672
697 pj_pool_t* (*create_pool)( pj_pool_factory *factory,
698 const char *name,
699 pj_size_t initial_size,
700 pj_size_t increment_size,
701 pj_pool_callback *callback);
702
709 void (*release_pool)( pj_pool_factory *factory, pj_pool_t *pool );
710
716 void (*dump_status)( pj_pool_factory *factory, pj_bool_t detail );
717
731
741 void (*on_block_free)(pj_pool_factory *factory, pj_size_t size);
742
743};
744
755 const char *name,
756 pj_size_t initial_size,
757 pj_size_t increment_size,
758 pj_pool_callback *callback);
759
767PJ_DECL(void) pj_pool_init_int( pj_pool_t *pool,
768 const char *name,
769 pj_size_t increment_size,
770 pj_pool_callback *callback);
771
776PJ_DECL(void) pj_pool_destroy_int( pj_pool_t *pool );
777
778
785 pj_bool_t detail )
786{
787 (*pf->dump_status)(pf, detail);
788}
789
794/* **************************************************************************/
795
815#define PJ_CACHING_POOL_ARRAY_SIZE 16
816
824{
827
835
842
849
854
860
865
870
874 char pool_buf[256 * (sizeof(size_t) / 4)];
875
880};
881
882
883
895PJ_DECL(void) pj_caching_pool_init( pj_caching_pool *ch_pool,
896 const pj_pool_factory_policy *policy,
897 pj_size_t max_capacity);
898
899
905PJ_DECL(void) pj_caching_pool_destroy( pj_caching_pool *ch_pool );
906
911# if PJ_FUNCTIONS_ARE_INLINED
912# include "pool_i.h"
913# endif
914
916
917#endif /* __PJ_POOL_H__ */
918
int pj_bool_t
Definition: types.h:71
struct pj_lock_t pj_lock_t
Definition: types.h:239
#define PJ_MAX_OBJ_NAME
Definition: types.h:286
size_t pj_size_t
Definition: types.h:58
void pj_caching_pool_destroy(pj_caching_pool *ch_pool)
#define PJ_CACHING_POOL_ARRAY_SIZE
Definition: pool.h:815
void pj_caching_pool_init(pj_caching_pool *ch_pool, const pj_pool_factory_policy *policy, pj_size_t max_capacity)
pj_pool_t * pj_pool_create_int(pj_pool_factory *factory, const char *name, pj_size_t initial_size, pj_size_t increment_size, pj_pool_callback *callback)
int PJ_NO_MEMORY_EXCEPTION
Definition: pool.h:636
pj_pool_factory_policy pj_pool_factory_default_policy
Definition: pool.h:652
void pj_pool_factory_dump(pj_pool_factory *pf, pj_bool_t detail)
Definition: pool.h:784
int pj_NO_MEMORY_EXCEPTION(void)
const pj_pool_factory_policy * pj_pool_factory_get_default_policy(void)
void pj_pool_destroy_int(pj_pool_t *pool)
void pj_pool_init_int(pj_pool_t *pool, const char *name, pj_size_t increment_size, pj_pool_callback *callback)
void * pj_pool_alloc(pj_pool_t *pool, pj_size_t size)
const char * pj_pool_getobjname(const pj_pool_t *pool)
void * pj_pool_alloc_from_block(pj_pool_block *block, pj_size_t size)
pj_size_t pj_pool_get_used_size(pj_pool_t *pool)
void pj_pool_secure_release(pj_pool_t **ppool)
pj_pool_t * pj_pool_create(pj_pool_factory *factory, const char *name, pj_size_t initial_size, pj_size_t increment_size, pj_pool_callback *callback)
void * pj_pool_calloc(pj_pool_t *pool, pj_size_t count, pj_size_t elem)
pj_size_t pj_pool_get_capacity(pj_pool_t *pool)
void * pj_pool_zalloc(pj_pool_t *pool, pj_size_t size)
Definition: pool.h:488
void pj_pool_reset(pj_pool_t *pool)
void * pj_pool_allocate_find(pj_pool_t *pool, pj_size_t size)
void pj_pool_safe_release(pj_pool_t **ppool)
void pj_pool_callback(pj_pool_t *pool, pj_size_t size)
Definition: pool.h:290
void pj_pool_release(pj_pool_t *pool)
#define PJ_BEGIN_DECL
Definition: config.h:1284
#define PJ_IDECL(type)
Definition: config.h:1333
#define PJ_INLINE(type)
Definition: config.h:1178
#define PJ_END_DECL
Definition: config.h:1285
Linked List data structure.
Definition: pool.h:824
pj_pool_factory factory
Definition: pool.h:826
pj_size_t peak_used_size
Definition: pool.h:859
pj_size_t max_capacity
Definition: pool.h:841
pj_size_t used_size
Definition: pool.h:853
char pool_buf[256 *(sizeof(size_t)/4)]
Definition: pool.h:874
pj_list used_list
Definition: pool.h:869
pj_lock_t * lock
Definition: pool.h:879
pj_size_t capacity
Definition: pool.h:834
pj_list free_list[16]
Definition: pool.h:864
pj_size_t used_count
Definition: pool.h:848
Definition: list.h:74
Definition: pool.h:297
unsigned char * end
Definition: pool.h:301
unsigned char * buf
Definition: pool.h:299
PJ_DECL_LIST_MEMBER(struct pj_pool_block)
unsigned char * cur
Definition: pool.h:300
Definition: pool.h:597
void(* block_free)(pj_pool_factory *factory, void *mem, pj_size_t size)
Definition: pool.h:616
unsigned flags
Definition: pool.h:626
pj_pool_callback * callback
Definition: pool.h:621
Definition: pool.h:667
void(* dump_status)(pj_pool_factory *factory, pj_bool_t detail)
Definition: pool.h:716
pj_pool_factory_policy policy
Definition: pool.h:671
void(* on_block_free)(pj_pool_factory *factory, pj_size_t size)
Definition: pool.h:741
void(* release_pool)(pj_pool_factory *factory, pj_pool_t *pool)
Definition: pool.h:709
pj_bool_t(* on_block_alloc)(pj_pool_factory *factory, pj_size_t size)
Definition: pool.h:730
Definition: pool.h:310
pj_pool_factory * factory
Definition: pool.h:317
PJ_DECL_LIST_MEMBER(struct pj_pool_t)
pj_size_t capacity
Definition: pool.h:323
void * factory_data
Definition: pool.h:320
pj_size_t increment_size
Definition: pool.h:326
char obj_name[PJ_MAX_OBJ_NAME]
Definition: pool.h:314
pj_pool_callback * callback
Definition: pool.h:332
pj_pool_block block_list
Definition: pool.h:329

 


PJLIB Open Source, high performance, small footprint, and very very portable framework
Copyright (C) 2006-2009 Teluu Inc.