commit a71d58c12a37632d04cf46d2d5b5c78cac0afc9c
parent 9d1a39ab1400bbe2fe618d5e1c6718fe047b4c73
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date: Sat, 26 Jul 2025 12:41:05 +0200
Fixed build without threads
Diffstat:
13 files changed, 90 insertions(+), 34 deletions(-)
diff --git a/configure.ac b/configure.ac
@@ -2036,7 +2036,6 @@ AS_IF([test "x$USE_THREADS" = "xposix"],
AM_CONDITIONAL([USE_POSIX_THREADS], [test "x$USE_THREADS" = "xposix"])
AM_CONDITIONAL([USE_W32_THREADS], [test "x$USE_THREADS" = "xw32"])
AM_CONDITIONAL([MHD_SUPPORT_THREADS], [test "x$USE_THREADS" != "xnone"])
-AM_CONDITIONAL([DISABLE_THREADS], [test "x$USE_THREADS" = "xnone"])
AC_MSG_RESULT([$USE_THREADS])
AC_ARG_ENABLE([[thread-names]],
diff --git a/src/mhd2/Makefile.am b/src/mhd2/Makefile.am
@@ -57,7 +57,6 @@ libmicrohttpd2_la_SOURCES = \
mhd_stream.h \
mhd_locks.h \
mhd_itc.c mhd_itc.h mhd_itc_types.h \
- mhd_threads.c mhd_threads.h sys_thread_entry_type.h \
mhd_mono_clock.c mhd_mono_clock.h \
mempool_funcs.c mempool_funcs.h mempool_types.h \
mhd_read_file.c mhd_read_file.h \
@@ -106,6 +105,9 @@ libmicrohttpd2_la_SOURCES += \
compat_calloc.c
endif
+threads_OPTSOURCES = \
+ mhd_threads.c mhd_threads.h sys_thread_entry_type.h
+
post_parser_OPTSOURCES = \
http_post_enc.h \
mhd_post_parser.h mhd_post_result.h mhd_postfield_int.h \
@@ -183,6 +185,10 @@ tls_open_OPTSOURCES = \
tls_open_tls_lib.h tls_open_daemon_data.h tls_open_conn_data.h \
tls_open_funcs.c tls_open_funcs.h
+if MHD_SUPPORT_THREADS
+ libmicrohttpd2_la_SOURCES += $(threads_OPTSOURCES)
+endif
+
if MHD_SUPPORT_POST_PARSER
libmicrohttpd2_la_SOURCES += $(post_parser_OPTSOURCES)
endif
diff --git a/src/mhd2/daemon_funcs.h b/src/mhd2/daemon_funcs.h
@@ -59,7 +59,7 @@ mhd_daemon_trigger_itc (struct MHD_Daemon *restrict d);
#else /* ! MHD_SUPPORT_THREADS */
-#define mhd_daemon_trigger_itc (d) ((void) d, ! 0)
+#define mhd_daemon_trigger_itc(d) ((void) d, ! 0)
#endif /* ! MHD_SUPPORT_THREADS */
diff --git a/src/mhd2/daemon_get_info.c b/src/mhd2/daemon_get_info.c
@@ -53,7 +53,7 @@ MHD_daemon_get_info_fixed_sz (
union MHD_DaemonInfoFixedData *MHD_RESTRICT output_buf,
size_t output_buf_size)
{
- mhd_assert (! mhd_D_HAS_MASTER(daemon));
+ mhd_assert (! mhd_D_HAS_MASTER (daemon));
if (mhd_DAEMON_STATE_STARTED > daemon->state)
return MHD_SC_TOO_EARLY;
if (mhd_DAEMON_STATE_STARTED < daemon->state)
@@ -62,7 +62,7 @@ MHD_daemon_get_info_fixed_sz (
switch (info_type)
{
case MHD_DAEMON_INFO_FIXED_POLL_SYSCALL:
- if (mhd_WM_INT_HAS_EXT_EVENTS(daemon->wmode_int))
+ if (mhd_WM_INT_HAS_EXT_EVENTS (daemon->wmode_int))
return MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE;
if (sizeof(output_buf->v_poll_syscall) > output_buf_size)
return MHD_SC_INFO_GET_BUFF_TOO_SMALL;
@@ -71,7 +71,7 @@ MHD_daemon_get_info_fixed_sz (
return MHD_SC_OK;
case MHD_DAEMON_INFO_FIXED_NUM_WORK_THREADS:
#ifdef MHD_SUPPORT_THREADS
- if (! mhd_WM_INT_HAS_THREADS(daemon->wmode_int))
+ if (! mhd_WM_INT_HAS_THREADS (daemon->wmode_int))
return MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE;
if (mhd_WM_INT_INTERNAL_EVENTS_THREAD_PER_CONNECTION == daemon->wmode_int)
return MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE;
@@ -223,7 +223,7 @@ MHD_daemon_get_info_dynamic_sz (
union MHD_DaemonInfoDynamicData *MHD_RESTRICT output_buf,
size_t output_buf_size)
{
- mhd_assert (! mhd_D_HAS_MASTER(daemon));
+ mhd_assert (! mhd_D_HAS_MASTER (daemon));
if (mhd_DAEMON_STATE_STARTED > daemon->state)
return MHD_SC_TOO_EARLY;
if (mhd_DAEMON_STATE_STARTED < daemon->state)
@@ -252,6 +252,7 @@ MHD_daemon_get_info_dynamic_sz (
res = (0 != daemon->conns.count) ? MHD_YES : MHD_NO;
else
{
+#ifdef MHD_SUPPORT_THREADS
unsigned int i;
res = MHD_NO;
mhd_assert (NULL != daemon->threading.hier.pool.workers);
@@ -263,6 +264,9 @@ MHD_daemon_get_info_dynamic_sz (
break;
}
}
+#else /* ! MHD_SUPPORT_THREADS */
+ res = MHD_NO; /* No used, mute compiler waring */
+#endif /* ! MHD_SUPPORT_THREADS */
}
output_buf->v_has_connections_bool = res;
return MHD_SC_OK;
diff --git a/src/mhd2/daemon_start.c b/src/mhd2/daemon_start.c
@@ -1272,7 +1272,7 @@ deinit_epoll (struct MHD_Daemon *restrict d)
mhd_assert ((MHD_INVALID_SOCKET != d->events.data.epoll.e_fd) || \
(mhd_WM_INT_INTERNAL_EVENTS_THREAD_POOL == d->wmode_int));
mhd_assert ((MHD_INVALID_SOCKET != d->events.data.epoll.e_fd) || \
- (mhd_DAEMON_TYPE_MASTER_CONTROL_ONLY == d->threading.d_type));
+ (mhd_D_HAS_WORKERS (d)));
if (MHD_INVALID_SOCKET != d->events.data.epoll.e_fd)
close (d->events.data.epoll.e_fd);
}
@@ -2122,7 +2122,9 @@ init_itc (struct MHD_Daemon *restrict d)
mhd_itc_set_invalid (&(d->threading.itc));
return MHD_SC_ITC_FD_OUTSIDE_OF_SET_RANGE;
}
-#endif /* MHD_SUPPORT_THREADS */
+#else /* ! MHD_SUPPORT_THREADS */
+ (void) d; /* Unused */
+#endif /* ! MHD_SUPPORT_THREADS */
return MHD_SC_OK;
}
@@ -2140,7 +2142,9 @@ deinit_itc (struct MHD_Daemon *restrict d)
// TODO: add and process "thread unsafe" daemon's option
mhd_assert (! mhd_ITC_IS_INVALID (d->threading.itc));
(void) mhd_itc_destroy (d->threading.itc);
-#endif /* MHD_SUPPORT_THREADS */
+#else /* ! MHD_SUPPORT_THREADS */
+ (void) d; /* Unused */
+#endif /* ! MHD_SUPPORT_THREADS */
}
@@ -3007,9 +3011,11 @@ daemon_init_threading_and_conn (struct MHD_Daemon *restrict d,
if (MHD_SC_OK != res)
return res;
+#ifdef MHD_SUPPORT_THREADS
d->threading.cfg.stack_size = s->stack_size;
+#endif /* MHD_SUPPORT_THREADS */
- if (! mhd_D_TYPE_HAS_WORKERS (d->threading.d_type))
+ if (! mhd_D_HAS_WORKERS (d))
res = init_individual_thread_data_events_conns (d, s);
#ifdef MHD_SUPPORT_THREADS
else
@@ -3022,7 +3028,8 @@ daemon_init_threading_and_conn (struct MHD_Daemon *restrict d,
d->threading.hier.pool.workers[0].conns.cfg.mem_pool_size;
}
}
-#endif /* ! MHD_SUPPORT_THREADS */
+#endif /* MHD_SUPPORT_THREADS */
+
if (MHD_SC_OK == res)
{
mhd_assert (d->dbg.events_allocated || \
@@ -3336,9 +3343,8 @@ daemon_stop_threads (struct MHD_Daemon *restrict d)
return;
}
#else /* ! MHD_SUPPORT_THREADS */
- mhd_assert (0 && "Impossible value");
mhd_UNREACHABLE ();
- return MHD_SC_INTERNAL_ERROR;
+ return;
#endif /* ! MHD_SUPPORT_THREADS */
}
}
diff --git a/src/mhd2/events_process.c b/src/mhd2/events_process.c
@@ -132,6 +132,7 @@ dbg_print_fd_state_update (const char *fd_name,
((void) 0)
#endif /* ! mhd_DEBUG_POLLING_FDS */
+#ifdef MHD_SUPPORT_THREADS
/**
* Log error message about broken ITC
* @param d the daemon to use
@@ -145,6 +146,8 @@ log_itc_broken (struct MHD_Daemon *restrict d)
}
+#endif /* MHD_SUPPORT_THREADS */
+
/**
* Log error message about broken listen socket
* @param d the daemon to use
@@ -173,7 +176,7 @@ mhd_daemon_get_wait_max (struct MHD_Daemon *restrict d)
#endif
return 0;
}
- if (d->threading.resume_requested) /* Remove? It is triggered by ITC anyway */
+ if (d->events.act_req.resume)
{
#ifdef mhd_DEBUG_POLLING_FDS
fprintf (stderr,
@@ -225,10 +228,10 @@ daemon_resume_conns_if_needed (struct MHD_Daemon *restrict d)
{
struct MHD_Connection *c;
- if (! d->threading.resume_requested)
+ if (! d->events.act_req.resume)
return;
- d->threading.resume_requested = false; /* Reset flag before processing data */
+ d->events.act_req.resume = false; /* Reset flag before processing data */
for (c = mhd_DLINKEDL_GET_FIRST (&(d->conns),all_conn);
NULL != c;
@@ -578,7 +581,7 @@ ext_events_process_net_updates_and_resume_conn (struct MHD_Daemon *restrict d)
mhd_assert (mhd_WM_INT_HAS_EXT_EVENTS (d->wmode_int));
mhd_assert (mhd_POLL_TYPE_EXT == d->events.poll_type);
- d->threading.resume_requested = false; /* Reset flag before processing data */
+ d->events.act_req.resume = false; /* Reset flag before processing data */
#ifdef MHD_SUPPORT_THREADS
if (d->events.data.extr.itc_data.is_active)
@@ -919,12 +922,13 @@ select_update_statuses_from_fdsets_and_resume_conn (struct MHD_Daemon *d,
mhd_assert (0 <= num_events);
mhd_assert (((unsigned int) num_events) <= d->dbg.num_events_elements);
- resuming_conn = d->threading.resume_requested;
+ resuming_conn = d->events.act_req.resume;
if (resuming_conn)
{
- mhd_assert (mhd_DAEMON_TYPE_LISTEN_ONLY != d->threading.d_type);
+ mhd_assert (! mhd_D_TYPE_IS_LISTEN_ONLY (d->threading.d_type));
+ mhd_assert (! mhd_D_HAS_THR_PER_CONN (d));
num_events = (int) -1; /* Force process all connections */
- d->threading.resume_requested = false;
+ d->events.act_req.resume = false;
}
#ifndef MHD_FAVOR_SMALL_CODE
@@ -992,7 +996,7 @@ select_update_statuses_from_fdsets_and_resume_conn (struct MHD_Daemon *d,
}
mhd_assert ((0 == num_events) || \
- (mhd_DAEMON_TYPE_LISTEN_ONLY != d->threading.d_type));
+ (! mhd_D_TYPE_IS_LISTEN_ONLY (d->threading.d_type)));
#ifdef MHD_FAVOR_SMALL_CODE
(void) num_events;
@@ -1339,7 +1343,7 @@ poll_update_statuses_from_fds (struct MHD_Daemon *restrict d,
}
mhd_assert ((0 == num_events) || \
- (mhd_DAEMON_TYPE_LISTEN_ONLY != d->threading.d_type));
+ (! mhd_D_TYPE_IS_LISTEN_ONLY (d->threading.d_type)));
for (i_c = i_s; (i_c < i_s + d->conns.count) && (0 < num_events); ++i_c)
{
@@ -1731,7 +1735,7 @@ process_all_events_and_data (struct MHD_Daemon *restrict d)
daemon_process_all_active_conns (d);
daemon_cleanup_upgraded_conns (d);
- return ! d->threading.stop_requested;
+ return ! mhd_D_HAS_STOP_REQ (d);
}
@@ -1823,6 +1827,8 @@ MHD_daemon_process_reg_events (struct MHD_Daemon *MHD_RESTRICT daemon,
}
+#ifdef MHD_SUPPORT_THREADS
+
/**
* The entry point for the daemon worker thread
* @param cls the closure
@@ -1938,3 +1944,6 @@ mhd_worker_connection (void *cls)
MHD_PANIC ("Not yet implemented");
return (mhd_THRD_RTRN_TYPE) 0;
}
+
+
+#endif /* MHD_SUPPORT_THREADS */
diff --git a/src/mhd2/events_process.h b/src/mhd2/events_process.h
@@ -31,10 +31,14 @@
#include "sys_base_types.h"
-#include "sys_thread_entry_type.h"
+#ifdef MHD_SUPPORT_THREADS
+# include "sys_thread_entry_type.h"
+#endif /* MHD_SUPPORT_THREADS */
struct MHD_Daemon; /* forward declaration */
+#ifdef MHD_SUPPORT_THREADS
+
/**
* The entry point for the daemon worker thread
* @param cls the closure
@@ -56,6 +60,8 @@ mhd_worker_listening_only (void *cls);
mhd_THRD_RTRN_TYPE mhd_THRD_CALL_SPEC
mhd_worker_connection (void *cls);
+#endif /* MHD_SUPPORT_THREADS */
+
/**
* Get maximum wait time for the daemon
* @param d the daemon to check
diff --git a/src/mhd2/mhd_connection.h b/src/mhd2/mhd_connection.h
@@ -40,7 +40,9 @@
#include "mhd_conn_socket.h"
-#include "mhd_threads.h"
+#ifdef MHD_SUPPORT_THREADS
+# include "mhd_threads.h"
+#endif
#include "mhd_tristate.h"
#include "mhd_dlinked_list.h"
diff --git a/src/mhd2/mhd_daemon.h b/src/mhd2/mhd_daemon.h
@@ -49,9 +49,10 @@
#ifdef MHD_SUPPORT_THREADS
# include "mhd_threads.h"
# include "mhd_itc_types.h"
-# include "mhd_locks.h"
#endif
+#include "mhd_locks.h"
+
#include "sys_select.h"
#include "sys_poll.h"
#ifdef MHD_SUPPORT_EPOLL
@@ -694,6 +695,7 @@ enum MHD_FIXED_ENUM_ mhd_DaemonType
#ifndef NDEBUG
= 1
#endif
+#ifdef MHD_SUPPORT_THREADS
,
/**
* A master daemon, only controlling worker daemons.
@@ -716,6 +718,7 @@ enum MHD_FIXED_ENUM_ mhd_DaemonType
* to application directly.
*/
mhd_DAEMON_TYPE_WORKER
+#endif /* MHD_SUPPORT_THREADS */
};
/**
@@ -749,6 +752,13 @@ enum MHD_FIXED_ENUM_ mhd_DaemonType
#define mhd_D_TYPE_HAS_MASTER_DAEMON(t) \
(mhd_DAEMON_TYPE_WORKER == (t))
+/**
+ * Check whether the daemon is listening only (with connection data
+ * processed in separate threads)
+ */
+#define mhd_D_TYPE_IS_LISTEN_ONLY(t) \
+ (mhd_DAEMON_TYPE_LISTEN_ONLY == (t))
+
#else /* ! MHD_SUPPORT_THREADS */
/**
@@ -777,6 +787,12 @@ enum MHD_FIXED_ENUM_ mhd_DaemonType
*/
#define mhd_D_TYPE_HAS_MASTER_DAEMON(t) (0)
+/**
+ * Check whether the daemon is listening only (with connection data
+ * processed in separate threads)
+ */
+#define mhd_D_TYPE_IS_LISTEN_ONLY(t) (0)
+
#endif /* ! MHD_SUPPORT_THREADS */
#ifdef MHD_SUPPORT_THREADS
@@ -851,11 +867,6 @@ struct mhd_DaemonThreadingData
volatile bool stop_requested;
/**
- * 'True' if resuming of any connection has been requested.
- */
- volatile bool resume_requested;
-
- /**
* The handle of the daemon's thread (if managed by the daemon)
*/
mhd_thread_handle_ID tid;
@@ -1221,6 +1232,12 @@ struct MHD_Daemon
# define mhd_D_HAS_THR_PER_CONN(d) (0)
#endif
+#ifdef MHD_SUPPORT_THREADS
+# define mhd_D_HAS_STOP_REQ(d) (d->threading.stop_requested)
+#else
+# define mhd_D_HAS_STOP_REQ(d) (0)
+#endif
+
#define mhd_D_HAS_WORKERS(d) mhd_D_TYPE_HAS_WORKERS ((d)->threading.d_type)
#define mhd_D_HAS_MASTER(d) mhd_D_TYPE_HAS_MASTER_DAEMON ((d)->threading.d_type)
diff --git a/src/mhd2/mhd_locks.h b/src/mhd2/mhd_locks.h
@@ -292,6 +292,7 @@ typedef CRITICAL_SECTION mhd_mutex;
#else /* ! MHD_SUPPORT_THREADS */
# define mhd_mutex_init(ignored) (! 0)
+# define mhd_mutex_init_short(ignored) (! 0)
# define mhd_MUTEX_INITIALISER_STAT /* empty */
# define mhd_MUTEX_STATIC_DEFN_INIT(ignored) /* nothing */
# define mhd_mutex_destroy(ignored) (! 0)
diff --git a/src/mhd2/mhd_threads.h b/src/mhd2/mhd_threads.h
@@ -38,6 +38,10 @@
#include "mhd_sys_options.h"
+#ifndef MHD_SUPPORT_THREADS
+# error Threads support disabled by configure.
+#endif
+
#if defined(mhd_THREADS_KIND_POSIX)
# include <pthread.h>
# ifndef MHD_SUPPORT_THREADS
diff --git a/src/mhd2/mhd_upgrade.h b/src/mhd2/mhd_upgrade.h
@@ -44,10 +44,12 @@ struct MHD_UpgradedHandle
*/
struct MHD_Connection *c;
+#ifdef MHD_SUPPORT_THREADS
/**
* The mutex for some operations
*/
mhd_mutex lock;
+#endif /* MHD_SUPPORT_THREADS */
};
#endif /* ! MHD_UPGRADE_H */
diff --git a/src/mhd2/request_resume.c b/src/mhd2/request_resume.c
@@ -63,6 +63,6 @@ MHD_request_resume (struct MHD_Request *request)
"%%%%%% Requested conn resume, FD: %2llu\n",
(unsigned long long) c->sk.fd);
#endif /* mhd_DEBUG_SUSPEND_RESUME */
- d->threading.resume_requested = true;
- mhd_daemon_trigger_itc (d);
+ d->events.act_req.resume = true;
+ (void) mhd_daemon_trigger_itc (d);
}