blob: 89fa023348119830c5a9d5d2aba0fda1592adf09 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
#include "thread.h"
#include <sys/prctl.h>
using namespace zen;
void zen::setCurrentThreadName(const Zstring& threadName)
{
::prctl(PR_SET_NAME, threadName.c_str(), 0, 0, 0);
}
namespace
{
//don't make this a function-scope static (avoid code-gen for "magic static")
const std::thread::id globalMainThreadId = std::this_thread::get_id();
}
bool zen::runningOnMainThread()
{
if (globalMainThreadId == std::thread::id()) //called during static initialization!
return true;
return std::this_thread::get_id() == globalMainThreadId;
}
|