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

1.13      paf         1: /** @file
1.14      paf         2:        Parser: pool class.
                      3: 
1.68    ! moko        4:        Copyright (c) 2000-2024 Art. Lebedev Studio (http://www.artlebedev.com)
1.67      moko        5:        Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru>
1.54      paf         6: */
1.14      paf         7: 
1.1       paf         8: #include "pa_pool.h"
1.7       paf         9: #include "pa_exception.h"
1.22      parser     10: #include "pa_common.h"
1.41      paf        11: #include "pa_sapi.h"
1.46      paf        12: #include "pa_charset.h"
1.22      parser     13: 
1.68    ! moko       14: volatile const char * IDENT_PA_POOL_C="$Id: pa_pool.C,v 1.67 2023/09/26 20:49:10 moko Exp $" IDENT_PA_POOL_H;
1.63      moko       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: