summaryrefslogtreecommitdiff
path: root/src/Runtime/global_destructor_chain.c
blob: 1f3790dde7cefdea018ab5dc640df489a4e83430 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "NMWException.h"

dtor_chain *__global_destructor_chain;

extern void *__register_global_object(void *object, dtor_func *destructor, dtor_chain *regmem) {
	regmem->next = __global_destructor_chain;
	regmem->destructor = destructor;
	regmem->object = object;
	__global_destructor_chain = regmem;
	return object;
}

void __destroy_global_chain() {
	dtor_chain *iter = __global_destructor_chain;
	while (__global_destructor_chain != 0) {
		iter = __global_destructor_chain;
		__global_destructor_chain = __global_destructor_chain->next;
		iter->destructor(iter->object, -1);
	}
}

__declspec(section ".dtors") static void* const __destroy_global_chain_reference = __destroy_global_chain;