The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

172 lines
4.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #include "juce_StandardHeader.h"
  19. BEGIN_JUCE_NAMESPACE
  20. #include "../text/juce_String.h"
  21. #include "juce_SystemStats.h"
  22. #include "juce_Random.h"
  23. #include "juce_Time.h"
  24. #include "juce_Atomic.h"
  25. #include "../threads/juce_Thread.h"
  26. #include "../text/juce_LocalisedStrings.h"
  27. #include "juce_PlatformUtilities.h"
  28. void juce_initialiseStrings();
  29. //==============================================================================
  30. const String SystemStats::getJUCEVersion() throw()
  31. {
  32. return "JUCE v" + String (JUCE_MAJOR_VERSION) + "." + String (JUCE_MINOR_VERSION);
  33. }
  34. //==============================================================================
  35. static bool juceInitialisedNonGUI = false;
  36. void JUCE_PUBLIC_FUNCTION initialiseJuce_NonGUI()
  37. {
  38. if (! juceInitialisedNonGUI)
  39. {
  40. #if JUCE_MAC || JUCE_IPHONE
  41. const ScopedAutoReleasePool pool;
  42. #endif
  43. #ifdef JUCE_DEBUG
  44. // Some simple test code to keep an eye on things and make sure these functions
  45. // work ok on all platforms. Let me know if any of these assertions fail!
  46. int n = 1;
  47. atomicIncrement (n);
  48. jassert (atomicIncrementAndReturn (n) == 3);
  49. atomicDecrement (n);
  50. jassert (atomicDecrementAndReturn (n) == 1);
  51. jassert (swapByteOrder ((uint32) 0x11223344) == 0x44332211);
  52. // quick test to make sure the run-time lib doesn't crash on freeing a null-pointer.
  53. SystemStats* nullPointer = 0;
  54. juce_free (nullPointer);
  55. delete[] nullPointer;
  56. delete nullPointer;
  57. #endif
  58. // Now the real initialisation..
  59. juceInitialisedNonGUI = true;
  60. DBG (SystemStats::getJUCEVersion());
  61. juce_initialiseStrings();
  62. SystemStats::initialiseStats();
  63. Random::getSystemRandom().setSeedRandomly(); // (mustn't call this before initialiseStats() because it relies on the time being set up)
  64. }
  65. }
  66. #if JUCE_WINDOWS
  67. // This is imported from the sockets code..
  68. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  69. extern juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib;
  70. #endif
  71. #if JUCE_DEBUG
  72. extern void juce_CheckForDanglingStreams();
  73. #endif
  74. void JUCE_PUBLIC_FUNCTION shutdownJuce_NonGUI()
  75. {
  76. if (juceInitialisedNonGUI)
  77. {
  78. #if JUCE_MAC || JUCE_IPHONE
  79. const ScopedAutoReleasePool pool;
  80. #endif
  81. #if JUCE_WINDOWS
  82. // need to shut down sockets if they were used..
  83. if (juce_CloseWin32SocketLib != 0)
  84. (*juce_CloseWin32SocketLib)();
  85. #endif
  86. LocalisedStrings::setCurrentMappings (0);
  87. Thread::stopAllThreads (3000);
  88. #if JUCE_DEBUG
  89. juce_CheckForDanglingStreams();
  90. #endif
  91. juceInitialisedNonGUI = false;
  92. }
  93. }
  94. //==============================================================================
  95. #ifdef JUCE_DLL
  96. void* juce_Malloc (const int size)
  97. {
  98. return malloc (size);
  99. }
  100. void* juce_Calloc (const int size)
  101. {
  102. return calloc (1, size);
  103. }
  104. void* juce_Realloc (void* const block, const int size)
  105. {
  106. return realloc (block, size);
  107. }
  108. void juce_Free (void* const block)
  109. {
  110. free (block);
  111. }
  112. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  113. void* juce_DebugMalloc (const int size, const char* file, const int line)
  114. {
  115. return _malloc_dbg (size, _NORMAL_BLOCK, file, line);
  116. }
  117. void* juce_DebugCalloc (const int size, const char* file, const int line)
  118. {
  119. return _calloc_dbg (1, size, _NORMAL_BLOCK, file, line);
  120. }
  121. void* juce_DebugRealloc (void* const block, const int size, const char* file, const int line)
  122. {
  123. return _realloc_dbg (block, size, _NORMAL_BLOCK, file, line);
  124. }
  125. void juce_DebugFree (void* const block)
  126. {
  127. _free_dbg (block, _NORMAL_BLOCK);
  128. }
  129. #endif
  130. #endif
  131. END_JUCE_NAMESPACE