VirtualBox

Changeset 19897 in vbox for trunk/include


Ignore:
Timestamp:
May 21, 2009 9:36:46 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
47592
Message:

IPRT: Termination callback framework. (not hooked up to anything yet)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/initterm.h

    r13832 r19897  
    44
    55/*
    6  * Copyright (C) 2006-2007 Sun Microsystems, Inc.
     6 * Copyright (C) 2006-2009 Sun Microsystems, Inc.
    77 *
    88 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    134134
    135135
     136/**
     137 * Termination reason.
     138 */
     139typedef enum RTTERMREASON
     140{
     141    /** Normal exit. iStatus contains the exit code. */
     142    RTTERMREASON_EXIT = 1,
     143    /** Any abnormal exit. iStatus is 0 and has no meaning. */
     144    RTTERMREASON_ABEND,
     145    /** Killed by a signal. The iStatus contains the signal number. */
     146    RTTERMREASON_SIGNAL,
     147    /** The IPRT module is being unloaded. iStatus is 0 and has no meaning. */
     148    RTTERMREASON_UNLOAD
     149} RTTERMREASON;
     150
     151/** Whether lazy clean up is Okay or not.
     152 * When the process is exiting, it is a waste of time to for instance free heap
     153 * memory or close open files. OTOH, when the runtime is unloaded from the
     154 * process, it is important to release absolutely all resources to prevent
     155 * resource leaks. */
     156#define RTTERMREASON_IS_LAZY_CLEANUP_OK(enmReason)  ((enmReason) != RTTERMREASON_UNLOAD)
     157
     158
     159/**
     160 * IPRT termination callback function.
     161 *
     162 * @param   enmReason           The cause of the termination.
     163 * @param   iStatus             The meaning of this depends on enmReason.
     164 * @param   pvUser              User argument passed to RTTermRegisterCallback.
     165 */
     166typedef DECLCALLBACK(void) FNRTTERMCALLBACK(RTTERMREASON enmReason, int32_t iStatus, void *pvUser);
     167/** Pointer to an IPRT termination callback function. */
     168typedef FNRTTERMCALLBACK *PFNRTTERMCALLBACK;
     169
     170
     171/**
     172 * Registers a termination callback.
     173 *
     174 * This is intended for performing clean up during IPRT termination. Frequently
     175 * paired with lazy initialization thru RTOnce.
     176 *
     177 * The callbacks are called in LIFO order.
     178 *
     179 * @returns IPRT status code.
     180 *
     181 * @param   pfnCallback         The callback function.
     182 * @param   pvUser              The user argument for the callback.
     183 *
     184 * @remarks May need to acquire a fast mutex or critical section, so use with
     185 *          some care in ring-0 context.
     186 *
     187 * @remarks Be very careful using this from code that may be unloaded before
     188 *          IPRT terminates. Unlike some atexit and on_exit implementations,
     189 *          IPRT will not automatically unregister callbacks when a module gets
     190 *          unloaded.
     191 */
     192RTDECL(int) RTTermRegisterCallback(PFNRTTERMCALLBACK pfnCallback, void *pvUser);
     193
     194/**
     195 * Deregister a termination callback.
     196 *
     197 * @returns VINF_SUCCESS if found, VERR_NOT_FOUND if the callback/pvUser pair
     198 *          wasn't found.
     199 *
     200 * @param   pfnCallback         The callback function.
     201 * @param   pvUser              The user argument for the callback.
     202 */
     203RTDECL(int) RTTermDeregisterCallback(PFNRTTERMCALLBACK pfnCallback, void *pvUser);
     204
     205/**
     206 * Runs the termination callback queue.
     207 *
     208 * Normally called by an internal IPRT termination function, but may also be
     209 * called by external code immediately prior to terminating IPRT if it is in a
     210 * better position to state the termination reason and/or status.
     211 *
     212 * @param   enmReason           The reason why it's called.
     213 * @param   iStatus             The associated exit status or signal number.
     214 */
     215RTDECL(void) RTTermRunCallbacks(RTTERMREASON enmReason, int32_t iStatus);
     216
    136217/** @} */
    137218
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette