Leosac
0.8.0
Open Source Access Control
ThreadUtils.cpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2014-2016 Leosac
3
4
This file is part of Leosac.
5
6
Leosac is free software: you can redistribute it and/or modify
7
it under the terms of the GNU Affero General Public License as published by
8
the Free Software Foundation, either version 3 of the License, or
9
(at your option) any later version.
10
11
Leosac is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU Affero General Public License for more details.
15
16
You should have received a copy of the GNU Affero General Public License
17
along with this program. If not, see <http://www.gnu.org/licenses/>.
18
*/
19
20
#include "
ThreadUtils.hpp
"
21
#include "
enforce.hpp
"
22
#include <errno.h>
23
#include <spdlog/fmt/fmt.h>
24
#include <stdio.h>
25
#include <stdlib.h>
26
#include <sys/prctl.h>
27
#include <sys/syscall.h>
28
#include <unistd.h>
29
30
namespace
Leosac
31
{
32
uint64_t
gettid
()
33
{
34
return
static_cast<
uint64_t
>
(syscall(SYS_gettid));
35
}
36
37
void
set_thread_name
(
const
std::string &name)
38
{
39
int
ret = prctl(PR_SET_NAME, name.c_str(), NULL, NULL, NULL);
40
LEOSAC_ENFORCE
(ret == 0,
41
fmt::format
(
"Failed to set thread name. Errno {}"
, errno));
42
}
43
}
Leosac::gettid
uint64_t gettid()
Return the Linux thread ID.
Definition:
ThreadUtils.cpp:32
Leosac::set_thread_name
void set_thread_name(const std::string &name)
Set the name of the current thread.
Definition:
ThreadUtils.cpp:37
ThreadUtils.hpp
enforce.hpp
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition:
APIStatusCode.hpp:22
Leosac::Colorize::detail::format
std::string format(const std::string &escape_code, const T &in)
Return a string containing the escape code, a string representation of T and the clear escape string.
Definition:
Colorize.hpp:49
LEOSAC_ENFORCE
#define LEOSAC_ENFORCE(cond,...)
Similar to enforce, except that it will throw a LEOSACException.
Definition:
enforce.hpp:47
src
tools
ThreadUtils.cpp
Generated on Tue Mar 22 2022 10:48:32 for Leosac by
1.8.17