2 ** $VER: LibInit.c 37.14 (13.8.97)
4 ** Library initializers and functions to be called by StartUp.c
6 ** (C) Copyright 1996-97 Andreas R. Kleinert
7 ** All Rights Reserved.
10 #define __USE_SYSBASE // perhaps only recognized by SAS/C
12 #include <exec/types.h>
13 #include <exec/memory.h>
14 #include <exec/libraries.h>
15 #include <exec/execbase.h>
16 #include <exec/resident.h>
17 #include <exec/initializers.h>
18 #include <graphics/gfxbase.h>
21 #include <clib/exec_protos.h>
23 #include <proto/exec.h>
25 #include <libcore/compiler.h>
29 struct ExecBase
* SysBase
= NULL
;
30 struct IntuitionBase
* IntuitionBase
= NULL
;
31 struct GfxBase
* GfxBase
= NULL
;
34 # define INTUITIONNAME "intuition.library" /* AROS defines this */
36 # include <intuition/intuitionbase.h> /* INTUITIONNAME */
39 /* -----------------------------------------------------------------------
40 Libraries not shareable between Processes or libraries messing with
41 RamLib (deadlock and crash) may not be opened here - open/close these
42 later locally and or maybe close them fromout L_CloseLibs() when
45 You may bypass this by opening such libs in L_OpenLib(), but then you
46 will have to a) protect it by a semaphore and b) make sure, that
47 libraries are opened only once (when using global library bases).
49 This function is called exactly once during the life cycle of the
51 ----------------------------------------------------------------------- */
52 ULONG SAVEDS STDARGS
L_InitLib (LIBBASETYPEPTR LIBBASE
)
54 SysBase
= LIBBASE
->exb_LibHeader
.lh_SysBase
;
56 IntuitionBase
= (struct IntuitionBase
*) OpenLibrary (INTUITIONNAME
, 37);
60 GfxBase
= (struct GfxBase
*) OpenLibrary (GRAPHICSNAME
, 37);
64 LIBBASE
->exb_IntuitionBase
= IntuitionBase
;
65 LIBBASE
->exb_GfxBase
= GfxBase
;
72 /* -----------------------------------------------------------------------
75 This one is called by OpenLib every time someone opens the library.
76 We don't use this in our example, and therefore it's commented out.
77 ----------------------------------------------------------------------- */
78 ULONG SAVEDS STDARGS
L_InitLib (LIBBASETYPEPTR LIBBASE
)
83 /* -----------------------------------------------------------------------
86 This one is called by CloseLib every time someone closes the library.
87 We don't use this in our example, and therefore it's commented out.
89 The function is only called if the library has been opened at least
91 ----------------------------------------------------------------------- */
92 void SAVEDS STDARGS
L_CloseLib (LIBBASETYPEPTR exb
)
97 /* -----------------------------------------------------------------------
100 This one by default is called by ExpungeLib, which only can take place
101 once and thus per definition is single-threaded.
103 When calling this fromout LibClose instead, you will have to protect it
104 by a semaphore, since you don't know whether a given
105 CloseLibrary(foobase) may cause a Wait(). Additionally, there should be
106 protection, that a library won't be closed twice.
108 This function is also called if L_InitLib() fails, so you can cleanup
110 ----------------------------------------------------------------------- */
111 void SAVEDS STDARGS
L_ExpungeLib (LIBBASETYPEPTR exb
)
114 CloseLibrary ((struct Library
*) GfxBase
);
117 CloseLibrary ((struct Library
*) IntuitionBase
);