Annotation of parser3/src/targets/cgi/pa_pool.C, revision 1.41.4.2

1.4       paf         1: /** @file
                      2:        Parser: CGI memory manager impl.
                      3: 
1.41      paf         4:        Copyright (c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com)
1.36      paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.39      paf         6: */
1.4       paf         7: 
1.41.4.2! paf         8: static const char* IDENT_POOL_C="$Date: 2003/03/17 14:48:06 $";
1.1       paf         9: 
                     10: #include "pa_pool.h"
                     11: 
1.41.4.1  paf        12: #ifdef XML
                     13: #      include "libxml/xmlmemory.h"
                     14: #endif
                     15: 
                     16: #ifdef _DEBUG
                     17: #      define GC_DEBUG
                     18: #endif
                     19: #include "gc.h"
                     20: 
1.37      paf        21: 
1.41.4.1  paf        22: // debug switches
                     23: 
                     24: #define DEBUG_TOTAL_ALLOC_SIZE
                     25: #define DEBUG_DUMP
                     26: 
                     27: //
                     28: 
                     29: #ifdef DEBUG_TOTAL_ALLOC_SIZE
1.37      paf        30: unsigned long total_alloc_size=0;
                     31: #endif
                     32: 
1.41.4.2! paf        33: void Pool::log_high_watermark(const char *msg) {
1.41.4.1  paf        34:        fprintf(stderr, "%s: malloced=%lu, heap_used=%lu, heap_free=%lu, bytes_since_gc=%lu, total_bytes=%lu\n",
                     35:                msg,
                     36:                total_alloc_size,
                     37:                GC_get_heap_size(),
                     38:                GC_get_free_bytes(),
                     39:                GC_get_bytes_since_gc(),
                     40:                GC_get_total_bytes()
                     41:                );
                     42: }
1.41.4.2! paf        43: 
1.41.4.1  paf        44: void Pool::collect_garbage() {
                     45: #ifdef DEBUG_DUMP
1.41.4.2! paf        46:        log_high_watermark("before gc");
1.41.4.1  paf        47: #endif
                     48: 
                     49:        //GC_dont_gc=false;
                     50:        //GC_collect_a_little();
                     51:        GC_gcollect();
                     52:        GC_gcollect();
                     53: 
                     54: #ifdef DEBUG_DUMP
1.41.4.2! paf        55:        log_high_watermark("after gc");
1.41.4.1  paf        56: #endif
                     57: }
                     58: 
                     59: #ifdef XML
                     60: char *pa_GC_strdup(const char *s) {
                     61:        if(!s)
                     62:                return 0;
                     63: 
                     64:        size_t size=strlen(s)+1;
                     65:        char *result=(char *)GC_MALLOC_ATOMIC(size);
                     66:        memcpy(result, s, size);
                     67:        return result;
                     68: }
                     69: 
                     70: #endif
                     71: 
                     72: void Pool::real_init() {
                     73: #ifdef DEBUG_DUMP
1.41.4.2! paf        74:        log_high_watermark("init");
1.41.4.1  paf        75: #endif
                     76:        //GC_dont_gc=true;
                     77: #ifdef XML
                     78:        static bool XML_memory_function_overloaded=false;
                     79:        if(!XML_memory_function_overloaded) {
                     80:                XML_memory_function_overloaded=true;
                     81:                xmlMemSetup(/*xmlFreeFunc */GC_free,
                     82:                         /*xmlMallocFunc */GC_malloc,
                     83:                         /*xmlReallocFunc */GC_realloc,
                     84:                         /*xmlStrdupFunc */pa_GC_strdup);
                     85:        }
                     86: #endif
                     87: }
                     88: void Pool::real_finit() {
                     89:        //collect_garbage();
                     90: }
                     91: 
1.25      paf        92: void *Pool::real_malloc(size_t size, int place) {
1.41.4.1  paf        93: #ifdef DEBUG_TOTAL_ALLOC_SIZE
                     94:        total_alloc_size+=size;
                     95: #endif
                     96:        //printf("%d,",size);
                     97: 
                     98:        return GC_MALLOC(size);//::calloc(size,1);//
                     99: }
                    100: 
                    101: void *Pool::real_malloc_atomic(size_t size, int place) {
                    102: #ifdef DEBUG_TOTAL_ALLOC_SIZE
1.37      paf       103:        total_alloc_size+=size;
                    104: #endif
                    105: 
1.41.4.1  paf       106:        return GC_MALLOC_ATOMIC(size);//::calloc(size,1);//
1.1       paf       107: }
                    108: 
                    109: void *Pool::real_calloc(size_t size) {
1.41.4.1  paf       110: #ifdef DEBUG_TOTAL_ALLOC_SIZE
1.37      paf       111:        total_alloc_size+=size;
                    112: #endif
                    113: 
1.41.4.1  paf       114:        return GC_MALLOC(size);//::calloc(size,1);//
1.1       paf       115: }
1.18      parser    116: 
1.41.4.1  paf       117: bool Pool::real_register_cleanup(void (*cleanup) (void *, void*), void *data) {
                    118:        GC_REGISTER_FINALIZER(data, cleanup, 0, 0, 0);
                    119:        return true;
1.34      paf       120: }

E-mail: