chromium之at_exit

Posted ckelsel

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了chromium之at_exit相关的知识,希望对你有一定的参考价值。

// 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.

exit_manager离开作用域,所有的回调函数,单例的析构函数将会被调用。


 

再看看头文件

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.
  AtExitManager(bool shadow);

 public:
  typedef void (*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().
  static void 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.
  static void ProcessCallbacksNow();

 

使用方法很简单,只要在main函数最开始的地方,定义一个即可

int main(...) 
{
   base::AtExitManager exit_manager;

   ....
}

 

以上是关于chromium之at_exit的主要内容,如果未能解决你的问题,请参考以下文章

chromium之compiler_specific

chromium之task

chromium之message_pump_win之三

chromium之message_pump_win之二

chromium之dynamic_annotations

chromium之lazy_instance