syslog-ng source
thread-utils.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2013 Balabit
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * As an additional exemption you are allowed to compile & link against the
19  * OpenSSL libraries as published by the OpenSSL project. See the file
20  * COPYING for details.
21  */
22 #ifndef THREAD_UTILS_H_INCLUDED
23 #define THREAD_UTILS_H_INCLUDED
24 
25 #include "syslog-ng.h"
26 #include <pthread.h>
27 
28 #ifdef _WIN32
29 typedef DWORD ThreadId;
30 #else
31 typedef pthread_t ThreadId;
32 #endif
33 
34 static inline ThreadId
35 get_thread_id(void)
36 {
37 #ifndef _WIN32
38  return pthread_self();
39 #else
40  return GetCurrentThreadId();
41 #endif
42 }
43 
44 static inline int
45 threads_equal(ThreadId thread_a, ThreadId thread_b)
46 {
47 #ifndef _WIN32
48  return pthread_equal(thread_a, thread_b);
49 #else
50  return thread_a == thread_b;
51 #endif
52 }
53 
54 static inline void
55 thread_cancel(ThreadId tid)
56 {
57 #ifndef _WIN32
58  pthread_cancel(tid);
59 #else
60  TerminateThread(tid, 0);
61 #endif
62 }
63 
64 static inline void
65 set_thread_name(const gchar *name)
66 {
67 #ifndef _WIN32
68 # if defined(__APPLE__)
69  pthread_setname_np(name);
70 # else
71  pthread_setname_np(pthread_self(), name);
72 # endif
73 #else
74 #endif
75 }
76 
77 #endif
const gchar * name
Definition: debugger.c:265
pthread_t ThreadId
Definition: thread-utils.h:31