xref: /haiku/src/kits/app/InitTerminateLibBe.cpp (revision cbe0a0c436162d78cc3f92a305b64918c839d079)
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 <AppMisc.h>
16 #include <LooperList.h>
17 #include <MessagePrivate.h>
18 #include <RosterPrivate.h>
19 #include <TokenSpace.h>
20 
21 
22 extern void __initialize_locale_kit();
23 
24 
25 // debugging
26 //#define DBG(x) x
27 #define DBG(x)
28 #define OUT	printf
29 
30 
31 static void
32 initialize_forked_child()
33 {
34 	DBG(OUT("initialize_forked_child()\n"));
35 
36 	BMessage::Private::StaticReInitForkedChild();
37 	BPrivate::gLooperList.InitAfterFork();
38 	BPrivate::gDefaultTokens.InitAfterFork();
39 	BPrivate::init_team_after_fork();
40 
41 	DBG(OUT("initialize_forked_child() done\n"));
42 }
43 
44 
45 extern "C" void
46 initialize_before(image_id)
47 {
48 	DBG(OUT("initialize_before()\n"));
49 
50 	BMessage::Private::StaticInit();
51 	BRoster::Private::InitBeRoster();
52 
53 	atfork(initialize_forked_child);
54 
55 	DBG(OUT("initialize_before() done\n"));
56 }
57 
58 
59 extern "C" void
60 initialize_after(image_id)
61 {
62 	DBG(OUT("initialize_after()\n"));
63 
64 	__initialize_locale_kit();
65 
66 	DBG(OUT("initialize_after() done\n"));
67 }
68 
69 
70 extern "C" void
71 terminate_after(image_id)
72 {
73 	DBG(OUT("terminate_after()\n"));
74 
75 	BRoster::Private::DeleteBeRoster();
76 	BMessage::Private::StaticCleanup();
77 	BMessage::Private::StaticCacheCleanup();
78 
79 	DBG(OUT("terminate_after() done\n"));
80 }
81 
82