File:  [parser3project] / parser3 / src / main / pa_pool.C
Revision 1.69: download - view: text, annotated - select for diffs - revision graph
Sat Apr 25 13:38:46 2026 UTC (2 months, 1 week ago) by moko
Branches: MAIN
CVS tags: HEAD
Copyright year updated, websites links changed to https://

/** @file
	Parser: pool class.

	Copyright (c) 2000-2026 Art. Lebedev Studio (https://www.artlebedev.com)
	Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru>
*/

#include "pa_pool.h"
#include "pa_exception.h"
#include "pa_common.h"
#include "pa_sapi.h"
#include "pa_charset.h"

volatile const char * IDENT_PA_POOL_C="$Id: pa_pool.C,v 1.69 2026/04/25 13:38:46 moko Exp $" IDENT_PA_POOL_H;

// Pool

Pool::Pool(){}

static void cleanup(Pool::Cleanup item, int) {
	if(item.cleanup)
		item.cleanup(item.data);
}
Pool::~Pool() {
	//__asm__("int3");
	//_asm int 3;
	//fprintf(stderr, "cleanups: %d\n", cleanups.size());
	// cleanups first, because they use some object's memory pointers
	cleanups.for_each(cleanup, 0);
}

void Pool::register_cleanup(void (*cleanup) (void *), void *data) {
	cleanups+=Cleanup(cleanup, data);
}

static void unregister_cleanup(Pool::Cleanup& item, void* cleanup_data) {
	if(item.data==cleanup_data)
		item.cleanup=0;
}
void Pool::unregister_cleanup(void *cleanup_data) {
	cleanups.for_each_ref(::unregister_cleanup, cleanup_data);
}

// Pooled

static void cleanup(void *data) {
	static_cast<Pooled*>(data)->~Pooled();
}

Pooled::Pooled(Pool& apool): fpool(apool) {
	fpool.register_cleanup(cleanup, this);
}

/// Sole: this got called automatically from Pool::~Pool()
Pooled::~Pooled() {
	fpool.unregister_cleanup(this);
}

E-mail: