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.

147 lines
4.2KB

  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. //==============================================================================
  33. const String SystemStats::getJUCEVersion()
  34. {
  35. return T("JUCE v") + String (JUCE_MAJOR_VERSION) + T(".") + String (JUCE_MINOR_VERSION);
  36. }
  37. //==============================================================================
  38. static bool juceInitialisedNonGUI = false;
  39. void JUCE_API initialiseJuce_NonGUI()
  40. {
  41. if (! juceInitialisedNonGUI)
  42. {
  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. SystemStats::initialiseStats();
  62. Random::getSystemRandom().setSeed (Time::currentTimeMillis());
  63. }
  64. }
  65. void JUCE_API shutdownJuce_NonGUI()
  66. {
  67. if (juceInitialisedNonGUI)
  68. {
  69. LocalisedStrings::setCurrentMappings (0);
  70. Thread::stopAllThreads (3000);
  71. juceInitialisedNonGUI = false;
  72. }
  73. }
  74. //==============================================================================
  75. #ifdef JUCE_DLL
  76. void* juce_Malloc (const int size)
  77. {
  78. return malloc (size);
  79. }
  80. void* juce_Calloc (const int size)
  81. {
  82. return calloc (1, size);
  83. }
  84. void* juce_Realloc (void* const block, const int size)
  85. {
  86. return realloc (block, size);
  87. }
  88. void juce_Free (void* const block)
  89. {
  90. free (block);
  91. }
  92. #if JUCE_DEBUG && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  93. void* juce_DebugMalloc (const int size, const char* file, const int line)
  94. {
  95. return _malloc_dbg (size, _NORMAL_BLOCK, file, line);
  96. }
  97. void* juce_DebugCalloc (const int size, const char* file, const int line)
  98. {
  99. return _calloc_dbg (1, size, _NORMAL_BLOCK, file, line);
  100. }
  101. void* juce_DebugRealloc (void* const block, const int size, const char* file, const int line)
  102. {
  103. return _realloc_dbg (block, size, _NORMAL_BLOCK, file, line);
  104. }
  105. void juce_DebugFree (void* const block)
  106. {
  107. _free_dbg (block, _NORMAL_BLOCK);
  108. }
  109. #endif
  110. #endif
  111. END_JUCE_NAMESPACE