diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..7e4a144e9 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.30) + +set(CMAKE_C_STANDARD 11) + +project(qthreads + VERSION 1.22 + DESCRIPTION "A user-level threading library" + LANGUAGES C ASM) + +add_subdirectory(src) + +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + include(CTest) + add_subdirectory(test) +endif() + diff --git a/configure.ac b/configure.ac index d77276dc8..5b6608a31 100644 --- a/configure.ac +++ b/configure.ac @@ -235,7 +235,7 @@ AC_CACHE_SAVE AC_HEADER_STDC AC_HEADER_SYS_WAIT AC_HEADER_TIME -AC_CHECK_HEADERS([stdlib.h fcntl.h ucontext.h sys/time.h sys/resource.h mach/mach_time.h malloc.h math.h sys/types.h sys/sysctl.h unistd.h sys/syscall.h]) +AC_CHECK_HEADERS([stdlib.h fcntl.h ucontext.h sys/time.h sys/resource.h mach/mach_time.h malloc.h math.h sys/types.h sys/sysctl.h]) AC_CACHE_SAVE diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 000000000..d585f8143 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,52 @@ +set(QTHREADS_SCHEDULER nemesis CACHE STRING "Which scheduler to use for qthreads. Valid options are nemesis, sherwood, and distrib.") +set(QTHREADS_TOPOLOGY no CACHE STRING "Which topology detection/management system to use for qthreads. Valid options are no, hwloc, and binders.") +set(QTHREADS_BARRIER feb CACHE STRING "Which barrier implementation to use for qthreads. Valid options are feb, sinc, array, and log.") +set(QTHREADS_SINC donecount CACHE STRING "Which sinc implementation to use for qthreads. Valid options are donecount, donecoutn_cas, snzi, and original.") +set(QTHREADS_ALLOC base CACHE STRING "Wich allocation implementation to use for qthreads. Valid options are base, and chapel.") +set(QTHREADS_CACHELINE_SIZE_ESTIMATE 64 CACHE STRING "Estimate of the cacheline size of the target machine (used for optimizing data structure layouts).") +set(QTHREADS_DEFAULT_STACK_SIZE 32768 CACHE STRING "Default qthread stack size.") +set(QTHREADS_HASHMAP hashmap CACHE STRING "Which hashmap implementation to use. Valid values are \"hashmap\" and \"lf_hashmap\".") + +set(QTHREADS_SOURCES + cacheline.c + envariables.c + feb.c + hazardptrs.c + io.c + locks.c + qalloc.c + qloop.c + queue.c + barrier/${QTHREADS_BARRIER}.c + qutil.c + syncvar.c + qthread.c + mpool.c + shepherds.c + workers.c + threadqueues/${QTHREADS_SCHEDULER}_threadqueues.c + sincs/${QTHREADS_SINC}.c + alloc/${QTHREADS_ALLOC}.c + affinity/common.c + affinity/${QTHREADS_TOPOLOGY}.c + touch.c + tls.c + teams.c + fastcontext/asm.S + fastcontext/context.c + ${QTHREADS_HASHMAP}.c +) + +# TODO: switch/checks necessary to include the correct +# fastcontext version when we need the fallback. + +add_library(qthread SHARED ${QTHREADS_SOURCES}) +target_include_directories(qthread + PUBLIC "../include/qthread" + PRIVATE "../include" +) +# TODO: move these into a configure header instead of piping them through the flags. +target_compile_definitions(qthread + PRIVATE CACHELINE_WIDTH=${QTHREADS_CACHELINE_SIZE_ESTIMATE} + PRIVATE QTHREAD_DEFAULT_STACK_SIZE=${QTHREADS_DEFAULT_STACK_SIZE} +) diff --git a/src/fastcontext/asm.S b/src/fastcontext/asm.S index afdacfd7d..5f3267882 100644 --- a/src/fastcontext/asm.S +++ b/src/fastcontext/asm.S @@ -2,11 +2,6 @@ /* Portions of this file are Copyright (c) 2005-2006 Russ Cox, MIT; see COPYRIGHT */ /* Portions of this file are Copyright Sandia National Laboratories */ #endif -#ifdef HAVE_CONFIG_H -# include "config.h" -#else -# error no config.h -#endif #include "qthread/common.h" #define _(x) diff --git a/src/io.c b/src/io.c index 11b6170b1..aae8c9be1 100644 --- a/src/io.c +++ b/src/io.c @@ -8,11 +8,9 @@ #include /* for fprintf() */ #include /* for abort() */ #include /* for gettimeofday() */ -#ifdef HAVE_SYS_SYSCALL_H /* - syscall(2) */ #include #include -#endif /* - accept(2) */ #include /* - connect(2) */ diff --git a/src/syscalls/accept.c b/src/syscalls/accept.c index 6ff10b6b6..d56ee84ae 100644 --- a/src/syscalls/accept.c +++ b/src/syscalls/accept.c @@ -5,10 +5,8 @@ #include /* System Headers */ -#ifdef HAVE_SYS_SYSCALL_H #include /* for SYS_accept and others */ #include -#endif /* Public Headers */ #include "qthread/qt_syscalls.h" diff --git a/src/syscalls/connect.c b/src/syscalls/connect.c index b511337bb..111f8a6f8 100644 --- a/src/syscalls/connect.c +++ b/src/syscalls/connect.c @@ -5,10 +5,8 @@ #include /* System Headers */ -#ifdef HAVE_SYS_SYSCALL_H #include /* for SYS_accept and others */ #include -#endif /* Public Headers */ #include "qthread/qt_syscalls.h" diff --git a/src/syscalls/poll.c b/src/syscalls/poll.c index ae009ece6..f9be5f857 100644 --- a/src/syscalls/poll.c +++ b/src/syscalls/poll.c @@ -4,10 +4,8 @@ #include -#ifdef HAVE_SYS_SYSCALL_H #include /* for SYS_accept and others */ #include -#endif /* Public Headers */ #include "qthread/qt_syscalls.h" diff --git a/src/syscalls/pread.c b/src/syscalls/pread.c index 3f6e8ccde..133b59bf2 100644 --- a/src/syscalls/pread.c +++ b/src/syscalls/pread.c @@ -7,10 +7,8 @@ /* System Headers */ #include -#ifdef HAVE_SYS_SYSCALL_H #include /* for SYS_accept and others */ #include -#endif /* Public Headers */ #include "qthread/qt_syscalls.h" diff --git a/src/syscalls/pwrite.c b/src/syscalls/pwrite.c index b392a65db..db0538687 100644 --- a/src/syscalls/pwrite.c +++ b/src/syscalls/pwrite.c @@ -7,10 +7,8 @@ /* System Headers */ #include -#ifdef HAVE_SYS_SYSCALL_H #include /* for SYS_accept and others */ #include -#endif /* Public Headers */ #include "qthread/qt_syscalls.h" diff --git a/src/syscalls/read.c b/src/syscalls/read.c index 490ca94bd..1de21984a 100644 --- a/src/syscalls/read.c +++ b/src/syscalls/read.c @@ -7,10 +7,8 @@ /* System Headers */ #include -#ifdef HAVE_SYS_SYSCALL_H #include /* for SYS_accept and others */ #include -#endif /* Public Headers */ #include "qthread/qt_syscalls.h" diff --git a/src/syscalls/select.c b/src/syscalls/select.c index 2be9a2f07..01347834c 100644 --- a/src/syscalls/select.c +++ b/src/syscalls/select.c @@ -7,10 +7,8 @@ /* System Headers */ #include -#ifdef HAVE_SYS_SYSCALL_H #include /* for SYS_accept and others */ #include -#endif /* Public Headers */ #include "qthread/qt_syscalls.h" diff --git a/src/syscalls/system.c b/src/syscalls/system.c index 950e6d07a..2e2a4bfec 100644 --- a/src/syscalls/system.c +++ b/src/syscalls/system.c @@ -5,9 +5,7 @@ #include /* System Headers */ -#ifdef HAVE_SYS_SYSCALL_H #include /* for SYS_accept and others */ -#endif /* Public Headers */ #include "qthread/qt_syscalls.h" diff --git a/src/syscalls/user_defined.c b/src/syscalls/user_defined.c index aab6aa961..2b71fcea4 100644 --- a/src/syscalls/user_defined.c +++ b/src/syscalls/user_defined.c @@ -9,9 +9,7 @@ #include #include -#ifdef HAVE_SYS_SYSCALL_H #include /* for SYS_accept and others */ -#endif /* Internal Headers */ #include "qt_asserts.h" diff --git a/src/syscalls/wait4.c b/src/syscalls/wait4.c index 63b3463e2..64a05af7a 100644 --- a/src/syscalls/wait4.c +++ b/src/syscalls/wait4.c @@ -5,10 +5,8 @@ #include /* System Headers */ -#ifdef HAVE_SYS_SYSCALL_H #include /* for SYS_accept and others */ #include -#endif /* Public Headers */ #include "qthread/qt_syscalls.h" diff --git a/src/syscalls/write.c b/src/syscalls/write.c index c506aea62..d6d4bdf48 100644 --- a/src/syscalls/write.c +++ b/src/syscalls/write.c @@ -7,10 +7,8 @@ /* System Headers */ #include -#ifdef HAVE_SYS_SYSCALL_H #include /* for SYS_accept and others */ #include -#endif /* Public Headers */ #include "qthread/qt_syscalls.h" diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 000000000..e69de29bb