File: pa_pool.C

package info (click to toggle)
parser 3.4.5-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,552 kB
  • sloc: cpp: 32,375; sh: 11,487; ansic: 10,849; yacc: 1,361; makefile: 248; awk: 5
file content (57 lines) | stat: -rw-r--r-- 1,363 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/** @file
	Parser: pool class.

	Copyright (c) 2000-2017 Art. Lebedev Studio (http://www.artlebedev.com)
	Author: Alexandr Petrosian <paf@design.ru> (http://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.65 2017/02/07 22:00:43 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);
}