MPD 0.20.6

- Main Page
- Namespaces
- Data Structures
- Files

- File List
- Globals

Name.hxx
Go to the documentation of this file.
1 /*
2 * Copyright 2003-2017 The Music Player Daemon Project
3 * http://www.musicpd.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef MPD_THREAD_NAME_HXX
21 #define MPD_THREAD_NAME_HXX
22
23 #if defined(HAVE_PTHREAD_SETNAME_NP) && !defined(__NetBSD__)
24 # define HAVE_THREAD_NAME
25 # include <pthread.h>
26 #elif defined(HAVE_PRCTL)
27 # include <sys/prctl.h>
28 # ifdef PR_SET_NAME
29 # define HAVE_THREAD_NAME
30 # endif
31 #endif
32
33 #ifdef HAVE_THREAD_NAME
34 # include <stdio.h>
35 #endif
36
37 static inline void
38 SetThreadName(const char *name)
39 {
40 #if defined(HAVE_PTHREAD_SETNAME_NP) && !defined(__NetBSD__)
41 /* not using pthread_setname_np() on NetBSD because it
42 requires a non-const pointer argument, which we don't have
43 here */
44
45 #ifdef __APPLE__
46 pthread_setname_np(name);
47 #else
48 pthread_setname_np(pthread_self(), name);
49 #endif
50 #elif defined(HAVE_PRCTL) && defined(PR_SET_NAME)
51 prctl(PR_SET_NAME, (unsigned long)name, 0, 0, 0);
52 #else
53 (void)name;
54 #endif
55 }
56
57 template<typename... Args>
58 static inline void
59 FormatThreadName(const char *fmt, gcc_unused Args&&... args)
60 {
61 #ifdef HAVE_THREAD_NAME
62 char buffer[16];
63 snprintf(buffer, sizeof(buffer), fmt, args...);
64 SetThreadName(buffer);
65 #else
66 (void)fmt;
67 #endif
68 }
69
70 #endif
FormatThreadName
static void FormatThreadName(const char *fmt, gcc_unused Args &&...args)
Definition: Name.hxx:59
SetThreadName
static void SetThreadName(const char *name)
Definition: Name.hxx:38
gcc_unused
#define gcc_unused
Definition: Compiler.h:118
fmt
const char * fmt
Definition: Client.hxx:232
name
const Partition const char * name
Definition: Count.hxx:34