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 # define MHD_USE_THREAD_NAME_
64 # endif /* HAVE_PTHREAD_SETNAME_NP */
65 # elif defined(MHD_USE_W32_THREADS)
66 # ifdef _MSC_FULL_VER
67  /* Thread names only available with VC compiler */
68 # define MHD_USE_THREAD_NAME_
69 # endif /* _MSC_FULL_VER */
70 # endif
71 #endif
72 
73 #if defined(MHD_USE_POSIX_THREADS)
74  typedef pthread_t MHD_thread_handle_;
75 #elif defined(MHD_USE_W32_THREADS)
76  typedef HANDLE MHD_thread_handle_;
77 #endif
78 
79 #if defined(MHD_USE_POSIX_THREADS)
80 # define MHD_THRD_RTRN_TYPE_ void*
81 # define MHD_THRD_CALL_SPEC_
82 #elif defined(MHD_USE_W32_THREADS)
83 # define MHD_THRD_RTRN_TYPE_ unsigned
84 # define MHD_THRD_CALL_SPEC_ __stdcall
85 #endif
86 
87 #if defined(MHD_USE_POSIX_THREADS)
88 
93 #define MHD_join_thread_(thread) (!pthread_join((thread), NULL))
94 #elif defined(MHD_USE_W32_THREADS)
95 
100 #define MHD_join_thread_(thread) (WAIT_OBJECT_0 == WaitForSingleObject((thread), INFINITE) ? (CloseHandle((thread)), !0) : 0)
101 #endif
102 
109 typedef MHD_THRD_RTRN_TYPE_
110 (MHD_THRD_CALL_SPEC_ *MHD_THREAD_START_ROUTINE_)(void *cls);
111 
112 
124 int
125 MHD_create_thread_ (MHD_thread_handle_ *thread,
126  size_t stack_size,
127  MHD_THREAD_START_ROUTINE_ start_routine,
128  void *arg);
129 
130 #ifndef MHD_USE_THREAD_NAME_
131 #define MHD_create_named_thread_(t,n,s,r,a) MHD_create_thread_((t),(s),(r),(a))
132 #else /* MHD_USE_THREAD_NAME_ */
133 
143 int
144 MHD_create_named_thread_ (MHD_thread_handle_ *thread,
145  const char* thread_name,
146  size_t stack_size,
147  MHD_THREAD_START_ROUTINE_ start_routine,
148  void *arg);
149 
150 #endif /* MHD_USE_THREAD_NAME_ */
151 
152 #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:181
#define MHD_create_named_thread_(t, n, s, r, a)
Definition: mhd_threads.h:131
MHD_THRD_RTRN_TYPE_(MHD_THRD_CALL_SPEC_ * MHD_THREAD_START_ROUTINE_)(void *cls)
Definition: mhd_threads.h:110