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.

169 lines
4.8KB

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