nde_init.cpp 675 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include "../nde_c.h"
  2. #include "../DBUtils.h"
  3. #include <atomic>
  4. extern "C" void NDE_HeapInit();
  5. extern "C" void NDE_HeapQuit();
  6. static volatile std::atomic<std::size_t> _init_count = 0;
  7. /* NDE_Init isn't thread safe, be aware
  8. best to call on the main thread during initialization
  9. */
  10. void NDE_Init()
  11. {
  12. if ( _init_count.load() == 0 )
  13. {
  14. NDE_HeapInit();
  15. HMODULE klib = LoadLibraryW( L"Kernel32.dll" );
  16. if ( klib )
  17. {
  18. void *nls = GetProcAddress( klib, "FindNLSString" );
  19. if ( nls )
  20. *( (void **)&findNLSString ) = nls;
  21. }
  22. FreeModule( klib );
  23. }
  24. _init_count.fetch_add( 1 );
  25. }
  26. void NDE_Quit()
  27. {
  28. if ( _init_count.fetch_sub( 1 ) == 0 )
  29. NDE_HeapQuit();
  30. }