Annotation of parser3/src/main/pa_pool.C, revision 1.62

1.13      paf         1: /** @file
1.14      paf         2:        Parser: pool class.
                      3: 
1.59      paf         4:        Copyright (c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com)
1.51      paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.54      paf         6: */
1.14      paf         7: 
1.62    ! paf         8: static const char * const IDENT_POOL_C="$Date: 2003/11/07 13:59:22 $";
1.1       paf         9: 
                     10: #include "pa_pool.h"
1.7       paf        11: #include "pa_exception.h"
1.22      parser     12: #include "pa_common.h"
1.41      paf        13: #include "pa_sapi.h"
1.46      paf        14: #include "pa_charset.h"
1.22      parser     15: 
1.61      paf        16: // Pool
1.21      parser     17: 
1.61      paf        18: Pool::Pool(){}
1.22      parser     19: 
1.61      paf        20: static void cleanup(Pool::Cleanup item, int) {
                     21:        if(item.cleanup)
                     22:                item.cleanup(item.data);
1.46      paf        23: }
1.61      paf        24: Pool::~Pool() {
                     25:        //__asm__("int3");
                     26:        //_asm int 3;
                     27:        //fprintf(stderr, "cleanups: %d\n", cleanups.size());
                     28:        // cleanups first, because they use some object's memory pointers
                     29:        cleanups.for_each(cleanup, 0);
1.22      parser     30: }
                     31: 
1.61      paf        32: void Pool::register_cleanup(void (*cleanup) (void *), void *data) {
                     33:        cleanups+=Cleanup(cleanup, data);
1.46      paf        34: }
1.49      paf        35: 
1.61      paf        36: static void unregister_cleanup(Pool::Cleanup& item, void* cleanup_data) {
                     37:        if(item.data==cleanup_data)
                     38:                item.cleanup=0;
1.49      paf        39: }
1.61      paf        40: void Pool::unregister_cleanup(void *cleanup_data) {
                     41:        cleanups.for_each_ref(::unregister_cleanup, cleanup_data);
1.49      paf        42: }
1.46      paf        43: 
1.61      paf        44: // Pooled
1.22      parser     45: 
1.61      paf        46: static void cleanup(void *data) {
                     47:        static_cast<Pooled*>(data)->~Pooled();
1.53      paf        48: }
                     49: 
1.61      paf        50: Pooled::Pooled(Pool& apool): fpool(apool) {
                     51:        fpool.register_cleanup(cleanup, this);
1.32      parser     52: }
                     53: 
1.61      paf        54: /// Sole: this got called automatically from Pool::~Pool()
                     55: Pooled::~Pooled() {
                     56:        fpool.unregister_cleanup(this);
1.32      parser     57: }

E-mail: