GNU libmicrohttpd
0.9.69
mhd_locks.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
37
#ifndef MHD_LOCKS_H
38
#define MHD_LOCKS_H 1
39
40
#include "
mhd_options.h
"
41
42
#if defined(MHD_USE_W32_THREADS)
43
# define MHD_W32_MUTEX_ 1
44
# ifndef WIN32_LEAN_AND_MEAN
45
# define WIN32_LEAN_AND_MEAN 1
46
# endif
/* !WIN32_LEAN_AND_MEAN */
47
# include <windows.h>
48
#elif defined(HAVE_PTHREAD_H) && defined(MHD_USE_POSIX_THREADS)
49
# define MHD_PTHREAD_MUTEX_ 1
50
# undef HAVE_CONFIG_H
51
# include <pthread.h>
52
# define HAVE_CONFIG_H 1
53
#else
54
# error No base mutex API is available.
55
#endif
56
57
#ifndef MHD_PANIC
58
# include <stdio.h>
59
# include <stdlib.h>
60
/* Simple implementation of MHD_PANIC, to be used outside lib */
61
# define MHD_PANIC(msg) do { fprintf (stderr, \
62
"Abnormal termination at %d line in file %s: %s\n", \
63
(int) __LINE__, __FILE__, msg); abort (); \
64
} while (0)
65
#endif
/* ! MHD_PANIC */
66
67
#if defined(MHD_PTHREAD_MUTEX_)
68
typedef
pthread_mutex_t MHD_mutex_;
69
#elif defined(MHD_W32_MUTEX_)
70
typedef
CRITICAL_SECTION MHD_mutex_;
71
#endif
72
73
#if defined(MHD_PTHREAD_MUTEX_)
74
79
#define MHD_mutex_init_(pmutex) (! (pthread_mutex_init ((pmutex), NULL)))
80
#elif defined(MHD_W32_MUTEX_)
81
86
#define MHD_mutex_init_(pmutex) (InitializeCriticalSectionAndSpinCount ( \
87
(pmutex),16))
88
#endif
89
90
#if defined(MHD_PTHREAD_MUTEX_)
91
# if defined(PTHREAD_MUTEX_INITIALIZER)
92
95
# define MHD_MUTEX_STATIC_DEFN_INIT_(m) static MHD_mutex_ m = \
96
PTHREAD_MUTEX_INITIALIZER
97
# endif
/* PTHREAD_MUTEX_INITIALIZER */
98
#endif
99
100
#if defined(MHD_PTHREAD_MUTEX_)
101
106
#define MHD_mutex_destroy_(pmutex) (! (pthread_mutex_destroy ((pmutex))))
107
#elif defined(MHD_W32_MUTEX_)
108
113
#define MHD_mutex_destroy_(pmutex) (DeleteCriticalSection ((pmutex)), ! 0)
114
#endif
115
121
#define MHD_mutex_destroy_chk_(pmutex) do { \
122
if (! MHD_mutex_destroy_ (pmutex)) \
123
MHD_PANIC (_ ("Failed to destroy mutex.\n")); \
124
} while (0)
125
126
127
#if defined(MHD_PTHREAD_MUTEX_)
128
135
#define MHD_mutex_lock_(pmutex) (! (pthread_mutex_lock ((pmutex))))
136
#elif defined(MHD_W32_MUTEX_)
137
144
#define MHD_mutex_lock_(pmutex) (EnterCriticalSection ((pmutex)), ! 0)
145
#endif
146
154
#define MHD_mutex_lock_chk_(pmutex) do { \
155
if (! MHD_mutex_lock_ (pmutex)) \
156
MHD_PANIC (_ ("Failed to lock mutex.\n")); \
157
} while (0)
158
159
#if defined(MHD_PTHREAD_MUTEX_)
160
165
#define MHD_mutex_unlock_(pmutex) (! (pthread_mutex_unlock ((pmutex))))
166
#elif defined(MHD_W32_MUTEX_)
167
172
#define MHD_mutex_unlock_(pmutex) (LeaveCriticalSection ((pmutex)), ! 0)
173
#endif
174
180
#define MHD_mutex_unlock_chk_(pmutex) do { \
181
if (! MHD_mutex_unlock_ (pmutex)) \
182
MHD_PANIC (_ ("Failed to unlock mutex.\n")); \
183
} while (0)
184
185
186
#endif
/* ! MHD_LOCKS_H */
mhd_options.h
additional automatic macros for MHD_config.h
src
microhttpd
mhd_locks.h
Generated by
1.8.16