ChimeraTK-cppext 01.07.01
Loading...
Searching...
No Matches
threadName.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3#pragma once
4
5#include <pthread.h>
6
7#include <string>
8
9namespace cppext {
10
17 inline void setThreadName(const std::string& name) {
18#if defined(__linux__)
19 pthread_setname_np(pthread_self(), name.substr(0, std::min<std::string::size_type>(name.length(), 15)).c_str());
20#elif defined(__APPLE__)
21 pthread_setname_np(name.substr(0, std::min<std::string::size_type>(name.length(), 15)).c_str());
22#endif
23 }
24
25} // namespace cppext
void setThreadName(const std::string &name)
Set name of the current thread.