/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file.
#ifndef BASE_AT_EXIT_H_ #define BASE_AT_EXIT_H_
#include <stack>
#include"base/basictypes.h"
#include"mozilla/Mutex.h"
namespace base {
// This class provides a facility similar to the CRT atexit(), except that // we control when the callbacks are executed. Under Windows for a DLL they // happen at a really bad time and under the loader lock. This facility is // mostly used by base::Singleton. // // The usage is simple. Early in the main() or WinMain() scope create an // AtExitManager object on the stack: // int main(...) { // base::AtExitManager exit_manager; // // } // When the exit_manager object goes out of scope, all the registered // callbacks and singleton destructors will be called.
class AtExitManager { protected: // This constructor will allow this instance of AtExitManager to be created // even if one already exists. This should only be used for testing! // AtExitManagers are kept on a global stack, and it will be removed during // destruction. This allows you to shadow another AtExitManager. explicit AtExitManager(bool shadow);
public: typedefvoid (*AtExitCallbackType)(void*);
AtExitManager();
// The dtor calls all the registered callbacks. Do not try to register more // callbacks after this point.
~AtExitManager();
// Registers the specified function to be called at exit. The prototype of // the callback function is void func(). staticvoid RegisterCallback(AtExitCallbackType func, void* param);
// Calls the functions registered with RegisterCallback in LIFO order. It // is possible to register new callbacks after calling this function. staticvoid ProcessCallbacksNow();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.