xref: /haiku/src/kits/app/InitTerminateLibBe.cpp (revision 579f1dbca962a2a03df54f69fdc6e9423f91f20e)
1 /*
2  * Copyright 2001-2011, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Ingo Weinhold (bonefish@users.sf.net)
7  */
8 
9 //!	Global library initialization/termination routines.
10 
11 
12 #include <stdio.h>
13 #include <stdlib.h>
14 
15 #include <LooperList.h>
16 #include <MessagePrivate.h>
17 #include <RosterPrivate.h>
18 #include <TokenSpace.h>
19 
20 
21 extern void __initialize_locale_kit();
22 
23 
24 // debugging
25 //#define DBG(x) x
26 #define DBG(x)
27 #define OUT	printf
28 
29 
30 static void
31 initialize_forked_child()
32 {
33 	DBG(OUT("initialize_forked_child()\n"));
34 
35 	BMessage::Private::StaticReInitForkedChild();
36 	BPrivate::gLooperList.InitAfterFork();
37 	BPrivate::gDefaultTokens.InitAfterFork();
38 
39 	DBG(OUT("initialize_forked_child() done\n"));
40 }
41 
42 
43 extern "C" void
44 initialize_before()
45 {
46 	DBG(OUT("initialize_before()\n"));
47 
48 	BMessage::Private::StaticInit();
49 	BRoster::Private::InitBeRoster();
50 
51 	atfork(initialize_forked_child);
52 
53 	DBG(OUT("initialize_before() done\n"));
54 }
55 
56 
57 extern "C" void
58 initialize_after()
59 {
60 	DBG(OUT("initialize_after()\n"));
61 
62 	__initialize_locale_kit();
63 
64 	DBG(OUT("initialize_after() done\n"));
65 }
66 
67 
68 extern "C" void
69 terminate_after()
70 {
71 	DBG(OUT("terminate_after()\n"));
72 
73 	BRoster::Private::DeleteBeRoster();
74 	BMessage::Private::StaticCleanup();
75 	BMessage::Private::StaticCacheCleanup();
76 
77 	DBG(OUT("terminate_after() done\n"));
78 }
79 
80