BLOG | DOCUMENTATION | TRAC

Home --> Documentations --> PJLIB Reference

pool.h
Go to the documentation of this file.
1 /* $Id: pool.h 4537 2013-06-19 06:47:43Z riza $ */
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 
294 typedef void pj_pool_callback(pj_pool_t *pool, pj_size_t size);
295 
300 typedef struct pj_pool_block
301 {
303  unsigned char *buf;
304  unsigned char *cur;
305  unsigned char *end;
306 } pj_pool_block;
307 
308 
313 struct pj_pool_t
314 {
319 
322 
325 
328 
331 
334 
337 
338 };
339 
340 
344 #define PJ_POOL_SIZE (sizeof(struct pj_pool_t))
345 
349 #ifndef PJ_POOL_ALIGNMENT
350 # define PJ_POOL_ALIGNMENT 4
351 #endif
352 
381  const char *name,
382  pj_size_t initial_size,
383  pj_size_t increment_size,
384  pj_pool_callback *callback);
385 
391 PJ_IDECL(void) pj_pool_release( pj_pool_t *pool );
392 
400 PJ_IDECL(const char *) pj_pool_getobjname( const pj_pool_t *pool );
401 
411 PJ_DECL(void) pj_pool_reset( pj_pool_t *pool );
412 
413 
425 
434 
447 PJ_IDECL(void*) pj_pool_alloc( pj_pool_t *pool, pj_size_t size);
448 
460 PJ_IDECL(void*) pj_pool_calloc( pj_pool_t *pool, pj_size_t count,
461  pj_size_t elem);
462 
463 
475 {
476  return pj_pool_calloc(pool, 1, size);
477 }
478 
479 
491 #define PJ_POOL_ALLOC_T(pool,type) \
492  ((type*)pj_pool_alloc(pool, sizeof(type)))
493 
505 #define PJ_POOL_ZALLOC_T(pool,type) \
506  ((type*)pj_pool_zalloc(pool, sizeof(type)))
507 
508 /*
509  * Internal functions
510  */
511 PJ_IDECL(void*) pj_pool_alloc_from_block(pj_pool_block *block, pj_size_t size);
512 PJ_DECL(void*) pj_pool_allocate_find(pj_pool_t *pool, pj_size_t size);
513 
514 
515 
520 /* **************************************************************************/
569 /* We unfortunately don't have support for factory policy options as now,
570  so we keep this commented at the moment.
571 enum PJ_POOL_FACTORY_OPTION
572 {
573  PJ_POOL_FACTORY_SERIALIZE = 1
574 };
575 */
576 
581 {
591  void* (*block_alloc)(pj_pool_factory *factory, pj_size_t size);
592 
600  void (*block_free)(pj_pool_factory *factory, void *mem, pj_size_t size);
601 
606 
610  unsigned flags;
611 
613 
621 PJ_DECL_DATA(int) PJ_NO_MEMORY_EXCEPTION;
622 
626 PJ_DECL(int) pj_NO_MEMORY_EXCEPTION(void);
627 
638 
639 
646 
647 
652 {
657 
682  pj_pool_t* (*create_pool)( pj_pool_factory *factory,
683  const char *name,
684  pj_size_t initial_size,
685  pj_size_t increment_size,
686  pj_pool_callback *callback);
687 
694  void (*release_pool)( pj_pool_factory *factory, pj_pool_t *pool );
695 
701  void (*dump_status)( pj_pool_factory *factory, pj_bool_t detail );
702 
715  pj_bool_t (*on_block_alloc)(pj_pool_factory *factory, pj_size_t size);
716 
726  void (*on_block_free)(pj_pool_factory *factory, pj_size_t size);
727 
728 };
729 
739 PJ_DECL(pj_pool_t*) pj_pool_create_int( pj_pool_factory *factory,
740  const char *name,
741  pj_size_t initial_size,
742  pj_size_t increment_size,
743  pj_pool_callback *callback);
744 
752 PJ_DECL(void) pj_pool_init_int( pj_pool_t *pool,
753  const char *name,
754  pj_size_t increment_size,
755  pj_pool_callback *callback);
756 
761 PJ_DECL(void) pj_pool_destroy_int( pj_pool_t *pool );
762 
763 
770  pj_bool_t detail )
771 {
772  (*pf->dump_status)(pf, detail);
773 }
774 
779 /* **************************************************************************/
780 
800 #define PJ_CACHING_POOL_ARRAY_SIZE 16
801 
809 {
812 
820 
827 
834 
839 
845 
850 
855 
859  char pool_buf[256 * (sizeof(size_t) / 4)];
860 
865 };
866 
867 
868 
880 PJ_DECL(void) pj_caching_pool_init( pj_caching_pool *ch_pool,
881  const pj_pool_factory_policy *policy,
882  pj_size_t max_capacity);
883 
884 
890 PJ_DECL(void) pj_caching_pool_destroy( pj_caching_pool *ch_pool );
891 
896 # if PJ_FUNCTIONS_ARE_INLINED
897 # include "pool_i.h"
898 # endif
899 
901 
902 #endif /* __PJ_POOL_H__ */
903 
unsigned char * end
Definition: pool.h:305
const char * pj_pool_getobjname(const pj_pool_t *pool)
Definition: pool.h:808
pj_size_t capacity
Definition: pool.h:819
void pj_pool_release(pj_pool_t *pool)
int pj_bool_t
Definition: types.h:71
pj_size_t pj_pool_get_capacity(pj_pool_t *pool)
pj_pool_callback * callback
Definition: pool.h:336
pj_size_t pj_pool_get_used_size(pj_pool_t *pool)
pj_pool_factory_policy policy
Definition: pool.h:656
int pj_NO_MEMORY_EXCEPTION(void)
#define PJ_MAX_OBJ_NAME
Definition: types.h:289
pj_size_t used_count
Definition: pool.h:833
void pj_pool_reset(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)
Definition: pool.h:651
pj_pool_factory_policy pj_pool_factory_default_policy
Definition: pool.h:637
void * pj_pool_alloc(pj_pool_t *pool, pj_size_t size)
pj_list free_list[16]
Definition: pool.h:849
pj_size_t max_capacity
Definition: pool.h:826
struct pj_lock_t pj_lock_t
Definition: types.h:239
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)
pj_pool_factory factory
Definition: pool.h:811
pj_list used_list
Definition: pool.h:854
int PJ_NO_MEMORY_EXCEPTION
Definition: pool.h:621
#define PJ_END_DECL
Definition: config.h:1067
pj_lock_t * lock
Definition: pool.h:864
PJ_DECL_LIST_MEMBER(struct pj_pool_t)
void pj_pool_destroy_int(pj_pool_t *pool)
pj_size_t capacity
Definition: pool.h:327
Definition: pool.h:300
unsigned char * cur
Definition: pool.h:304
Linked List data structure.
#define PJ_CACHING_POOL_ARRAY_SIZE
Definition: pool.h:800
#define PJ_BEGIN_DECL
Definition: config.h:1066
#define PJ_INLINE(type)
Definition: config.h:960
void pj_caching_pool_init(pj_caching_pool *ch_pool, const pj_pool_factory_policy *policy, pj_size_t max_capacity)
unsigned char * buf
Definition: pool.h:303
#define PJ_IDECL(type)
Definition: config.h:1115
Definition: pool.h:313
Definition: pool.h:580
pj_size_t increment_size
Definition: pool.h:330
unsigned flags
Definition: pool.h:610
char pool_buf[256 *(sizeof(size_t)/4)]
Definition: pool.h:859
char obj_name[PJ_MAX_OBJ_NAME]
Definition: pool.h:318
void pj_pool_callback(pj_pool_t *pool, pj_size_t size)
Definition: pool.h:294
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)
pj_size_t used_size
Definition: pool.h:838
PJ_DECL_LIST_MEMBER(struct pj_pool_block)
pj_pool_callback * callback
Definition: pool.h:605
void * pj_pool_zalloc(pj_pool_t *pool, pj_size_t size)
Definition: pool.h:474
void pj_pool_factory_dump(pj_pool_factory *pf, pj_bool_t detail)
Definition: pool.h:769
void * pj_pool_calloc(pj_pool_t *pool, pj_size_t count, pj_size_t elem)
pj_pool_block block_list
Definition: pool.h:333
Definition: list.h:74
const pj_pool_factory_policy * pj_pool_factory_get_default_policy(void)
pj_size_t peak_used_size
Definition: pool.h:844
void * factory_data
Definition: pool.h:324
size_t pj_size_t
Definition: types.h:58
pj_pool_factory * factory
Definition: pool.h:321
void pj_caching_pool_destroy(pj_caching_pool *ch_pool)

 


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