cplusXtors.c
上传用户:baixin
上传日期:2008-03-13
资源大小:4795k
文件大小:4k
- /* cplusXtors.c - run time support for static ctors and dtors */
- /* Copyright 1993 Wind River Systems, Inc. */
- #include "copyright_wrs.h"
- /*
- modification history
- --------------------
- 01f,19mar02,sn SPR 71699 - moved cplusXtorStrategy here from cplusUsr.o
- 01e,21jan02,sn combined with cplusGlob.cpp; made a 'C' file
- 01d,16oct00,sn use standard C++
- 01c,03jun93,srh doc cleanup
- 01b,23apr93,srh implemented new force-link/initialization scheme
- 01a,31jan93,srh written.
- */
- /*
- DESCRIPTION
- This module contains core run time support for static constructors and
- destructors (cplusCallCtors/cplusCallDtors) as well as user-callable
- functions (cplusCtorsLink/cplusDtorsLink) which call static
- initializers for C++ modules that are linked with VxWorks.
- NOMANUAL
- */
- /* Includes */
- #include "vxWorks.h"
- #include "cplusLib.h"
- extern VOIDFUNCPTR _ctors[];
- extern VOIDFUNCPTR _dtors[];
- /* Globals */
- char __cplusXtors_o = 0;
- CPLUS_XTOR_STRATEGIES cplusXtorStrategy = AUTOMATIC;
- /******************************************************************************
- *
- * cplusCtorsLink - call all linked static constructors (C++)
- *
- * This function calls constructors for all of the static objects linked
- * with a VxWorks bootable image. When creating bootable applications,
- * this function should be called from usrRoot() to initialize all static
- * objects. Correct operation depends on correctly munching the C++
- * modules that are linked with VxWorks.
- *
- * RETURNS: N/A
- */
- BOOL linkedCtorsInitialized = FALSE;
- void cplusCtorsLink ()
- {
- if (!linkedCtorsInitialized)
- {
- cplusCallCtors (_ctors);
- linkedCtorsInitialized = TRUE;
- }
- }
- /******************************************************************************
- *
- * cplusDtorsLink - call all linked static destructors (C++)
- *
- * This function calls destructors for all of the static objects linked
- * with a VxWorks bootable image. When creating bootable applications,
- * this function should be called during system shutdown to decommission
- * all static objects. Correct operation depends on correctly munching
- * the C++ modules that are linked with VxWorks.
- *
- * RETURNS: N/A
- */
- void cplusDtorsLink ()
- {
- cplusCallDtors (_dtors);
- }
- /******************************************************************************
- *
- * cplusCallCtors - call static constructors
- *
- * This routine takes a <ctors> array, as generated by the munch utility,
- * and calls the function which is pointed to by each entry. Each function
- * in the <ctors> array calls the static constructors for one compilation
- * unit. The functions are called in the first-to-last order.
- *
- * NOMANUAL
- */
- void cplusCallCtors
- (
- VOIDFUNCPTR *ctors /* array of pointers to ctor-calling functions */
- )
- {
- /* call ctors in order */
- VOIDFUNCPTR *pVFP;
- for (pVFP = ctors; *pVFP != 0; pVFP++)
- {
- (**pVFP)();
- }
- }
- /******************************************************************************
- *
- * cplusCallDtors - call static destructors
- *
- * This routine takes a <dtors> array, as generated by the munch utility,
- * and calls the function which is pointed to by each entry. Each function
- * in the <dtors> array calls the static destructors for one compilation
- * unit. The functions are called in the last-to-first order, reversing
- * the order in which the static constructors were originally called.
- *
- * NOMANUAL
- */
- void cplusCallDtors
- (
- VOIDFUNCPTR *dtors /* array of pointers to dtor-calling functions */
- )
- {
- /* advance pVFP to end of dtors list */
- VOIDFUNCPTR *pVFP;
- for (pVFP = dtors; *pVFP != 0; pVFP++)
- {
- }
-
- /* call dtors in reverse order of ctors */
- while (pVFP > dtors)
- {
- (**--pVFP)();
- }
- }