aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2017-11-27 17:39:27 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2017-11-27 17:54:14 +0300
commit46727a1b87e201255cfa18ffb88ce8220ac03b4f (patch)
tree2c10d3b499e8c45875826851e034ea16a7340143
parent201a12289de9f50092a7a4aa804159ccbf7166a9 (diff)
downloadlibmicrohttpd-46727a1b87e201255cfa18ffb88ce8220ac03b4f.tar.gz
libmicrohttpd-46727a1b87e201255cfa18ffb88ce8220ac03b4f.zip
Added automatic initialisation of MHD even if GNU function attribute is
not supported.
-rw-r--r--src/microhttpd/daemon.c53
1 files changed, 49 insertions, 4 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 8005c01e..8f3d47b4 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -149,12 +149,19 @@ mhd_panic_std (void *cls,
149/** 149/**
150 * Handler for fatal errors. 150 * Handler for fatal errors.
151 */ 151 */
152MHD_PanicCallback mhd_panic; 152MHD_PanicCallback mhd_panic = NULL;
153 153
154/** 154/**
155 * Closure argument for #mhd_panic. 155 * Closure argument for #mhd_panic.
156 */ 156 */
157void *mhd_panic_cls; 157void *mhd_panic_cls = NULL;
158
159/**
160 * Globally initialise library.
161 */
162void
163MHD_init(void);
164
158 165
159#if defined(_WIN32) && ! defined(__CYGWIN__) 166#if defined(_WIN32) && ! defined(__CYGWIN__)
160/** 167/**
@@ -163,6 +170,40 @@ void *mhd_panic_cls;
163static int mhd_winsock_inited_ = 0; 170static int mhd_winsock_inited_ = 0;
164#endif 171#endif
165 172
173#ifdef _AUTOINIT_FUNCS_ARE_SUPPORTED
174/**
175 * Do nothing - global initialisation is
176 * performed by library constructor.
177 */
178#define MHD_check_global_init_(x) (void)0
179#else /* ! _AUTOINIT_FUNCS_ARE_SUPPORTED */
180/**
181 * Track global initialisation
182 */
183volatile int global_init_count = 0;
184#ifdef MHD_MUTEX_STATIC_DEFN_INIT_
185/**
186 * Global initialisation mutex
187 */
188MHD_MUTEX_STATIC_DEFN_INIT_(global_init_mutex_);
189#endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */
190/**
191 * Check whether global initialisation was performed
192 * and call initialiser if necessary.
193 */
194void
195MHD_check_global_init_ (void)
196{
197#ifdef MHD_MUTEX_STATIC_DEFN_INIT_
198 MHD_mutex_lock_chk_(&global_init_mutex_);
199#endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */
200 if (0 == global_init_count++)
201 MHD_init ();
202#ifdef MHD_MUTEX_STATIC_DEFN_INIT_
203 MHD_mutex_unlock_chk_(&global_init_mutex_);
204#endif /* MHD_MUTEX_STATIC_DEFN_INIT_ */
205}
206#endif /* ! _AUTOINIT_FUNCS_ARE_SUPPORTED */
166 207
167/** 208/**
168 * Trace up to and return master daemon. If the supplied daemon 209 * Trace up to and return master daemon. If the supplied daemon
@@ -5215,6 +5256,7 @@ MHD_start_daemon_va (unsigned int flags,
5215 enum MHD_FLAG eflags; /* same type as in MHD_Daemon */ 5256 enum MHD_FLAG eflags; /* same type as in MHD_Daemon */
5216 enum MHD_FLAG *pflags; 5257 enum MHD_FLAG *pflags;
5217 5258
5259 MHD_check_global_init_();
5218 eflags = (enum MHD_FLAG) flags; 5260 eflags = (enum MHD_FLAG) flags;
5219 pflags = &eflags; 5261 pflags = &eflags;
5220#ifndef HAVE_INET6 5262#ifndef HAVE_INET6
@@ -6709,8 +6751,9 @@ MHD_init(void)
6709#if defined(_WIN32) && ! defined(__CYGWIN__) 6751#if defined(_WIN32) && ! defined(__CYGWIN__)
6710 WSADATA wsd; 6752 WSADATA wsd;
6711#endif /* _WIN32 && ! __CYGWIN__ */ 6753#endif /* _WIN32 && ! __CYGWIN__ */
6712 mhd_panic = &mhd_panic_std; 6754
6713 mhd_panic_cls = NULL; 6755 if (NULL == mhd_panic)
6756 mhd_panic = &mhd_panic_std;
6714 6757
6715#if defined(_WIN32) && ! defined(__CYGWIN__) 6758#if defined(_WIN32) && ! defined(__CYGWIN__)
6716 if (0 != WSAStartup(MAKEWORD(2, 2), &wsd)) 6759 if (0 != WSAStartup(MAKEWORD(2, 2), &wsd))
@@ -6759,6 +6802,8 @@ MHD_fini(void)
6759 MHD_monotonic_sec_counter_finish(); 6802 MHD_monotonic_sec_counter_finish();
6760} 6803}
6761 6804
6805#ifdef _AUTOINIT_FUNCS_ARE_SUPPORTED
6762_SET_INIT_AND_DEINIT_FUNCS(MHD_init, MHD_fini); 6806_SET_INIT_AND_DEINIT_FUNCS(MHD_init, MHD_fini);
6807#endif /* _AUTOINIT_FUNCS_ARE_SUPPORTED */
6763 6808
6764/* end of daemon.c */ 6809/* end of daemon.c */