GNU libmicrohttpd  0.9.29
mhd_threads.h
Go to the documentation of this file.
1 /*
2  This file is part of libmicrohttpd
3  Copyright (C) 2016 Karlson2k (Evgeny Grin)
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library 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 GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 */
20 
36 #ifndef MHD_THREADS_H
37 #define MHD_THREADS_H 1
38 
39 #include "mhd_options.h"
40 #ifdef HAVE_STDDEF_H
41 # include <stddef.h> /* for size_t */
42 #else /* ! HAVE_STDDEF_H */
43 # include <stdlib.h> /* for size_t */
44 #endif /* ! HAVE_STDDEF_H */
45 
46 #if defined(MHD_USE_POSIX_THREADS)
47 # undef HAVE_CONFIG_H
48 # include <pthread.h>
49 # define HAVE_CONFIG_H 1
50 #elif defined(MHD_USE_W32_THREADS)
51 # ifndef WIN32_LEAN_AND_MEAN
52 # define WIN32_LEAN_AND_MEAN 1
53 # endif /* !WIN32_LEAN_AND_MEAN */
54 # include <windows.h>
55 #else
56 # error No threading API is available.
57 #endif
58 
59 #ifndef MHD_NO_THREAD_NAMES
60 # if defined(MHD_USE_POSIX_THREADS)
61 # if defined(HAVE_PTHREAD_SETNAME_NP_GNU) || defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) || \
62  defined(HAVE_PTHREAD_SETNAME_NP_DARWIN) || defined(HAVE_PTHREAD_SETNAME_NP_NETBSD) || \
63  defined(HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD) || defined(HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI)
64 # define MHD_USE_THREAD_NAME_
65 # endif /* HAVE_PTHREAD_SETNAME_NP */
66 # elif defined(MHD_USE_W32_THREADS)
67 # ifdef _MSC_FULL_VER
68  /* Thread names only available with VC compiler */
69 # define MHD_USE_THREAD_NAME_
70 # endif /* _MSC_FULL_VER */
71 # endif
72 #endif
73 
74 #if defined(MHD_USE_POSIX_THREADS)
75  typedef pthread_t MHD_thread_handle_;
76 #elif defined(MHD_USE_W32_THREADS)
77  typedef HANDLE MHD_thread_handle_;
78 #endif
79 
80 #if defined(MHD_USE_POSIX_THREADS)
81 # define MHD_THRD_RTRN_TYPE_ void*
82 # define MHD_THRD_CALL_SPEC_
83 #elif defined(MHD_USE_W32_THREADS)
84 # define MHD_THRD_RTRN_TYPE_ unsigned
85 # define MHD_THRD_CALL_SPEC_ __stdcall
86 #endif
87 
88 #if defined(MHD_USE_POSIX_THREADS)
89 
94 #define MHD_join_thread_(thread) (!pthread_join((thread), NULL))
95 #elif defined(MHD_USE_W32_THREADS)
96 
101 #define MHD_join_thread_(thread) (WAIT_OBJECT_0 == WaitForSingleObject((thread), INFINITE) ? (CloseHandle((thread)), !0) : 0)
102 #endif
103 
110 typedef MHD_THRD_RTRN_TYPE_
111 (MHD_THRD_CALL_SPEC_ *MHD_THREAD_START_ROUTINE_)(void *cls);
112 
113 
125 int
126 MHD_create_thread_ (MHD_thread_handle_ *thread,
127  size_t stack_size,
128  MHD_THREAD_START_ROUTINE_ start_routine,
129  void *arg);
130 
131 #ifndef MHD_USE_THREAD_NAME_
132 #define MHD_create_named_thread_(t,n,s,r,a) MHD_create_thread_((t),(s),(r),(a))
133 #else /* MHD_USE_THREAD_NAME_ */
134 
144 int
145 MHD_create_named_thread_ (MHD_thread_handle_ *thread,
146  const char* thread_name,
147  size_t stack_size,
148  MHD_THREAD_START_ROUTINE_ start_routine,
149  void *arg);
150 
151 #endif /* MHD_USE_THREAD_NAME_ */
152 
153 #endif /* ! MHD_THREADS_H */
additional automatic macros for MHD_config.h
int MHD_create_thread_(MHD_thread_handle_ *thread, size_t stack_size, MHD_THREAD_START_ROUTINE_ start_routine, void *arg)
Definition: mhd_threads.c:186
#define MHD_create_named_thread_(t, n, s, r, a)
Definition: mhd_threads.h:132
MHD_THRD_RTRN_TYPE_(MHD_THRD_CALL_SPEC_ * MHD_THREAD_START_ROUTINE_)(void *cls)
Definition: mhd_threads.h:111