Blindly add a few stuff from VST
[juce-lv2.git] / juce / source / src / native / linux / juce_linux_Threads.cpp
bloba0961b2a40af15988031ec2f20ebda994d040d3e
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 // (This file gets included by juce_linux_NativeCode.cpp, rather than being
27 // compiled on its own).
28 #if JUCE_INCLUDED_FILE
31 Note that a lot of methods that you'd expect to find in this file actually
32 live in juce_posix_SharedCode.h!
35 //==============================================================================
36 // sets the process to 0=low priority, 1=normal, 2=high, 3=realtime
37 void Process::setPriority (ProcessPriority prior)
39 struct sched_param param;
40 int policy, maxp, minp;
42 const int p = (int) prior;
44 if (p <= 1)
45 policy = SCHED_OTHER;
46 else
47 policy = SCHED_RR;
49 minp = sched_get_priority_min (policy);
50 maxp = sched_get_priority_max (policy);
52 if (p < 2)
53 param.sched_priority = 0;
54 else if (p == 2 )
55 // Set to middle of lower realtime priority range
56 param.sched_priority = minp + (maxp - minp) / 4;
57 else
58 // Set to middle of higher realtime priority range
59 param.sched_priority = minp + (3 * (maxp - minp) / 4);
61 pthread_setschedparam (pthread_self(), policy, &param);
64 void Process::terminate()
66 exit (0);
69 JUCE_API bool JUCE_CALLTYPE juce_isRunningUnderDebugger()
71 static char testResult = 0;
73 if (testResult == 0)
75 testResult = (char) ptrace (PT_TRACE_ME, 0, 0, 0);
77 if (testResult >= 0)
79 ptrace (PT_DETACH, 0, (caddr_t) 1, 0);
80 testResult = 1;
84 return testResult < 0;
87 JUCE_API bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
89 return juce_isRunningUnderDebugger();
92 void Process::raisePrivilege()
94 // If running suid root, change effective user
95 // to root
96 if (geteuid() != 0 && getuid() == 0)
98 setreuid (geteuid(), getuid());
99 setregid (getegid(), getgid());
103 void Process::lowerPrivilege()
105 // If runing suid root, change effective user
106 // back to real user
107 if (geteuid() == 0 && getuid() != 0)
109 setreuid (geteuid(), getuid());
110 setregid (getegid(), getgid());
114 #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
116 void* PlatformUtilities::loadDynamicLibrary (const String& name)
118 return dlopen (name.toUTF8(), RTLD_LOCAL | RTLD_NOW);
121 void PlatformUtilities::freeDynamicLibrary (void* handle)
123 dlclose(handle);
126 void* PlatformUtilities::getProcedureEntryPoint (void* libraryHandle, const String& procedureName)
128 return dlsym (libraryHandle, procedureName.toUTF8());
131 #endif
133 #endif