JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_Threads_linux.cpp
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26/*
27 Note that a lot of methods that you'd expect to find in this file actually
28 live in juce_posix_SharedCode.h!
29*/
30
31bool Thread::createNativeThread (Priority)
32{
33 PosixThreadAttribute attr { threadStackSize };
34 PosixSchedulerPriority::getNativeSchedulerAndPriority (realtimeOptions, {}).apply (attr);
35
36 threadId = threadHandle = makeThreadHandle (attr, this, [] (void* userData) -> void*
37 {
38 auto* myself = static_cast<Thread*> (userData);
39
40 juce_threadEntryPoint (myself);
41
42 return nullptr;
43 });
44
45 return threadId != nullptr;
46}
47
48void Thread::killThread()
49{
50 if (threadHandle != nullptr)
51 pthread_cancel ((pthread_t) threadHandle.load());
52}
53
54// Until we implement Nice awareness, these don't do anything on Linux.
56{
58
59 return priority;
60}
61
63{
65
66 // Return true to make it compatible with other platforms.
67 priority = newPriority;
68 return true;
69}
70
71//==============================================================================
72JUCE_API void JUCE_CALLTYPE Process::setPriority (ProcessPriority) {}
73
74static bool swapUserAndEffectiveUser()
75{
76 auto result1 = setreuid (geteuid(), getuid());
77 auto result2 = setregid (getegid(), getgid());
78 return result1 == 0 && result2 == 0;
79}
80
81JUCE_API void JUCE_CALLTYPE Process::raisePrivilege() { if (geteuid() != 0 && getuid() == 0) swapUserAndEffectiveUser(); }
82JUCE_API void JUCE_CALLTYPE Process::lowerPrivilege() { if (geteuid() == 0 && getuid() != 0) swapUserAndEffectiveUser(); }
83
84} // namespace juce
static void JUCE_CALLTYPE raisePrivilege()
Raises the current process's privilege level.
static void JUCE_CALLTYPE setPriority(ProcessPriority priority)
Changes the current process's priority.
static void JUCE_CALLTYPE lowerPrivilege()
Lowers the current process's privilege level.
ThreadID getThreadId() const noexcept
Returns the ID of this thread.
Priority getPriority() const
Returns the current priority of this thread.
bool setPriority(Priority newPriority)
Attempts to set the priority for this thread.
Thread(const String &threadName, size_t threadStackSize=osDefaultStackSize)
Creates a thread.
static ThreadID JUCE_CALLTYPE getCurrentThreadId()
Returns an id that identifies the caller thread.
Priority
The different runtime priorities of non-realtime threads.
Definition juce_Thread.h:54
getegid
geteuid
getgid
getuid
#define jassert(expression)
Platform-independent assertion macro.
#define JUCE_CALLTYPE
This macro defines the C calling convention used as the standard for JUCE calls.
T load(T... args)
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
pthread_cancel
setregid
setreuid