BLOG | DOCUMENTATION | TRAC

Home --> Documentations --> PJLIB Reference

pool.h
Go to the documentation of this file.
1 /* $Id$ */
2 /*
3  * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4  * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 #include <pj/list.h>
22 
23 /* See if we use pool's alternate API.
24  * The alternate API is used e.g. to implement pool debugging.
25  */
26 #if PJ_HAS_POOL_ALT_API
27 # include <pj/pool_alt.h>
28 #endif
29 
30 
31 #ifndef __PJ_POOL_H__
32 #define __PJ_POOL_H__
33 
40 
291 typedef void pj_pool_callback(pj_pool_t *pool, pj_size_t size);
292 
297 typedef struct pj_pool_block
298 {
300  unsigned char *buf;
301  unsigned char *cur;
302  unsigned char *end;
303 } pj_pool_block;
304 
305 
310 struct pj_pool_t
311 {
316 
319 
322 
325 
328 
331 
334 
335 };
336 
337 
341 #define PJ_POOL_SIZE (sizeof(struct pj_pool_t))
342 
346 #ifndef PJ_POOL_ALIGNMENT
347 # define PJ_POOL_ALIGNMENT 4
348 #endif
349 
378  const char *name,
379  pj_size_t initial_size,
380  pj_size_t increment_size,
381  pj_pool_callback *callback);
382 
388 PJ_IDECL(void) pj_pool_release( pj_pool_t *pool );
389 
390 
396 PJ_IDECL(void) pj_pool_safe_release( pj_pool_t **ppool );
397 
398 
405 PJ_IDECL(void) pj_pool_secure_release( pj_pool_t **ppool );
406 
407 
415 PJ_IDECL(const char *) pj_pool_getobjname( const pj_pool_t *pool );
416 
426 PJ_DECL(void) pj_pool_reset( pj_pool_t *pool );
427 
428 
440 
449 
462 PJ_IDECL(void*) pj_pool_alloc( pj_pool_t *pool, pj_size_t size);
463 
475 PJ_IDECL(void*) pj_pool_calloc( pj_pool_t *pool, pj_size_t count,
476  pj_size_t elem);
477 
478 
490 {
491  return pj_pool_calloc(pool, 1, size);
492 }
493 
494 
506 #define PJ_POOL_ALLOC_T(pool,type) \
507  ((type*)pj_pool_alloc(pool, sizeof(type)))
508 
520 #define PJ_POOL_ZALLOC_T(pool,type) \
521  ((type*)pj_pool_zalloc(pool, sizeof(type)))
522 
523 /*
524  * Internal functions
525  */
526 PJ_IDECL(void*) pj_pool_alloc_from_block(pj_pool_block *block, pj_size_t size);
527 PJ_DECL(void*) pj_pool_allocate_find(pj_pool_t *pool, pj_size_t size);
528 
529 
530 
535 /* **************************************************************************/
584 /* We unfortunately don't have support for factory policy options as now,
585  so we keep this commented at the moment.
586 enum PJ_POOL_FACTORY_OPTION
587 {
588  PJ_POOL_FACTORY_SERIALIZE = 1
589 };
590 */
591 
596 {
606  void* (*block_alloc)(pj_pool_factory *factory, pj_size_t size);
607 
615  void (*block_free)(pj_pool_factory *factory, void *mem, pj_size_t size);
616 
621 
625  unsigned flags;
626 
628 
636 PJ_DECL_DATA(int) PJ_NO_MEMORY_EXCEPTION;
637 
641 PJ_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 
754 PJ_DECL(pj_pool_t*) pj_pool_create_int( pj_pool_factory *factory,
755  const char *name,
756  pj_size_t initial_size,
757  pj_size_t increment_size,
758  pj_pool_callback *callback);
759 
767 PJ_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 
776 PJ_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 
895 PJ_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 
905 PJ_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 
pj_size_t used_size
Definition: pool.h:853
size_t pj_size_t
Definition: types.h:58
void(* block_free)(pj_pool_factory *factory, void *mem, pj_size_t size)
Definition: pool.h:615
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)
int pj_bool_t
Definition: types.h:71
int PJ_NO_MEMORY_EXCEPTION
Definition: pool.h:636
#define PJ_CACHING_POOL_ARRAY_SIZE
Definition: pool.h:815
pj_size_t capacity
Definition: pool.h:834
pj_pool_factory_policy pj_pool_factory_default_policy
Definition: pool.h:652
typedef int(PJ_THREAD_FUNC pj_thread_proc)(void *)
void * pj_pool_calloc(pj_pool_t *pool, pj_size_t count, pj_size_t elem)
void(* release_pool)(pj_pool_factory *factory, pj_pool_t *pool)
Definition: pool.h:709
pj_pool_callback * callback
Definition: pool.h:333
int pj_rand(void)
unsigned char * buf
Definition: pool.h:300
#define PJ_BEGIN_DECL
Definition: config.h:1244
PJ_BEGIN_DECL pj_pool_t * pj_pool_create_on_buf(const char *name, void *buf, pj_size_t size)
Definition: pool.h:310
void(* on_block_free)(pj_pool_factory *factory, pj_size_t size)
Definition: pool.h:741
void pj_caching_pool_init(pj_caching_pool *ch_pool, const pj_pool_factory_policy *policy, pj_size_t max_capacity)
pj_pool_callback * callback
Definition: pool.h:620
Linked List data structure.
#define PJ_POOL_SIZE
Definition: pool.h:341
void pj_pool_release(pj_pool_t *pool)
#define PJ_MAX_OBJ_NAME
Definition: types.h:286
char pool_buf[256 *(sizeof(size_t)/4)]
Definition: pool.h:874
Logging Utility.
pj_size_t pj_pool_get_used_size(pj_pool_t *pool)
void * pj_pool_alloc(pj_pool_t *pool, pj_size_t size)
#define PJ_TRY
Definition: except.h:374
struct pj_lock_t pj_lock_t
Definition: types.h:239
Memory Pool.
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(void)
#define PJ_UNUSED_ARG(arg)
Definition: config.h:1303
void(* dump_status)(pj_pool_factory *factory, pj_bool_t detail)
Definition: pool.h:716
pj_size_t peak_used_size
Definition: pool.h:859
Exception Handling in C.
Definition: pool.h:823
void pj_pool_destroy_int(pj_pool_t *pool)
void pj_pool_reset(pj_pool_t *pool)
pj_list used_list
Definition: pool.h:869
pj_pool_factory factory
Definition: pool.h:826
pj_size_t capacity
Definition: pool.h:324
PJ_DECL_LIST_MEMBER(struct pj_pool_t)
void pj_pool_secure_release(pj_pool_t **ppool)
unsigned char * cur
Definition: pool.h:301
unsigned char * end
Definition: pool.h:302
#define PJ_LOG(level, arg)
Definition: log.h:107
Definition: pool.h:297
pj_size_t increment_size
Definition: pool.h:327
pj_size_t pj_pool_get_capacity(pj_pool_t *pool)
void pj_caching_pool_destroy(pj_caching_pool *ch_pool)
void pj_pool_safe_release(pj_pool_t **ppool)
void pj_pool_factory_dump(pj_pool_factory *pf, pj_bool_t detail)
Definition: pool.h:784
#define PJ_IDECL(type)
Definition: config.h:1293
pj_list free_list[16]
Definition: pool.h:864
const pj_pool_factory_policy * pj_pool_factory_get_default_policy(void)
#define PJ_POOL_ALIGNMENT
Definition: pool.h:347
pj_size_t max_capacity
Definition: pool.h:841
pj_lock_t * lock
Definition: pool.h:879
pj_pool_factory_policy policy
Definition: pool.h:671
void * pj_pool_zalloc(pj_pool_t *pool, pj_size_t size)
Definition: pool.h:489
pj_pool_block block_list
Definition: pool.h:330
Random Number Generator.
const char * pj_pool_getobjname(const pj_pool_t *pool)
void * factory_data
Definition: pool.h:321
pj_size_t used_count
Definition: pool.h:848
pj_bool_t(* on_block_alloc)(pj_pool_factory *factory, pj_size_t size)
Definition: pool.h:730
Definition: pool.h:666
#define PJ_USE_EXCEPTION
Definition: except.h:368
#define PJ_INLINE(type)
Definition: config.h:1138
#define PJ_END
Definition: except.h:395
#define PJ_CATCH_ANY
Definition: except.h:389
PJ_DECL_LIST_MEMBER(struct pj_pool_block)
char obj_name[PJ_MAX_OBJ_NAME]
Definition: pool.h:315
#define PJ_END_DECL
Definition: config.h:1245
pj_pool_factory * factory
Definition: pool.h:318
void pj_pool_callback(pj_pool_t *pool, pj_size_t size)
Definition: pool.h:291
void pj_pool_init_int(pj_pool_t *pool, const char *name, pj_size_t increment_size, pj_pool_callback *callback)
Definition: pool.h:595
unsigned flags
Definition: pool.h:625
Definition: list.h:74

 


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