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.

203 lines
5.1KB

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