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.

204 lines
5.3KB

  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 "../../../src/juce_core/basics/juce_StandardHeader.h"
  24. #include <pthread.h>
  25. #include <sched.h>
  26. #include <sys/file.h>
  27. #include <sys/types.h>
  28. #include <sys/sysctl.h>
  29. #include <Carbon/Carbon.h>
  30. BEGIN_JUCE_NAMESPACE
  31. #include "../../../src/juce_core/threads/juce_CriticalSection.h"
  32. #include "../../../src/juce_core/threads/juce_WaitableEvent.h"
  33. #include "../../../src/juce_core/threads/juce_Thread.h"
  34. #include "../../../src/juce_core/threads/juce_Process.h"
  35. #include "../../../src/juce_core/misc/juce_PlatformUtilities.h"
  36. #include "../../../src/juce_core/io/files/juce_File.h"
  37. //==============================================================================
  38. /*
  39. Note that a lot of methods that you'd expect to find in this file actually
  40. live in juce_posix_SharedCode.cpp!
  41. */
  42. //==============================================================================
  43. void JUCE_API juce_threadEntryPoint (void*);
  44. void* threadEntryProc (void* userData) throw()
  45. {
  46. juce_threadEntryPoint (userData);
  47. return 0;
  48. }
  49. void* juce_createThread (void* userData) throw()
  50. {
  51. pthread_t handle = 0;
  52. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  53. {
  54. pthread_detach (handle);
  55. return (void*) handle;
  56. }
  57. return 0;
  58. }
  59. void juce_killThread (void* handle) throw()
  60. {
  61. if (handle != 0)
  62. pthread_cancel ((pthread_t) handle);
  63. }
  64. void juce_setCurrentThreadName (const String& /*name*/) throw()
  65. {
  66. }
  67. int Thread::getCurrentThreadId() throw()
  68. {
  69. return (int) pthread_self();
  70. }
  71. void juce_setThreadPriority (void* handle, int priority) throw()
  72. {
  73. if (handle == 0)
  74. handle = (void*) pthread_self();
  75. struct sched_param param;
  76. int policy;
  77. pthread_getschedparam ((pthread_t) handle, &policy, &param);
  78. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  79. pthread_setschedparam ((pthread_t) handle, policy, &param);
  80. }
  81. void Thread::yield() throw()
  82. {
  83. sched_yield();
  84. }
  85. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask) throw()
  86. {
  87. // xxx
  88. jassertfalse
  89. }
  90. //==============================================================================
  91. bool JUCE_CALLTYPE juce_isRunningUnderDebugger() throw()
  92. {
  93. static char testResult = 0;
  94. if (testResult == 0)
  95. {
  96. struct kinfo_proc info;
  97. int m[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
  98. size_t sz = sizeof (info);
  99. sysctl (m, 4, &info, &sz, 0, 0);
  100. testResult = ((info.kp_proc.p_flag & P_TRACED) != 0) ? 1 : -1;
  101. }
  102. return testResult > 0;
  103. }
  104. bool JUCE_CALLTYPE Process::isRunningUnderDebugger() throw()
  105. {
  106. return juce_isRunningUnderDebugger();
  107. }
  108. void Process::raisePrivilege()
  109. {
  110. jassertfalse
  111. }
  112. void Process::lowerPrivilege()
  113. {
  114. jassertfalse
  115. }
  116. void Process::terminate()
  117. {
  118. ExitToShell();
  119. }
  120. void Process::setPriority (ProcessPriority p)
  121. {
  122. // xxx
  123. }
  124. void* Process::loadDynamicLibrary (const String& name)
  125. {
  126. // xxx needs to use bundles
  127. FSSpec fs;
  128. if (PlatformUtilities::makeFSSpecFromPath (&fs, name))
  129. {
  130. CFragConnectionID connID;
  131. Ptr mainPtr;
  132. Str255 errorMessage;
  133. Str63 nm;
  134. PlatformUtilities::copyToStr63 (nm, name);
  135. const OSErr err = GetDiskFragment (&fs, 0, kCFragGoesToEOF, nm, kReferenceCFrag, &connID, &mainPtr, errorMessage);
  136. if (err == noErr)
  137. return (void*)connID;
  138. }
  139. return 0;
  140. }
  141. void Process::freeDynamicLibrary (void* handle)
  142. {
  143. if (handle != 0)
  144. CloseConnection ((CFragConnectionID*)&handle);
  145. }
  146. void* Process::getProcedureEntryPoint (void* h, const String& procedureName)
  147. {
  148. if (h != 0)
  149. {
  150. CFragSymbolClass cl;
  151. Ptr ptr;
  152. Str255 name;
  153. PlatformUtilities::copyToStr255 (name, procedureName);
  154. if (FindSymbol ((CFragConnectionID) h, name, &ptr, &cl) == noErr)
  155. {
  156. return ptr;
  157. }
  158. }
  159. return 0;
  160. }
  161. END_JUCE_NAMESPACE