From fdb188da1ab82e677ae77fafadfd0717b5900fef Mon Sep 17 00:00:00 2001 From: Olaf Barthel Date: Mon, 4 Jul 2005 11:21:14 +0000 Subject: [PATCH] - Added the clib2 shared library initialization/cleanup code. git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@15006 87f5fb63-7c3d-0410-a384-fd976d0f7a62 --- library/skeleton_library/lib_user.c | 48 +++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/library/skeleton_library/lib_user.c b/library/skeleton_library/lib_user.c index 5dc66dd..ae12803 100755 --- a/library/skeleton_library/lib_user.c +++ b/library/skeleton_library/lib_user.c @@ -1,5 +1,5 @@ /* - * $Id: lib_user.c,v 1.3 2005-07-04 11:06:21 obarthel Exp $ + * $Id: lib_user.c,v 1.4 2005-07-04 11:21:14 obarthel Exp $ * * :ts=4 * @@ -35,6 +35,10 @@ /****************************************************************************/ +#include + +/****************************************************************************/ + /* The following function is called as part of the library initialization, right after the library is loaded. This function should perform only initialization operations which can be accomplished quickly and without @@ -94,13 +98,34 @@ UserLibInit( BOOL UserLibOpen(struct UserData * ud) { - BOOL result; + BOOL result = FALSE; + + /* For the AmigaOS4 build, invoke the clib2 shared library + initialization code. Note that this is not strictly + necessary. In fact, you should not need this functionality + if you stick to use Amiga operating system routines only + and stay away from using 'C' runtime library functions + that are not reentrant, such as malloc() or fprintf(). + Use this feature only if you are porting code to the Amiga + which cannot be easily converted to follow the AmigaOS + API definitions only. */ + #if defined(__amigaos4__) && defined(__THREAD_SAFE) + { + /* Note that the clib2 library initialization is + called exactly once, when the first client + opens this library. */ + if(ud->ud_UseCount == 0 && !__lib_init(SysBase)) + goto out; + } + #endif /* __amigaos4__ && __THREAD_SAFE */ /* Remember that one more customer is using this data structure. */ ud->ud_UseCount++; result = TRUE; + out: + return(result); } @@ -114,6 +139,25 @@ UserLibClose(struct UserData * ud) { /* Remember that one less customer is using this data structure. */ ud->ud_UseCount--; + + /* For the AmigaOS4 build, invoke the clib2 shared library + cleanup code. Note that this is not strictly + necessary. In fact, you should not need this functionality + if you stick to use Amiga operating system routines only + and stay away from using 'C' runtime library functions + that are not reentrant, such as malloc() or fprintf(). + Use this feature only if you are porting code to the Amiga + which cannot be easily converted to follow the AmigaOS + API definitions only. */ + #if defined(__amigaos4__) && defined(__THREAD_SAFE) + { + /* Note that the clib2 library cleanup code is + called exactly once, when the first client + opens this library. */ + if(ud->ud_UseCount == 0) + __lib_exit(); + } + #endif /* __amigaos4__ && __THREAD_SAFE */ } /****************************************************************************/