util: allocate log filename buffers
[openafs.git] / src / util / pthread_threadname.c
1 /*
2  * Copyright 2011, Garrett Wollman
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  *
25  */
26 #include <afsconfig.h>
27 #include <afs/param.h>
28
29 #include "afsutil.h"
30
31 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
32 # include <pthread.h>
33 # ifdef HAVE_PTHREAD_NP_H
34 #  include <pthread_np.h>
35 # endif
36
37 void
38 afs_pthread_setname_self(const char *threadname)
39 {
40 # if defined(HAVE_PTHREAD_SET_NAME_NP)
41         /* FreeBSD style */
42         pthread_set_name_np(pthread_self(), threadname);
43 # elif defined(HAVE_PTHREAD_SETNAME_NP)
44 #  if PTHREAD_SETNAME_NP_ARGS == 3
45         /* DECthreads style */
46         pthread_setname_np(pthread_self(), threadname, (void *)0);
47 #  elif PTHREAD_SETNAME_NP_ARGS == 2
48         /* GNU libc on Linux style */
49         pthread_setname_np(pthread_self(), threadname);
50 #  elif PTHREAD_SETNAME_NP_ARGS == 1
51         /* Mac OS style */
52         pthread_setname_np(threadname);
53 #  else
54 #    error "Could not identify your pthread_setname_np() implementation"
55 #  endif
56 # endif
57 }
58 #endif