Fibers don't require makecontext() on Windows.
This also fixes the MinGW linker errors about pthreads. It turns out async-test.c++ uses pthreads when fibers are disabled. So when the MinGW build incorrectly decided it couldn't use fibers, it then started trying to use pthreads, which we don't link against on Windows.
diff --git a/c++/configure.ac b/c++/configure.ac
index 78bebc9..2d110a3 100644
--- a/c++/configure.ac
+++ b/c++/configure.ac
@@ -216,34 +216,43 @@
])
])
-# Fibers need the symbols getcontext, setcontext, swapcontext and makecontext.
-# We assume that makecontext implies the rest.
+# Check for library support necessary for fibers.
AS_IF([test "$with_fibers" != no], [
- libc_supports_fibers=yes
- AC_SEARCH_LIBS([makecontext], [], [], [
- libc_supports_fibers=no
- ])
-
- AS_IF([test "$libc_supports_fibers" = yes], [
+ case "${host_os}" in
+ cygwin* | mingw* )
+ # Fibers always work on Windows, where there's an explicit API for them.
with_fibers=yes
- ], [
- # If getcontext does not exist in libc, try with libucontext
- ucontext_supports_fibers=yes
- AC_CHECK_LIB(ucontext, [makecontext], [], [
- ucontext_supports_fibers=no
- ])
- AS_IF([test "$ucontext_supports_fibers" = yes], [
- ASYNC_LIBS="$ASYNC_LIBS -lucontext"
- with_fibers=yes
- ], [
- AS_IF([test "$with_fibers" = yes], [
- AC_MSG_ERROR([Missing symbols required for fibers (makecontext, setcontext, ...). Disable fibers (--without-fibers) or install libucontext])
- ], [
- AC_MSG_WARN([could not find required symbols (makecontext, setcontext, ...) -- won't build with fibers])
- with_fibers=no
+ ;;
+ * )
+ # Fibers need the symbols getcontext, setcontext, swapcontext and makecontext.
+ # We assume that makecontext implies the rest.
+ libc_supports_fibers=yes
+ AC_SEARCH_LIBS([makecontext], [], [], [
+ libc_supports_fibers=no
])
- ])
- ])
+
+ AS_IF([test "$libc_supports_fibers" = yes], [
+ with_fibers=yes
+ ], [
+ # If getcontext does not exist in libc, try with libucontext
+ ucontext_supports_fibers=yes
+ AC_CHECK_LIB(ucontext, [makecontext], [], [
+ ucontext_supports_fibers=no
+ ])
+ AS_IF([test "$ucontext_supports_fibers" = yes], [
+ ASYNC_LIBS="$ASYNC_LIBS -lucontext"
+ with_fibers=yes
+ ], [
+ AS_IF([test "$with_fibers" = yes], [
+ AC_MSG_ERROR([Missing symbols required for fibers (makecontext, setcontext, ...). Disable fibers (--without-fibers) or install libucontext])
+ ], [
+ AC_MSG_WARN([could not find required symbols (makecontext, setcontext, ...) -- won't build with fibers])
+ with_fibers=no
+ ])
+ ])
+ ])
+ ;;
+ esac
])
AS_IF([test "$with_fibers" = yes], [
CXXFLAGS="$CXXFLAGS -DKJ_USE_FIBERS"
diff --git a/c++/src/kj/async-test.c++ b/c++/src/kj/async-test.c++
index fe11665..0672caf 100644
--- a/c++/src/kj/async-test.c++
+++ b/c++/src/kj/async-test.c++
@@ -25,7 +25,7 @@
#include "mutex.h"
#include "thread.h"
-#if !KJ_USE_FIBERS
+#if !KJ_USE_FIBERS && !_WIN32
#include <pthread.h>
#endif
@@ -737,6 +737,10 @@
EXPECT_EQ(1u, errorHandler.exceptionCount);
}
+#if KJ_USE_FIBERS || !_WIN32
+// This test requires either fibers or pthreads in order to limit the stack size. Currently we
+// don't have a version that works on Windows without fibers, so skip the test there.
+
TEST(Async, LargeTaskSetDestruction) {
static constexpr size_t stackSize = 200 * 1024;
@@ -776,6 +780,8 @@
#endif
}
+#endif // KJ_USE_FIBERS || !_WIN32
+
TEST(Async, TaskSet) {
EventLoop loop;
WaitScope waitScope(loop);