diff --git a/.gitignore b/.gitignore index fabec22f..38dcdf6d 100644 --- a/.gitignore +++ b/.gitignore @@ -103,6 +103,7 @@ Release-64/ *.scc *.exe *.a +*.manifest # Visual C++ cache files ipch/ diff --git a/Bmakefile b/Bmakefile index c6bcf93d..e00fffb2 100644 --- a/Bmakefile +++ b/Bmakefile @@ -7,14 +7,14 @@ # -DLL_VER = 2 +PTW32_VER = 3 DEVROOT = . DLLDEST = $(DEVROOT)\DLL LIBDEST = $(DEVROOT)\DLL -DLLS = pthreadBC$(DLL_VER).dll +DLLS = pthreadBC$(PTW32_VER).dll OPTIM = /O2 diff --git a/CMakeLists.txt b/CMakeLists.txt index 91f83a39..b6697f9b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,26 +1,155 @@ -cmake_minimum_required(VERSION 3.8) -project(pthread) - -# STATIC library pthread -set(PUBLIC_INTERFACE pthread.h sched.h semaphore.h) -set(PRIVATE_SOURCES pthread.c) # everything is in pthread.c -file(GLOB PRIVATE_HEADERS *.h) -source_group(include FILES ${PRIVATE_HEADERS}) -source_group(src FILES ${PRIVATE_SOURCES}) - -include_directories(".") -add_library(pthread STATIC ${PRIVATE_HEADERS} ${PRIVATE_SOURCES}) -target_compile_definitions(pthread PRIVATE - -DPTW32_STATIC_LIB=1 - -DHAVE_CONFIG_H=1 -) +cmake_minimum_required(VERSION 3.11) + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "MinSizeRel" CACHE STRING "Choose the type of build, options are: Debug, Release, or MinSizeRel." FORCE) + message(STATUS "No build type specified, defaulting to MinSizeRel.") +endif() + +set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_SOURCE_DIR}/cmake") + +include (get_version) + +message(STATUS "Generator ......... ${CMAKE_GENERATOR}") +message(STATUS "Build Type ........ ${CMAKE_BUILD_TYPE}") +message(STATUS "Version ........... ${PTHREADS4W_VERSION}") + +project(pthreads4w VERSION ${PTHREADS4W_VERSION} LANGUAGES C) + +set(PTW32_VER ${PROJECT_VERSION_MAJOR}${EXTRAVERSION}) +set(CMAKE_DEBUG_POSTFIX d) + +# Uncomment this if config.h defines RETAIN_WSALASTERROR +#set(XLIBS wsock32.lib) + + +include_directories(.) + +################################# +# Target Arch # +################################# +include (target_arch) + +get_target_arch(TARGET_ARCH) + +if(${TARGET_ARCH} STREQUAL "ARM") + add_definitions(-DPTW32_ARCHARM -D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1) +elseif(${TARGET_ARCH} STREQUAL "ARM64") + add_definitions(-DPTW32_ARCHARM64 -D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1) +elseif(${TARGET_ARCH} STREQUAL "x86_64") + add_definitions(-DPTW32_ARCHAMD64) +elseif(${TARGET_ARCH} STREQUAL "x86") + add_definitions(-DPTW32_ARCHX86) +elseif(${TARGET_ARCH} STREQUAL "x64") + add_definitions(-DPTW32_ARCHX64) +else() + MESSAGE(ERROR "\"${TARGET_ARCH}\" not supported in version.rc") +endif() +message(STATUS "Target ............ ${TARGET_ARCH}") + +if(MSVC) + message(STATUS "MSVC Version ...... ${MSVC_VERSION}") +endif() + +################################# +# Install Path # +################################# +if(DIST_ROOT) + set(CMAKE_INSTALL_PREFIX "${DIST_ROOT}") +else() + set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/PTHREADS-BUILT") +endif() +message(STATUS "Install Path ${CMAKE_INSTALL_PREFIX}") + + +set(DLLDEST ${CMAKE_INSTALL_PREFIX}/${TARGET_ARCH}/${CMAKE_BUILD_TYPE}/bin) +set(LIBDEST ${CMAKE_INSTALL_PREFIX}/${TARGET_ARCH}/${CMAKE_BUILD_TYPE}/lib) +set(HDRDEST ${CMAKE_INSTALL_PREFIX}/${TARGET_ARCH}/${CMAKE_BUILD_TYPE}/include) +set(TESTDEST ${CMAKE_INSTALL_PREFIX}/${TARGET_ARCH}/${CMAKE_BUILD_TYPE}/test) + +################################# +# Defs # +################################# +add_definitions(-DPTW32_BUILD_INLINED) if(MSVC) - add_compile_options(/Gm-) - add_link_options(/ignore:4006) + + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /errorReport:none /nologo ") + + # C++ Exceptions + # (Note: If you are using Microsoft VC++6.0, the library needs to be built + # with /EHa instead of /EHs or else cancellation won't work properly.) + if(MSVC_VERSION EQUAL 1200) + set(VCEFLAGS "/EHa /TP ") + else() + set(VCEFLAGS "/EHs /TP ") + endif() + + add_definitions(-DHAVE_CONFIG_H -DPTW32_RC_MSC) + +endif() + +# Update filename with proper version info +configure_file(${CMAKE_SOURCE_DIR}/cmake/version.rc.in ${CMAKE_BINARY_DIR}/version.rc @ONLY) + +################################# +# Libraries # +################################# +set(targ_suffix "") +if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") + set(targ_suffix ${CMAKE_DEBUG_POSTFIX}) endif() -install(FILES ${PUBLIC_INTERFACE} DESTINATION include) -install(TARGETS pthread - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib) +macro(shared_lib type def) + set(targ pthread${type}${PTW32_VER}) + add_library(${targ} SHARED pthread.c ${CMAKE_BINARY_DIR}/version.rc) + message(STATUS ${targ}) + target_compile_definitions(${targ} PUBLIC "-D${def}") + if(${type} STREQUAL "VCE") + set_target_properties(${targ} PROPERTIES COMPILE_FLAGS ${VCEFLAGS}) + endif() + if(${CMAKE_GENERATOR} MATCHES "Visual Studio") + install(FILES ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${targ}${targ_suffix}.dll DESTINATION ${DLLDEST}) + install(FILES ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${targ}${targ_suffix}.lib DESTINATION ${LIBDEST}) + else() + install(FILES ${CMAKE_BINARY_DIR}/${targ}${targ_suffix}.dll DESTINATION ${DLLDEST}) + install(FILES ${CMAKE_BINARY_DIR}/${targ}${targ_suffix}.lib DESTINATION ${LIBDEST}) + endif() +endmacro() + +macro(static_lib type def) + set(targ libpthread${type}${PTW32_VER}) + add_library(${targ} STATIC pthread.c) + message(STATUS ${targ}) + target_compile_definitions(${targ} PUBLIC "-D${def}" -DPTW32_STATIC_LIB) + if(${type} STREQUAL "VCE") + set_target_properties(${targ} PROPERTIES COMPILE_FLAGS ${VCEFLAGS}) + endif() + if(${CMAKE_GENERATOR} MATCHES "Visual Studio") + install(FILES ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${targ}${targ_suffix}.lib DESTINATION ${LIBDEST}) + else() + install(FILES ${CMAKE_BINARY_DIR}/${targ}${targ_suffix}.lib DESTINATION ${LIBDEST}) + endif() +endmacro() + +shared_lib ( VCE PTW32_CLEANUP_CXX ) +shared_lib ( VSE PTW32_CLEANUP_SEH ) +shared_lib ( VC PTW32_CLEANUP_C ) + +static_lib ( VCE PTW32_CLEANUP_CXX ) +static_lib ( VSE PTW32_CLEANUP_SEH ) +static_lib ( VC PTW32_CLEANUP_C ) + +################################# +# Install # +################################# +install(FILES _ptw32.h pthread.h sched.h semaphore.h DESTINATION ${HDRDEST}) + +################################# +# Test # +################################# +option(ENABLE_TESTS "Enable Test code build" FALSE) + +#TODO determine if cross compile... +if(ENABLE_TESTS) + add_subdirectory(tests) +endif() diff --git a/GNUmakefile.in b/GNUmakefile.in new file mode 100644 index 00000000..77e0e81f --- /dev/null +++ b/GNUmakefile.in @@ -0,0 +1,411 @@ +# @configure_input@ +# -------------------------------------------------------------------------- +# +# pthreads-win32 / pthreads4w - POSIX Threads for Windows +# Copyright 1998 John E. Bossom +# Copyright(C) 1999-2021 pthreads-win32 / pthreads4w contributors +# +# Homepage: http://sources.redhat.com/pthreads-win32 +# +# The current list of contributors is contained +# in the file CONTRIBUTORS included with the source +# code distribution. The list can also be seen at the +# following World Wide Web location: +# +# https://sourceforge.net/p/pthreads4w/wiki/Contributors/ +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library in the file COPYING.LIB; +# if not, write to the Free Software Foundation, Inc., +# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA +# +# -------------------------------------------------------------------------- +# +PACKAGE = @PACKAGE_TARNAME@ +VERSION = @PACKAGE_VERSION@ + +PTW32_VER = 3$(EXTRAVERSION) + +# See pthread.h and README for the description of version numbering. +PTW32_VERD = $(PTW32_VER)d + +srcdir = @srcdir@ +builddir = @builddir@ +VPATH = @srcdir@ + +# FIXME: Replace these path name references with autoconf standards. +DESTROOT = ../PTHREADS-BUILT +DLLDEST = $(DESTROOT)/bin +LIBDEST = $(DESTROOT)/lib +HDRDEST = $(DESTROOT)/include +# i.e. +# +prefix = @prefix@ +exec_prefix = @exec_prefix@ +bindir = ${DESTDIR}@bindir@ +includedir = ${DESTDIR}@includedir@ +libdir = ${DESTDIR}@libdir@ + +# FIXME: This is correct for a static library; a DLL import library +# should be called libpthread.dll.a, or some such. +DEST_LIB_NAME = libpthread + +# If Running MsysDTK +RM = rm -f +MV = mv -f +CP = cp -f +GREP = grep +MKDIR = mkdir -p +ECHO = echo +TESTNDIR = test ! -d +TESTFILE = test -f +AND = && +COUNT_UNIQ = uniq -c + +# If not. +#RM = erase +#MV = rename +#CP = copy +#MKDIR = mkdir +#ECHO = echo +#TESTNDIR = if exist +#TESTFILE = if exist +# AND = + +# For cross compiling use e.g. +# make CROSS=x86_64-w64-mingw32- clean GC-inlined +# FIXME: To be removed; autoconf handles this transparently; +# DO NOT use this non-standard feature. +#CROSS = + +CC = @CC@ +CXX = @CXX@ + +AR = @AR@ +DLLTOOL = @DLLTOOL@ +RANLIB = @RANLIB@ +RC = @RC@ +OD_PRIVATE = @OBJDUMP@ -p + +# Build for non-native architecture. E.g. "-m64" "-m32" etc. +# Not tested fully, needs gcc built with "--enable-multilib" +# Check your "gcc -v" output for the options used to build your gcc. +# You can set this as a shell variable or on the make comand line. +# You don't need to uncomment it here unless you want to hardwire +# a value. +#ARCH = + +# +# Look for targets that $(RC) (usually windres) supports then look at any object +# file just built to see which target the compiler used and set the $(RC) target +# to match it. +# +KNOWN_TARGETS := pe-% pei-% elf32-% elf64-% srec symbolsrec verilog tekhex binary ihex +SUPPORTED_TARGETS := $(filter $(KNOWN_TARGETS),$(shell $(RC) --help)) +RC_TARGET = --target $(firstword $(filter $(SUPPORTED_TARGETS),$(shell $(OD_PRIVATE) *.$(OBJEXT)))) + +OPT = $(CLEANUP) -O3 # -finline-functions -findirect-inlining +XOPT = + +RCFLAGS = --include-dir=${srcdir} +LFLAGS = $(ARCH) +# Uncomment this if config.h defines RETAIN_WSALASTERROR +# FIXME: autoconf (or GNU make) convention dictates that this should be +# LIBS (or LDLIBS); ideally, it should be set by configure. +#LFLAGS += -lws2_32 +# +# Uncomment this next to link the GCC/C++ runtime libraries statically +# (Be sure to read about these options and their associated caveats +# at http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html) +# +# NOTE 1: Doing this appears to break GCE:pthread_cleanup_*(), which +# relies on C++ class destructors being called when leaving scope. +# +# NOTE 2: If you do this DO NOT distribute your pthreads DLLs with +# the official filenaming, i.e. pthreadVC2.dll, etc. Instead, change PTW32_VER +# above to "2slgcc" for example, to build "pthreadGC2slgcc.dll", etc. +# +# FIXME: in this case, convention would have us use LDFLAGS; once again, if +# we really want this, we should support it via a configure script option. +#LFLAGS += -static-libgcc -static-libstdc++ + +# ---------------------------------------------------------------------- +# The library can be built with some alternative behaviour to +# facilitate development of applications on Win32 that will be ported +# to other POSIX systems. Nothing definable here will make the library +# non-compliant, but applications that make assumptions that POSIX +# does not garrantee may fail or misbehave under some settings. +# +# PTW32_THREAD_ID_REUSE_INCREMENT +# Purpose: +# POSIX says that applications should assume that thread IDs can be +# recycled. However, Solaris and some other systems use a [very large] +# sequence number as the thread ID, which provides virtual uniqueness. +# pthreads-win32 provides pseudo-unique IDs when the default increment +# (1) is used, but pthread_t is not a scalar type like Solaris's. +# +# Usage: +# Set to any value in the range: 0 <= value <= 2^wordsize +# +# Examples: +# Set to 0 to emulate non recycle-unique behaviour like Linux or *BSD. +# Set to 1 for recycle-unique thread IDs (this is the default). +# Set to some other +ve value to emulate smaller word size types +# (i.e. will wrap sooner). +# +#PTW32_FLAGS = "-DPTW32_THREAD_ID_REUSE_INCREMENT=0" +# +# ---------------------------------------------------------------------- + +GC_CFLAGS = $(PTW32_FLAGS) +GCE_CFLAGS = $(PTW32_FLAGS) -mthreads + +## Mingw +#MAKE ?= make +DEFS = @DEFS@ -DPTW32_BUILD +CFLAGS = $(OPT) $(XOPT) $(ARCH) -I. -I${srcdir} $(DEFS) -Wall + +OBJEXT = @OBJEXT@ +OEXT = @OBJEXT@ +RESEXT = @OBJEXT@ + +include ${srcdir}/common.mk + +DLL_OBJS += $(RESOURCE_OBJS) +STATIC_OBJS += $(RESOURCE_OBJS) +STATIC_OBJS_SMALL += $(RESOURCE_OBJS) + +GCE_DLL = pthreadGCE$(PTW32_VER).dll +GCED_DLL= pthreadGCE$(PTW32_VERD).dll +GCE_LIB = libpthreadGCE$(PTW32_VER).a +GCED_LIB= libpthreadGCE$(PTW32_VERD).a + +GC_DLL = pthreadGC$(PTW32_VER).dll +GCD_DLL = pthreadGC$(PTW32_VERD).dll +GC_LIB = libpthreadGC$(PTW32_VER).a +GCD_LIB = libpthreadGC$(PTW32_VERD).a +GC_INLINED_STATIC_STAMP = libpthreadGC$(PTW32_VER).inlined_static_stamp +GCD_INLINED_STATIC_STAMP = libpthreadGC$(PTW32_VERD).inlined_static_stamp +GCE_INLINED_STATIC_STAMP = libpthreadGCE$(PTW32_VER).inlined_static_stamp +GCED_INLINED_STATIC_STAMP = libpthreadGCE$(PTW32_VERD).inlined_static_stamp +GC_SMALL_STATIC_STAMP = libpthreadGC$(PTW32_VER).small_static_stamp +GCD_SMALL_STATIC_STAMP = libpthreadGC$(PTW32_VERD).small_static_stamp +GCE_SMALL_STATIC_STAMP = libpthreadGCE$(PTW32_VER).small_static_stamp +GCED_SMALL_STATIC_STAMP = libpthreadGCE$(PTW32_VERD).small_static_stamp + +PTHREAD_DEF = pthread.def + +help: + @ echo "Run one of the following command lines:" + @ echo "$(MAKE) clean all (build targets GC, GCE, GC-static, GCE-static)" + @ echo "$(MAKE) clean all-tests (build and test all non-debug targets below)" + @ echo "$(MAKE) clean GC (to build the GNU C dll with C cleanup code)" + @ echo "$(MAKE) clean GC-debug (to build the GNU C debug dll with C cleanup code)" + @ echo "$(MAKE) clean GCE (to build the GNU C dll with C++ exception handling)" + @ echo "$(MAKE) clean GCE-debug (to build the GNU C debug dll with C++ exception handling)" + @ echo "$(MAKE) clean GC-static (to build the GNU C static lib with C cleanup code)" + @ echo "$(MAKE) clean GC-static-debug (to build the GNU C static debug lib with C cleanup code)" + @ echo "$(MAKE) clean GCE-static (to build the GNU C++ static lib with C++ cleanup code)" + @ echo "$(MAKE) clean GCE-static-debug (to build the GNU C++ static debug lib with C++ cleanup code)" + @ echo "$(MAKE) clean GC-small-static (to build the GNU C static lib with C cleanup code)" + @ echo "$(MAKE) clean GC-small-static-debug (to build the GNU C static debug lib with C cleanup code)" + @ echo "$(MAKE) clean GCE-small-static (to build the GNU C++ static lib with C++ cleanup code)" + @ echo "$(MAKE) clean GCE-small-static-debug (to build the GNU C++ static debug lib with C++ cleanup code)" + +all: + @ $(MAKE) clean GC + @ $(MAKE) clean GCE + @ $(MAKE) clean GC-static + @ $(MAKE) clean GCE-static + +TEST_ENV = PTW32_FLAGS="$(PTW32_FLAGS) -DNO_ERROR_DIALOGS" PTW32_VER=$(PTW32_VER) ARCH="$(ARCH)" + +all-tests: + $(MAKE) realclean GC + cd tests && $(MAKE) clean GC $(TEST_ENV) && $(MAKE) clean GCX $(TEST_ENV) + $(MAKE) realclean GCE + cd tests && $(MAKE) clean GCE $(TEST_ENV) + $(MAKE) realclean GC-static + cd tests && $(MAKE) clean GC-static $(TEST_ENV) && $(MAKE) clean GCX-static $(TEST_ENV) + $(MAKE) realclean GCE-static + cd tests && $(MAKE) clean GCE-static $(TEST_ENV) + $(MAKE) realclean GC-small-static + cd tests && $(MAKE) clean GC-small-static $(TEST_ENV) && $(MAKE) clean GCX-small-static $(TEST_ENV) + $(MAKE) realclean GCE-small-static + cd tests && $(MAKE) clean GCE-small-static $(TEST_ENV) + $(MAKE) realclean + @ - $(GREP) Passed *.log | $(COUNT_UNIQ) + @ - $(GREP) FAILED *.log + +all-tests-cflags: + $(MAKE) all-tests PTW32_FLAGS="-Wall -Wextra" + @ $(ECHO) "$@ completed." + +GC: + $(MAKE) XOPT="-DPTW32_BUILD_INLINED" CLEANUP=-DPTW32_CLEANUP_C XC_FLAGS="$(GC_CFLAGS)" OBJ="$(DLL_OBJS)" $(GC_DLL) + +GC-debug: + $(MAKE) XOPT="-DPTW32_BUILD_INLINED" CLEANUP=-DPTW32_CLEANUP_C XC_FLAGS="$(GC_CFLAGS)" OBJ="$(DLL_OBJS)" PTW32_VER=$(PTW32_VERD) OPT="-DPTW32_CLEANUP_C -g -O0" $(GCD_DLL) + +GCE: + $(MAKE) XOPT="-DPTW32_BUILD_INLINED" CC=$(CXX) CLEANUP=-DPTW32_CLEANUP_CXX XC_FLAGS="$(GCE_CFLAGS)" OBJ="$(DLL_OBJS)" $(GCE_DLL) + +GCE-debug: + $(MAKE) XOPT="-DPTW32_BUILD_INLINED" CC=$(CXX) CLEANUP=-DPTW32_CLEANUP_CXX XC_FLAGS="$(GCE_CFLAGS)" OBJ="$(DLL_OBJS)" PTW32_VER=$(PTW32_VERD) OPT="-DPTW32_CLEANUP_CXX -g -O0" $(GCED_DLL) + +GC-static: + $(MAKE) XOPT="-DPTW32_BUILD_INLINED -DPTW32_STATIC_LIB" CLEANUP=-DPTW32_CLEANUP_C XC_FLAGS="$(GC_CFLAGS)" OBJ="$(STATIC_OBJS)" $(GC_INLINED_STATIC_STAMP) + +GC-static-debug: + $(MAKE) XOPT="-DPTW32_BUILD_INLINED -DPTW32_STATIC_LIB" CLEANUP=-DPTW32_CLEANUP_C XC_FLAGS="$(GC_CFLAGS)" OBJ="$(STATIC_OBJS)" PTW32_VER=$(PTW32_VERD) OPT="-DPTW32_CLEANUP_C -g -O0" $(GCD_INLINED_STATIC_STAMP) + +GC-small-static: + $(MAKE) XOPT="-DPTW32_STATIC_LIB" CLEANUP=-DPTW32_CLEANUP_C XC_FLAGS="$(GC_CFLAGS)" OBJ="$(STATIC_OBJS_SMALL)" $(GC_SMALL_STATIC_STAMP) + +GC-small-static-debug: + $(MAKE) XOPT="-DPTW32_STATIC_LIB" CLEANUP=-DPTW32_CLEANUP_C XC_FLAGS="$(GC_CFLAGS)" OBJ="$(STATIC_OBJS_SMALL)" PTW32_VER=$(PTW32_VERD) OPT="-DPTW32_CLEANUP_C -g -O0" $(GCD_SMALL_STATIC_STAMP) + +GCE-static: + $(MAKE) XOPT="-DPTW32_BUILD_INLINED -DPTW32_STATIC_LIB" CC=$(CXX) CLEANUP=-DPTW32_CLEANUP_CXX XC_FLAGS="$(GCE_CFLAGS)" OBJ="$(STATIC_OBJS)" $(GCE_INLINED_STATIC_STAMP) + +GCE-static-debug: + $(MAKE) XOPT="-DPTW32_BUILD_INLINED -DPTW32_STATIC_LIB" CC=$(CXX) CLEANUP=-DPTW32_CLEANUP_CXX XC_FLAGS="$(GCE_CFLAGS)" OBJ="$(STATIC_OBJS)" PTW32_VER=$(PTW32_VERD) OPT="-DPTW32_CLEANUP_C -g -O0" $(GCED_INLINED_STATIC_STAMP) + +GCE-small-static: + $(MAKE) XOPT="-DPTW32_STATIC_LIB" CC=$(CXX) CLEANUP=-DPTW32_CLEANUP_CXX XC_FLAGS="$(GCE_CFLAGS)" OBJ="$(STATIC_OBJS_SMALL)" $(GCE_SMALL_STATIC_STAMP) + +GCE-small-static-debug: + $(MAKE) XOPT="-DPTW32_STATIC_LIB" CC=$(CXX) CLEANUP=-DPTW32_CLEANUP_CXX XC_FLAGS="$(GCE_CFLAGS)" OBJ="$(STATIC_OBJS_SMALL)" PTW32_VER=$(PTW32_VERD) OPT="-DPTW32_CLEANUP_C -g -O0" $(GCED_SMALL_STATIC_STAMP) + +tests: + @ cd tests + @ $(MAKE) auto + +# Very basic install. + +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +mkinstalldirs = @MKDIR_P@ $1 + +.PHONY: install installdirs install-headers +.PHONY: install-dlls install-lib-default install-libs-specific + +install: installdirs install-headers install-libs install-dlls + +installdirs: ${bindir} ${includedir} ${libdir} +${bindir} ${includedir} ${libdir}:; $(call mkinstalldirs,$@) + +install-dlls: $(wildcard ${builddir}/pthreadGC*.dll) + $(INSTALL_DATA) $^ ${bindir} + +install-libs: install-libs-specific +install-libs-specific: $(wildcard ${builddir}/libpthreadGC*.a) + $(INSTALL_DATA) $^ ${libdir} + +default_libs = $(wildcard $(addprefix $1,$(PTW32_VER)$2 $(PTW32_VERD)$2)) + +# FIXME: this is a ghastly, utterly non-deterministic hack; who knows +# what it's going to install as the default libpthread.a? Better to +# just explicitly make it a copy of libpthreadGC$(PTW32_VER).a +install-libs: install-lib-default +install-lib-default: $(call default_libs,libpthreadGC,.a) +install-lib-default: $(call default_libs,libpthreadGCE,.a) + $(INSTALL_DATA) $(lastword $^) ${libdir}/$(DEST_LIB_NAME).a + +# FIXME: similarly, who knows what this will install? Once again, it +# would be better to explicitly install libpthread.dll.a as a copy of +# libpthreadGC$(PTW32_VER).dll.a +install-libs: install-implib-default +install-implib-default: $(call default_libs,libpthreadGC,.dll.a) +install-implib-default: $(call default_libs,libpthreadGCE,.dll.a) + $(INSTALL_DATA) $(lastword $^) ${libdir}/$(DEST_LIB_NAME).dll.a + +install-headers: pthread.h sched.h semaphore.h _ptw32.h + $(INSTALL_DATA) $^ ${includedir} + +%.pre: %.c + $(CC) -E -o $@ $(CFLAGS) $^ + +%.s: %.c + $(CC) -c $(CFLAGS) -DPTW32_BUILD_INLINED -Wa,-ahl $^ > $@ + +%.o: %.rc + $(RC) $(RC_TARGET) $(RCFLAGS) $(CLEANUP) -o $@ -i $< + +.SUFFIXES: .dll .rc .c .o + +.c.o: + $(CC) -c -o $@ $(CFLAGS) $(XC_FLAGS) $< + + +$(GC_DLL) $(GCD_DLL): $(DLL_OBJS) + $(CC) $(OPT) -shared -o $@ $^ $(LFLAGS) + $(DLLTOOL) -z pthread.def $^ + $(DLLTOOL) -k --dllname $@ --output-lib lib$@.a --def $(PTHREAD_DEF) + +$(GCE_DLL) $(GCED_DLL): $(DLL_OBJS) + $(CC) $(OPT) -mthreads -shared -o $@ $^ $(LFLAGS) + $(DLLTOOL) -z pthread.def $^ + $(DLLTOOL) -k --dllname $@ --output-lib lib$@.a --def $(PTHREAD_DEF) + +$(GC_INLINED_STATIC_STAMP) $(GCE_INLINED_STATIC_STAMP) $(GCD_INLINED_STATIC_STAMP) $(GCED_INLINED_STATIC_STAMP): $(STATIC_OBJS) + $(RM) $(basename $@).a + $(AR) -rsv $(basename $@).a $^ + $(ECHO) touched > $@ + +$(GC_SMALL_STATIC_STAMP) $(GCE_SMALL_STATIC_STAMP) $(GCD_SMALL_STATIC_STAMP) $(GCED_SMALL_STATIC_STAMP): $(STATIC_OBJS_SMALL) + $(RM) $(basename $@).a + $(AR) -rsv $(basename $@).a $^ + $(ECHO) touched > $@ + +clean: + -$(RM) *~ + -$(RM) *.i + -$(RM) *.s + -$(RM) *.o + -$(RM) *.obj + -$(RM) *.exe + -$(RM) *.manifest + -$(RM) $(PTHREAD_DEF) + -cd tests && $(MAKE) clean + +realclean: clean + -$(RM) lib*.a + -$(RM) *.lib + -$(RM) pthread*.dll + -$(RM) *_stamp + -$(RM) make.log.txt + -cd tests && $(MAKE) realclean + +var_check_list = + +define var_check_target +var-check-$(1): + @for src in $($(1)); do \ + fgrep -q "\"$$$$src\"" $(2) && continue; \ + echo "$$$$src is in \$$$$($(1)), but not in $(2)"; \ + exit 1; \ + done + @grep '^# *include *".*\.c"' $(2) | cut -d'"' -f2 | while read src; do \ + echo " $($(1)) " | fgrep -q " $$$$src " && continue; \ + echo "$$$$src is in $(2), but not in \$$$$($(1))"; \ + exit 1; \ + done + @echo "$(1) <-> $(2): OK" + +var_check_list += var-check-$(1) +endef + +$(eval $(call var_check_target,PTHREAD_SRCS,pthread.c)) + +srcs-vars-check: $(var_check_list) diff --git a/Makefile b/Makefile index e6c3508d..3d7242f8 100644 --- a/Makefile +++ b/Makefile @@ -3,38 +3,37 @@ # The variables $DLLDEST and $LIBDEST hold the destination directories for the # dll and the lib, respectively. Probably all that needs to change is $DEVROOT. -# DLL_VER: +# PTW32_VER: # See pthread.h and README for the description of version numbering. -DLL_VER = 2$(EXTRAVERSION) -DLL_VERD= $(DLL_VER)d +PTW32_VER = 3$(EXTRAVERSION) +PTW32_VER_DEBUG= $(PTW32_VER)d DESTROOT = ..\PTHREADS-BUILT -DEST_LIB_NAME = pthread.lib DLLDEST = $(DESTROOT)\bin LIBDEST = $(DESTROOT)\lib HDRDEST = $(DESTROOT)\include -DLLS = pthreadVCE$(DLL_VER).dll pthreadVSE$(DLL_VER).dll pthreadVC$(DLL_VER).dll \ - pthreadVCE$(DLL_VERD).dll pthreadVSE$(DLL_VERD).dll pthreadVC$(DLL_VERD).dll -INLINED_STATIC_STAMPS = pthreadVCE$(DLL_VER).inlined_static_stamp pthreadVSE$(DLL_VER).inlined_static_stamp \ - pthreadVC$(DLL_VER).inlined_static_stamp pthreadVCE$(DLL_VERD).inlined_static_stamp \ - pthreadVSE$(DLL_VERD).inlined_static_stamp pthreadVC$(DLL_VERD).inlined_static_stamp -SMALL_STATIC_STAMPS = pthreadVCE$(DLL_VER).small_static_stamp pthreadVSE$(DLL_VER).small_static_stamp \ - pthreadVC$(DLL_VER).small_static_stamp pthreadVCE$(DLL_VERD).small_static_stamp \ - pthreadVSE$(DLL_VERD).small_static_stamp pthreadVC$(DLL_VERD).small_static_stamp +DLLS = pthreadVCE$(PTW32_VER).dll pthreadVSE$(PTW32_VER).dll pthreadVC$(PTW32_VER).dll \ + pthreadVCE$(PTW32_VER_DEBUG).dll pthreadVSE$(PTW32_VER_DEBUG).dll pthreadVC$(PTW32_VER_DEBUG).dll +INLINED_STATIC_STAMPS = pthreadVCE$(PTW32_VER).inlined_static_stamp pthreadVSE$(PTW32_VER).inlined_static_stamp \ + pthreadVC$(PTW32_VER).inlined_static_stamp pthreadVCE$(PTW32_VER_DEBUG).inlined_static_stamp \ + pthreadVSE$(PTW32_VER_DEBUG).inlined_static_stamp pthreadVC$(PTW32_VER_DEBUG).inlined_static_stamp +SMALL_STATIC_STAMPS = pthreadVCE$(PTW32_VER).small_static_stamp pthreadVSE$(PTW32_VER).small_static_stamp \ + pthreadVC$(PTW32_VER).small_static_stamp pthreadVCE$(PTW32_VER_DEBUG).small_static_stamp \ + pthreadVSE$(PTW32_VER_DEBUG).small_static_stamp pthreadVC$(PTW32_VER_DEBUG).small_static_stamp -CC = cl +CC = cl /errorReport:none /nologo CPPFLAGS = /I. /DHAVE_CONFIG_H -XCFLAGS = /W3 /MD /nologo -CFLAGS = /O2 /Ob2 $(XCFLAGS) -CFLAGSD = /Z7 $(XCFLAGS) +XCFLAGS = +CFLAGS = /W3 /O2 /Ob2 $(XCFLAGS) +CFLAGSD = /W3 /Z7 $(XCFLAGS) # Uncomment this if config.h defines RETAIN_WSALASTERROR #XLIBS = wsock32.lib # Default cleanup style -CLEANUP = __CLEANUP_C +CLEANUP = PTW32_CLEANUP_C # C++ Exceptions # (Note: If you are using Microsoft VC++6.0, the library needs to be built @@ -48,137 +47,148 @@ VSEFLAGSD = $(CPPFLAGS) $(CFLAGSD) VCFLAGS = $(CPPFLAGS) $(CFLAGS) VCFLAGSD = $(CPPFLAGS) $(CFLAGSD) -OBJEXT = obj -RESEXT = res +OBJEXT = obj +OEXT = o +RESEXT = res include common.mk -DLL_OBJS = $(DLL_OBJS) $(RESOURCE_OBJS) -STATIC_OBJS = $(STATIC_OBJS) $(RESOURCE_OBJS) +DLL_OBJS = $(DLL_OBJS) $(RESOURCE_OBJS) +STATIC_OBJS = $(STATIC_OBJS) $(RESOURCE_OBJS) +STATIC_OBJS_SMALL = $(STATIC_OBJS_SMALL) $(RESOURCE_OBJS) help: - @ echo Run one of the following command lines: + @ echo To just build all possible versions and install them in $(DESTROOT) + @ echo nmake all install + @ echo ------------------------------------------ + @ echo Or run one of the following command lines: @ echo nmake clean all-tests - @ echo nmake -DEXHAUSTIVE clean all-tests + @ echo nmake -DEXHAUSTIVE clean all-tests + @ echo nmake clean all-tests-md + @ echo nmake clean all-tests-mt @ echo nmake clean VC @ echo nmake clean VC-debug @ echo nmake clean VC-static @ echo nmake clean VC-static-debug -# @ echo nmake clean VC-small-static -# @ echo nmake clean VC-small-static-debug @ echo nmake clean VCE @ echo nmake clean VCE-debug @ echo nmake clean VCE-static @ echo nmake clean VCE-static-debug -# @ echo nmake clean VCE-small-static -# @ echo nmake clean VCE-small-static-debug @ echo nmake clean VSE @ echo nmake clean VSE-debug @ echo nmake clean VSE-static @ echo nmake clean VSE-static-debug -# @ echo nmake clean VSE-small-static -# @ echo nmake clean VSE-small-static-debug all: + $(MAKE) /E clean VC-static + $(MAKE) /E clean VCE-static + $(MAKE) /E clean VSE-static + $(MAKE) /E clean VC-static-debug + $(MAKE) /E clean VCE-static-debug + $(MAKE) /E clean VSE-static-debug + $(MAKE) /E clean VC $(MAKE) /E clean VCE $(MAKE) /E clean VSE - $(MAKE) /E clean VC + $(MAKE) /E clean VC-debug $(MAKE) /E clean VCE-debug $(MAKE) /E clean VSE-debug - $(MAKE) /E clean VC-debug + $(MAKE) /E clean TEST_ENV = CFLAGS="$(CFLAGS) /DNO_ERROR_DIALOGS" all-tests: -# $(MAKE) /E realclean VC-small-static$(XDBG) -# cd tests && $(MAKE) /E clean VC-small-static$(XDBG) $(TEST_ENV) && $(MAKE) /E clean VCX-small-static$(XDBG) $(TEST_ENV) -# $(MAKE) /E realclean VCE-small-static$(XDBG) -# cd tests && $(MAKE) /E clean VCE-small-static$(XDBG) $(TEST_ENV) -# $(MAKE) /E realclean VSE-small-static$(XDBG) -# cd tests && $(MAKE) /E clean VSE-small-static$(XDBG) $(TEST_ENV) + $(MAKE) all-tests-md all-tests-mt + +all-tests-dll: $(MAKE) /E realclean VC$(XDBG) - cd tests && $(MAKE) /E clean VC$(XDBG) $(TEST_ENV) && $(MAKE) /E clean VCX$(XDBG) $(TEST_ENV) + cd tests && $(MAKE) /E clean VC$(XDBG) $(TEST_ENV) $(MAKE) /E realclean VCE$(XDBG) cd tests && $(MAKE) /E clean VCE$(XDBG) $(TEST_ENV) $(MAKE) /E realclean VSE$(XDBG) cd tests && $(MAKE) /E clean VSE$(XDBG) $(TEST_ENV) -#!IF DEFINED(EXHAUSTIVE) + +all-tests-static: $(MAKE) /E realclean VC-static$(XDBG) - cd tests && $(MAKE) /E clean VC-static$(XDBG) $(TEST_ENV) && $(MAKE) /E clean VCX-static$(XDBG) $(TEST_ENV) + cd tests && $(MAKE) /E clean VC-static$(XDBG) $(TEST_ENV) $(MAKE) /E realclean VCE-static$(XDBG) cd tests && $(MAKE) /E clean VCE-static$(XDBG) $(TEST_ENV) $(MAKE) /E realclean VSE-static$(XDBG) cd tests && $(MAKE) /E clean VSE-static$(XDBG) $(TEST_ENV) -#!ENDIF $(MAKE) realclean @ echo $@ completed successfully. -all-tests-cflags: +all-tests-md: @ -$(SETENV) - $(MAKE) all-tests XCFLAGS="/W3 /WX /MD /nologo" - $(MAKE) all-tests XCFLAGS="/W3 /WX /MT /nologo" -!IF DEFINED(MORE_EXHAUSTIVE) - $(MAKE) all-tests XCFLAGS="/W3 /WX /MDd /nologo" XDBG="-debug" - $(MAKE) all-tests XCFLAGS="/W3 /WX /MTd /nologo" XDBG="-debug" + $(MAKE) all-tests-dll +!IF DEFINED(EXHAUSTIVE) + $(MAKE) all-tests-dll XDBG="-debug" +!ENDIF + @ echo $@ completed successfully. + +all-tests-mt: + @ -$(SETENV) + $(MAKE) all-tests-static +!IF DEFINED(EXHAUSTIVE) + $(MAKE) all-tests-static XDBG="-debug" !ENDIF @ echo $@ completed successfully. VCE: - @ $(MAKE) /E /nologo EHFLAGS="$(VCEFLAGS) /D_WINDLL /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_CXX pthreadVCE$(DLL_VER).dll + @ $(MAKE) /E /nologo XCFLAGS="/MD" EHFLAGS="$(VCEFLAGS) /D_WINDLL /DPTW32_BUILD_INLINED" CLEANUP=PTW32_CLEANUP_CXX pthreadVCE$(PTW32_VER).dll VCE-debug: - @ $(MAKE) /E /nologo EHFLAGS="$(VCEFLAGSD) /D_WINDLL /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_CXX pthreadVCE$(DLL_VERD).dll + @ $(MAKE) /E /nologo XCFLAGS="/MDd" EHFLAGS="$(VCEFLAGSD) /D_WINDLL /DPTW32_BUILD_INLINED" CLEANUP=PTW32_CLEANUP_CXX pthreadVCE$(PTW32_VER_DEBUG).dll VSE: - @ $(MAKE) /E /nologo EHFLAGS="$(VSEFLAGS) /D_WINDLL /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_SEH pthreadVSE$(DLL_VER).dll + @ $(MAKE) /E /nologo XCFLAGS="/MD" EHFLAGS="$(VSEFLAGS) /D_WINDLL /DPTW32_BUILD_INLINED" CLEANUP=PTW32_CLEANUP_SEH pthreadVSE$(PTW32_VER).dll VSE-debug: - @ $(MAKE) /E /nologo EHFLAGS="$(VSEFLAGSD) /D_WINDLL /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_SEH pthreadVSE$(DLL_VERD).dll + @ $(MAKE) /E /nologo XCFLAGS="/MDd" EHFLAGS="$(VSEFLAGSD) /D_WINDLL /DPTW32_BUILD_INLINED" CLEANUP=PTW32_CLEANUP_SEH pthreadVSE$(PTW32_VER_DEBUG).dll VC: - @ $(MAKE) /E /nologo EHFLAGS="$(VCFLAGS) /D_WINDLL /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_C pthreadVC$(DLL_VER).dll + @ $(MAKE) /E /nologo XCFLAGS="/MD" EHFLAGS="$(VCFLAGS) /D_WINDLL /DPTW32_BUILD_INLINED" CLEANUP=PTW32_CLEANUP_C pthreadVC$(PTW32_VER).dll VC-debug: - @ $(MAKE) /E /nologo EHFLAGS="$(VCFLAGSD) /D_WINDLL /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_C pthreadVC$(DLL_VERD).dll + @ $(MAKE) /E /nologo XCFLAGS="/MDd" EHFLAGS="$(VCFLAGSD) /D_WINDLL /DPTW32_BUILD_INLINED" CLEANUP=PTW32_CLEANUP_C pthreadVC$(PTW32_VER_DEBUG).dll # # Static builds # #VCE-small-static: -# @ $(MAKE) /E /nologo EHFLAGS="$(VCEFLAGS) /DPTW32_STATIC_LIB" CLEANUP=__CLEANUP_CXX pthreadVCE$(DLL_VER).small_static_stamp +# @ $(MAKE) /E /nologo XCFLAGS="/MT" EHFLAGS="$(VCEFLAGS) /DPTW32_STATIC_LIB" CLEANUP=PTW32_CLEANUP_CXX pthreadVCE$(PTW32_VER).small_static_stamp #VCE-small-static-debug: -# @ $(MAKE) /E /nologo EHFLAGS="$(VCEFLAGSD) /DPTW32_STATIC_LIB" CLEANUP=__CLEANUP_CXX pthreadVCE$(DLL_VERD).small_static_stamp +# @ $(MAKE) /E /nologo XCFLAGS="/MTd" EHFLAGS="$(VCEFLAGSD) /DPTW32_STATIC_LIB" CLEANUP=PTW32_CLEANUP_CXX pthreadVCE$(PTW32_VER_DEBUG).small_static_stamp #VSE-small-static: -# @ $(MAKE) /E /nologo EHFLAGS="$(VSEFLAGS) /DPTW32_STATIC_LIB" CLEANUP=__CLEANUP_SEH pthreadVSE$(DLL_VER).small_static_stamp +# @ $(MAKE) /E /nologo XCFLAGS="/MT" EHFLAGS="$(VSEFLAGS) /DPTW32_STATIC_LIB" CLEANUP=PTW32_CLEANUP_SEH pthreadVSE$(PTW32_VER).small_static_stamp #VSE-small-static-debug: -# @ $(MAKE) /E /nologo EHFLAGS="$(VSEFLAGSD) /DPTW32_STATIC_LIB" CLEANUP=__CLEANUP_SEH pthreadVSE$(DLL_VERD).small_static_stamp +# @ $(MAKE) /E /nologo XCFLAGS="/MTd" EHFLAGS="$(VSEFLAGSD) /DPTW32_STATIC_LIB" CLEANUP=PTW32_CLEANUP_SEH pthreadVSE$(PTW32_VER_DEBUG).small_static_stamp #VC-small-static: -# @ $(MAKE) /E /nologo EHFLAGS="$(VCFLAGS) /DPTW32_STATIC_LIB" CLEANUP=__CLEANUP_C pthreadVC$(DLL_VER).small_static_stamp +# @ $(MAKE) /E /nologo XCFLAGS="/MT" EHFLAGS="$(VCFLAGS) /DPTW32_STATIC_LIB" CLEANUP=PTW32_CLEANUP_C pthreadVC$(PTW32_VER).small_static_stamp #VC-small-static-debug: -# @ $(MAKE) /E /nologo EHFLAGS="$(VCFLAGSD) /DPTW32_STATIC_LIB" CLEANUP=__CLEANUP_C pthreadVC$(DLL_VERD).small_static_stamp +# @ $(MAKE) /E /nologo XCFLAGS="/MTd" EHFLAGS="$(VCFLAGSD) /DPTW32_STATIC_LIB" CLEANUP=PTW32_CLEANUP_C pthreadVC$(PTW32_VER_DEBUG).small_static_stamp VCE-static: - @ $(MAKE) /E /nologo EHFLAGS="$(VCEFLAGS) /DPTW32_STATIC_LIB /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_CXX pthreadVCE$(DLL_VER).inlined_static_stamp + @ $(MAKE) /E /nologo XCFLAGS="/MT" EHFLAGS="$(VCEFLAGS) /DPTW32_STATIC_LIB /DPTW32_BUILD_INLINED" CLEANUP=PTW32_CLEANUP_CXX pthreadVCE$(PTW32_VER).inlined_static_stamp VCE-static-debug: - @ $(MAKE) /E /nologo EHFLAGS="$(VCEFLAGSD) /DPTW32_STATIC_LIB /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_CXX pthreadVCE$(DLL_VERD).inlined_static_stamp + @ $(MAKE) /E /nologo XCFLAGS="/MTd" EHFLAGS="$(VCEFLAGSD) /DPTW32_STATIC_LIB /DPTW32_BUILD_INLINED" CLEANUP=PTW32_CLEANUP_CXX pthreadVCE$(PTW32_VER_DEBUG).inlined_static_stamp VSE-static: - @ $(MAKE) /E /nologo EHFLAGS="$(VSEFLAGS) /DPTW32_STATIC_LIB /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_SEH pthreadVSE$(DLL_VER).inlined_static_stamp + @ $(MAKE) /E /nologo XCFLAGS="/MT" EHFLAGS="$(VSEFLAGS) /DPTW32_STATIC_LIB /DPTW32_BUILD_INLINED" CLEANUP=PTW32_CLEANUP_SEH pthreadVSE$(PTW32_VER).inlined_static_stamp VSE-static-debug: - @ $(MAKE) /E /nologo EHFLAGS="$(VSEFLAGSD) /DPTW32_STATIC_LIB /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_SEH pthreadVSE$(DLL_VERD).inlined_static_stamp + @ $(MAKE) /E /nologo XCFLAGS="/MTd" EHFLAGS="$(VSEFLAGSD) /DPTW32_STATIC_LIB /DPTW32_BUILD_INLINED" CLEANUP=PTW32_CLEANUP_SEH pthreadVSE$(PTW32_VER_DEBUG).inlined_static_stamp VC-static: - @ $(MAKE) /E /nologo EHFLAGS="$(VCFLAGS) /DPTW32_STATIC_LIB /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_C pthreadVC$(DLL_VER).inlined_static_stamp + @ $(MAKE) /E /nologo XCFLAGS="/MT" EHFLAGS="$(VCFLAGS) /DPTW32_STATIC_LIB /DPTW32_BUILD_INLINED" CLEANUP=PTW32_CLEANUP_C pthreadVC$(PTW32_VER).inlined_static_stamp VC-static-debug: - @ $(MAKE) /E /nologo EHFLAGS="$(VCFLAGSD) /DPTW32_STATIC_LIB /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_C pthreadVC$(DLL_VERD).inlined_static_stamp + @ $(MAKE) /E /nologo XCFLAGS="/MTd" EHFLAGS="$(VCFLAGSD) /DPTW32_STATIC_LIB /DPTW32_BUILD_INLINED" CLEANUP=PTW32_CLEANUP_C pthreadVC$(PTW32_VER_DEBUG).inlined_static_stamp realclean: clean @@ -186,62 +196,68 @@ realclean: clean if exist *.lib del *.lib if exist *.a del *.a if exist *.manifest del *.manifest - if exist *_stamp del *_stamp if exist make.log.txt del make.log.txt - cd tests && $(MAKE) clean + cd tests && $(MAKE) realclean clean: if exist *.obj del *.obj if exist *.def del *.def if exist *.ilk del *.ilk + if exist *.idb del *.idb if exist *.pdb del *.pdb if exist *.exp del *.exp if exist *.map del *.map if exist *.o del *.o if exist *.i del *.i if exist *.res del *.res + if exist *_stamp del *_stamp + cd tests && $(MAKE) clean -# Very basic install. It assumes "realclean" was done just prior to build target if -# you want the installed $(DEVDEST_LIB_NAME) to match that build. +# Very basic install. It assumes "realclean" was done just prior to build target. install: if not exist $(DLLDEST) mkdir $(DLLDEST) if not exist $(LIBDEST) mkdir $(LIBDEST) if not exist $(HDRDEST) mkdir $(HDRDEST) if exist pthreadV*.dll copy pthreadV*.dll $(DLLDEST) copy pthreadV*.lib $(LIBDEST) + copy libpthreadV*.lib $(LIBDEST) + copy _ptw32.h $(HDRDEST) copy pthread.h $(HDRDEST) copy sched.h $(HDRDEST) copy semaphore.h $(HDRDEST) - if exist pthreadVC$(DLL_VER).lib copy pthreadVC$(DLL_VER).lib $(LIBDEST)\$(DEST_LIB_NAME) - if exist pthreadVC$(DLL_VERD).lib copy pthreadVC$(DLL_VERD).lib $(LIBDEST)\$(DEST_LIB_NAME) - if exist pthreadVCE$(DLL_VER).lib copy pthreadVCE$(DLL_VER).lib $(LIBDEST)\$(DEST_LIB_NAME) - if exist pthreadVCE$(DLL_VERD).lib copy pthreadVCE$(DLL_VERD).lib $(LIBDEST)\$(DEST_LIB_NAME) - if exist pthreadVSE$(DLL_VER).lib copy pthreadVSE$(DLL_VER).lib $(LIBDEST)\$(DEST_LIB_NAME) - if exist pthreadVSE$(DLL_VERD).lib copy pthreadVSE$(DLL_VERD).lib $(LIBDEST)\$(DEST_LIB_NAME) $(DLLS): $(DLL_OBJS) - $(CC) /LDd /Zi /nologo $(DLL_OBJS) /link /implib:$*.lib $(XLIBS) /out:$@ + $(CC) /LDd /Zi $(DLL_OBJS) /link /implib:$*.lib $(XLIBS) /out:$@ -$(INLINED_STATIC_STAMPS): $(DLL_OBJS) - if exist $*.lib del $*.lib - lib $(DLL_OBJS) /out:$*.lib +$(INLINED_STATIC_STAMPS): $(STATIC_OBJS) + if exist lib$*.lib del lib$*.lib + lib $(STATIC_OBJS) /out:lib$*.lib echo. >$@ -$(SMALL_STATIC_STAMPS): $(STATIC_OBJS) - if exist $*.lib del $*.lib - lib $(STATIC_OBJS) /out:$*.lib +$(SMALL_STATIC_STAMPS): $(STATIC_OBJS_SMALL) + if exist lib$*.lib del lib$*.lib + lib $(STATIC_OBJS_SMALL) /out:lib$*.lib echo. >$@ .c.obj: - $(CC) $(EHFLAGS) /D$(CLEANUP) -c $< + $(CC) $(XCFLAGS) $(EHFLAGS) /D$(CLEANUP) -c $< + +.c.o: + $(CC) $(XCFLAGS) $(EHFLAGS) /D$(CLEANUP) /Fo$*.$(OEXT) -c $< # TARGET_CPU is an environment variable set by Visual Studio Command Prompt # as provided by the SDK (VS 2010 Express plus SDK 7.1) # PLATFORM is an environment variable that may be set in the VS 2013 Express x64 cross # development environment +# On my HP Compaq PC running VS 10, PLATFORM was defined as "HPD" but PROCESSOR_ARCHITECTURE +# was defined as "x86" .rc.res: !IF DEFINED(PLATFORM) - rc /dPTW32_ARCH$(PLATFORM) /dPTW32_RC_MSC /d$(CLEANUP) $< +! IF DEFINED(PROCESSOR_ARCHITECTURE) + rc /dPTW32_ARCH$(PROCESSOR_ARCHITECTURE) /dPTW32_RC_MSC /d$(CLEANUP) $< +! ELSE + rc /dPTW32_ARCH$(PLATFORM) /dPTW32_RC_MSC /d$(CLEANUP) $< +! ENDIF !ELSE IF DEFINED(TARGET_CPU) rc /dPTW32_ARCH$(TARGET_CPU) /dPTW32_RC_MSC /d$(CLEANUP) $< !ELSE diff --git a/README.md b/README.md index e82fb36d..80841436 100644 --- a/README.md +++ b/README.md @@ -1,631 +1,1605 @@ -### PThreadWindows +### pthread-win32 for Windows + Combined pthread-win32 fork of RedFox20 + Oktonion + WinBuild + PThread https://github.com/WinBuilds/pthread-win32 changes: + This is a fork of version 2.10.0.0 the [pthreads-win32](https://sourceforge.net/projects/pthreads4w/ "https://sourceforge.net/projects/pthreads4w/") package. The ABI of this fork is different from the original. + Changes done: + 1. The type of the reuse counter in ptw32_handle_t has been changed from int to size_t in order to facilitate long-running servers. 2. Removed unused elements from pthread_once_t -PTHREADS-WIN32 Readme -============== -pthreads-win32 is free software, distributed under the GNU Lesser -General Public License (LGPL). See the file 'COPYING.LIB' for terms -and conditions. Also see the file 'COPYING' for information -specific to pthreads-win32, copyrights and the LGPL. +RELEASE 3.0.0 +-------------- +(2018-08-08) +General +------- +Note that this is a new major release. The major version increment +introduces two ABI changes along with other naming changes that will +require recompilation of linking applications and possibly some textual +changes to compile-time macro references in configuration and source +files, e.g. PTW32_* changes to PTW32_*, ptw32_* to ptw32_*, etc. -What is it? ------------ +License Change +-------------- +With the agreement of all substantial relevant contributors pthreads-win32 / pthreads4w +version 3, with the exception of four files, is being released under the +terms of the Apache License v2.0. The APLv2 is compatible with the GPLv3 +and LGPLv3 licenses and therefore this code may continue to be legally +included within GPLv3 and LGPLv3 projects. + +A substantial relevant contributor was defined as one who has contributed +original code that implements a capability present in the releases going +forward. This excludes several contributors who have contributed code +that has been obsoleted, or have provided patches that fix bugs, +reorganise code for aesthetic or practical purposes, or improve build +processes. This distinction was necessary in order to move forward in the +likelyhood that not all contributors would be contactable. All +contributors are listed in the file CONTRIBUTORS. + +The four files that will remain LGPL but change to v3 are files used to +configure the GNU environment builds: + + aclocal.m4 + configure.ac + GNUmakefile.in + tests/GNUmakefile.in + +Contributors who have either requested this change or agreed to it when +consulted are: + +John Bossom +Alexander Terekhov +Vladimir Kliatchko +Ross Johnson -pthreads-win32 (a.k.a. pthreads4w) is an Open Source Software -implementation of the Threads component of the POSIX 1003.1c 1995 -Standard (or later) for Microsoft's Windows environment. Some functions -from POSIX 1003.1b are also supported, including semaphores. Other -related functions include the set of read-write lock functions. The -library also supports some of the functionality of the Open -Group's Single Unix specification, namely mutex types, plus some common -and pthreads-win32 specific non-portable routines (see README.NONPORTABLE). +pthreads-win32 / pthreads4w version 2 releases will remain LGPL but version 2.11 and later +will be released under v3 of that license so that any additions to +pthreads4w version 3 code that is backported to v2 will not pollute that +code. + +Backporting and Support of Legacy Windows Releases +-------------------------------------------------- +Some changes from 2011-02-26 onward may not be compatible with pre +Windows 2000 systems. + +New bug fixes in all releases since 2.8.0 have NOT been applied to the +1.x.x series. + +Testing and verification +------------------------ +The MSVC, MinGW and MinGW64 builds have been tested on SMP architecture +(Intel x64 Hex Core) by completing the included test suite, as well as the +stress and bench tests. + +Be sure to run your builds against the test suite. If you see failures +then please consider how your toolchains might be contributing to the +failure. See the README file for more detailed descriptions of the +toolchains and test systems that we have used to get the tests to pass +successfully. + +We recommend MinGW64 over MinGW for both 64 and 32 bit GNU CC builds +only because the MinGW DWARF2 exception handling with C++ builds causes some +problems with thread cancelation. + +MinGW64 also includes its own native pthreads implementation, which you may +prefer to use. If you wish to build our library you will need to select the +Win32 native threads option at install time. We recommend also selecting the +SJLJ exception handling method for MinGW64-w32 builds. For MinGW64-w64 builds +either the SJLJ or SEH exception handling method should work. + +New Features +------------ +Other than the following, this release is feature-equivalent to v2.11.0. -See the file "ANNOUNCE" for more information including standards -conformance details and the list of supported and unsupported -routines. +This release introduces a change to pthread_t and pthread_once_t that will +affect applications that link with the library. +pthread_t: remains a struct but extends the reuse counter from 32 bits to 64 +bits. On 64 bit machines the overall size of the object will not increase, we +simply put 4 bytes of padding to good use reducing the risk that the counter +could wrap around in very long-running applications from small to, effectively, +zero. The 64 bit reuse counter extends risk-free run time from months +(assuming an average thread lifetime of 1ms) to centuries (assuming an +average thread lifetime of 1ns). -Prerequisites -------------- -MSVC or GNU C (MinGW32 or MinGW64 MSys development kit) - To build from source. - -QueueUserAPCEx by Panagiotis E. Hadjidoukas - To support any thread cancellation in C++ library builds or - to support cancellation of blocked threads in any build. - This library is not required otherwise. - - For true async cancellation of threads (including blocked threads). - This is a DLL and Windows driver that provides pre-emptive APC - by forcing threads into an alertable state when the APC is queued. - Both the DLL and driver are provided with the pthreads-win32.exe - self-unpacking ZIP, and on the pthreads-win32 FTP site (in source - and pre-built forms). Currently this is a separate LGPL package to - pthreads-win32. See the README in the QueueUserAPCEx folder for - installation instructions. - - pthreads-win32 will automatically detect if the QueueUserAPCEx DLL - QuserEx.DLL is available and whether the driver AlertDrv.sys is - loaded. If it is not available, pthreads-win32 will simulate async - cancellation, which means that it can async cancel only threads that - are runnable. The simulated async cancellation cannot cancel blocked - threads. - - [FOR SECURITY] To be found Quserex.dll MUST be installed in the - Windows System Folder. This is not an unreasonable constraint given a - driver must also be installed and loaded at system startup. - - -Library naming +pthread_once_t: removes two long-obsoleted elements and reduces it's size. + + +RELEASE 2.11.0 -------------- +(2018-08-08) + +General +------- +New bug fixes in all releases since 2.8.0 have NOT been applied to the +1.x.x series. + +Some changes from 2011-02-26 onward may not be compatible with +pre Windows 2000 systems. + +License Change to LGPL v3 +------------------------- +pthreads-win32 / pthreads4w version 2.11 and all future 2.x versions will be released +under the Lesser GNU Public License version 3 (LGPLv3). + +Planned Release Under the Apache License v2 +------------------------------------------- +The next major version of this software (version 3) will be released +under the Apache License version 2.0 (ALv2). Releasing 2.11 under LGPLv3 +will allow modifications to version 3 of this software to be backported +to version 2 going forward. Further to this, any GPL projects currently +using this library will be able to continue to use either version 2 or 3 +of this code in their projects. + +For more information please see: +https://www.apache.org/licenses/GPL-compatibility.html + +In order to remain consistent with this change, from this point on +modifications to this library will only be accepted against version 3 +of this software under the terms of the ALv2. They will then, where +appropriate, be backported to version 2. + +We hope to release version 3 at the same time as we release version 2.11. + +Testing and verification +------------------------ +This version has been tested on SMP architecture (Intel x64 Hex Core) +by completing the included test suite, as well as the stress and bench +tests. + +Be sure to run your builds against the test suite. If you see failures +then please consider how your toolchains might be contributing to the +failure. See the README file for more detailed descriptions of the +toolchains and test systems that we have used to get the tests to pass +successfully. We recommend MinGW64 over MinGW32 for both 64 and 32 bit +GNU CC builds. MinGW64 also includes its own independent pthreads +implementation, which you may prefer to use. + +New Features or Changes +----------------------- +For Microsoft toolchain builds: +(1) Static linking requires both this library and any linking +libraries or applications to be compiled with /MT consistently. + +(2) Static libraries have been renamed as libpthreadV*.lib +to differentiate them from DLL import libs pthreadV*.lib. + +(3) If you are using mixed linkage, e.g. linking the static /MT version +of the library to an application linked with /MD you may be able to use +GetLastError() to interrogate the error code because the library sets +both errno (via _set_errno()) and SetLastError(). + +Bug Fixes +--------- +Remove the attempt to set PTW32_USES_SEPARATE_CRT in the headers which +can cause unexpected results. In certain situations a user may want to +define it explicitly in their environment to invoke it's effects, either +when buidling the library or an application or both. See README.NONPORTABLE. +-- Ross Johnson + +The library should be more reliable under fully statically linked +scenarios. Note: we have removed the PIMAGE_TLS_CALLBACK code and +reverted to the earlier method that appears to be more reliable +across all compiler editions. +- Mark Pizzolato + +Various corrections to GNUmakefile. Although this file has been removed, +for completeness the changes have been recorded as commits to the +repository. +- Kyle Schwarz + +MinGW64-w64 defines pid_t as __int64. sched.h now reflects that. +- Kyle Schwarz + +Several tests have been fixed that were seen to fail on machines under +load. Other tests that used similar crude mechanisms to synchronise +threads (these are unit tests) had the same improvements applied: +semaphore5.c recognises that sem_destroy can legitimately return +EBUSY; mutex6*.c, mutex7*.c and mutex8*.c all replaced a single +Sleep() with a polling loop. +- Ross Johnson + + +RELEASE 2.10.0 +-------------- +(2016-09-18) + +General +------- +New bug fixes in all releases since 2.8.0 have NOT been applied to the +1.x.x series. + +Some changes from 2011-02-26 onward may not be compatible with +pre Windows 2000 systems. + +Testing and verification +------------------------ +This version has been tested on SMP architecture (Intel x64 Hex Core) +by completing the included test suite, as well as the stress and bench +tests. + +Be sure to run your builds against the test suite. If you see failures +then please consider how your toolchains might be contributing to the +failure. See the README file for more detailed descriptions of the +toolchains and test systems that we have used to get the tests to pass +successfully. We recommend MinGW64 over MinGW32 for both 64 and 32 bit +GNU CC builds. MinGW64 also includes its own independent pthreads +implementation, which you may prefer to use. + +New Features +------------ +New routines: +pthread_timedjoin_np() +pthread_tryjoin_np() + - added for compatibility with Linux. +sched_getaffinity() +sched_setaffinity() +pthread_getaffinity_np() +pthread_setaffinity_np() +pthread_attr_getaffinity_np() +pthread_attr_setaffinity_np() + - added for compatibility with Linux and other libgcc-based systems. + The macros to manipulate cpu_set_t objects (the cpu affinity mask + vector) are also defined: CPU_ZERO, CPU_CLR, CPU_SET, CPU_EQUAL, + CPU_AND, CPU_OR, CPU_XOR, CPU_COUNT, CPU_ISSET. +pthread_getname_np() +pthread_setname_np() +pthread_attr_getname_np() +pthread_attr_setname_np() + - added for compatibility with other POSIX implementations. Because + some implementations use different *_setname_np() prototypes + you can define one of the following macros when building the library: + PTW32_COMPATIBILITY_BSD (compatibility with NetBSD, FreeBSD) + PTW32_COMPATIBILITY_TRU64 + If not defined then compatibility is with Linux and other equivalents. + We don't impose a strict limit on the length of the thread name for the + default compatibility case. Unlike Linux, no default thread name is set. + For MSVC builds, the thread name if set is made available for use by the + MSVS debugger, i.e. it should be displayed within the debugger to + identify the thread in place of/as well as a threadID. +pthread_win32_getabstime_np() + - Return the current time plus an optional offset in a platform-aware way + that is compatible with POSIX timed calls (returns the struct timespec + address which is the first argument). Intended primarily to make it + easier to write tests but may be useful for applications generally. +GNU compiler environments (MinGW32 and MinGW64) now have the option of using +autoconf to automatically configure the build. + +Builds: +New makefile targets have been added and existing targets modified or +removed. For example, targets to build and test all of the possible +configurations of both dll and static libs. + +GNU compiler builds are now explicitly using ISO C and C++ 2011 standards +compatibility. If your GNU compiler doesn't support this please consider +updating. Auto configuration is now possible via 'configure' script. The +script must be generated using autoconf - see the README file. Thanks to +Keith Marshall from the MinGW project. + +Static linking: +The autostatic functionality has been moved to dll.c, and extended so +that builds using MSVC8 and later no longer require apps to call +pthread_win32_thread_detach_np(). That is, all of the DllMain +functionality is now automatic for static linking for these builds. + +Some nmake static linking targets have been disabled: +Due to an issue with TLS behaviour, the V*-small-static* nmake targets +in Makefile have been disabled. The issue is exposed by tests/semaphore3.c +where the pthread_self() call inside the thread fails to return the +correct POSIX thread handle but returns a new "implicit" POSIX thread +handle instead. Implicit pthread handles have detached thread status, which +causes the pthread_detach() call inside the thread to return EINVAL. The +V*-static* targets appear to be not affected. The primary difference is +that the latter are generated from a single compilation unit. + +Bug Fixes +--------- +Small object file static linking now works (MinGW). The autostatic code +is required but nothing explicitly referenced this code so was getting +optimised out. +- Daniel Richard G. + +sem_getvalue() could return the errno value instead of setting errno +and returning -1. +- Ross Johnson + +Errno values were being lost if the library is statically linked +with the runtime library, meaning also that the application used a +separate runtime instance. This is still the case except a build +switch has been added that allows more robust error status to be +incorporated, i.e. allow the return code to be retrieved via +GetLastError(). +- Daniel Richard G. + +Identified the cause of significant failures around cancelation +and pthread_exit() for the GCE (GNU C++) build configuration as +coming from Mingw32. Not sure if this is general or just when +building 32 bit libraries and apps that run on 64 bit systems. +These failures do not arise with Mingw64 32 bit builds (GCC built +with multilib enabled) running on 64 bit systems. +- Daniel Richard G. and Ross Johnson + +pthread_key_delete() bug introduced in release 2.9.x caused this +routine to fail in a way that the test suite was not detecting. A +new test has been added to confirm that this routine behaves +correctly, particularly when keys with destructors are deleted +before threads exit. +- Stephane Clairet + +pthread_win32_process_attach_np() fix potential failure/security around +finding and loading of QUSEREX.DLL. +- Jason Baker + +_POSIX_THREAD_ATTR_STACKADDR is now set equal to -1 in pthread.h. As a +consequence pthread_attr_setstackaddr() now returns ENOSYS. Previously +the value was stored and could be retrieved but was otherwise unused. +pthread_attr_getstackaddr() returns ENOSYS correspondingly. +- Ross Johnson + +Fixed a potential memory leak in pthread_mutex_init(). The leak would +only occur if the mutex initialisation failed (extremely rare if ever). +- Jaeeun Choi + +Fixed sub-millisecond timeouts, which caused the library to busy wait. +- Mark Smith + +Fix a race condition and crash in MCS locks. The waiter queue management +code in ptw32_mcs_lock_acquire was racing with the queue management code +in ptw32_mcs_lock_release and causing a segmentation fault. +- Anurag Sharma +- Jonathan Brown (also reported this bug and provided a fix) + +RELEASE 2.9.1 +------------- +(2012-05-27) -Because the library is being built using various exception -handling schemes and compilers - and because the library -may not work reliably if these are mixed in an application, -each different version of the library has it's own name. - -Please do not distribute your own modified versions of the library -using names conforming to this description. You can use the -makefile variable "EXTRAVERSION" to append your own suffix to the -library names when building and testing your library. +General +------- +New bug fixes in this release since 2.8.0 have NOT been applied to the +1.x.x series. -Note 1: the incompatibility is really between EH implementations -of the different compilers. It should be possible to use the -standard C version from either compiler with C++ applications -built with a different compiler. If you use an EH version of -the library, then you must use the same compiler for the -application. This is another complication and dependency that -can be avoided by using only the standard C library version. - -Note 2: if you use a standard C pthread*.dll with a C++ -application, then any functions that you define that are -intended to be called via pthread_cleanup_push() must be -__cdecl. - -Note 3: the intention was to also name either the VC or GC -version (it should be arbitrary) as pthread.dll, including -pthread.lib and libpthread.a as appropriate. This is no longer -likely to happen. - -Note 4: the compatibility number (major version number) was -added so that applications can differentiate between binary -incompatible versions of the libs and dlls. - -In general the naming format used is: - pthread[VG]{SE,CE,C}[c][E].dll - pthread[VG]{SE,CE,C}[c][E].lib - -where: - [VG] indicates the compiler - V - MS VC, or - G - GNU C - - {SE,CE,C} indicates the exception handling scheme - SE - Structured EH, or - CE - C++ EH, or - C - no exceptions - uses setjmp/longjmp - - c - DLL major version number indicating ABI - compatibility with applications built against - a snapshot with the same major version number. - See 'Version numbering' below. - E - EXTRAVERSION suffix. - -The name may also be suffixed by a 'd' to indicate a debugging version -of the library. E.g. pthreadVC2d.lib. These will be created e.g. when -the *-debug makefile targets are used. - -Examples: - pthreadVC2.dll (MSVC/not dependent on exceptions - not binary - compatible with pthreadVC1.dll or pthreadVC.dll) - pthreadGC2-w32.dll (As built, e.g., by "make GC ARCH=-m32 EXTRAVERSION=-w32") - pthreadVC2-w64.dll (As built, e.g., by "nmake VC ARCH=-m64 EXTRAVERSION=-w64") - -For information on ARCH (MinGW GNUmakefile) or TARGET_CPU (MSVS Makefile) -see the respective "Building with ..." sections below. - -The GNU library archive file names have correspondingly changed, e.g.: - - libpthreadGCE2.a - libpthreadGC2.a - libpthreadGC2-w64.a - - -Version numbering ------------------ - -See pthread.h and the resource file 'version.rc'. - -Microsoft version numbers use 4 integers: - - 0.0.0.0 - -pthreads-win32 uses the first 3 following the standard major.minor.micro -system. We had claimed to follow the Libtool convention but this has -not been the case with recent releases. Binary compatibility and -consequently library file naming has not changed over this time either -so it should not cause any problems. - -The fourth is commonly used for the build number, but will be reserved -for future use. - - major.minor.micro.0 - -The numbers are changed as follows: - -1. If the general binary interface (ABI) has changed at all since the - last update in a way that requires recompilation and relinking of - applications, then increment Major, and set both minor and micro to 0. - (`M:m:u' becomes `M+1:0:0') -2. If the general API has changed at all since the last update or - there have been semantic/behaviour changes (bug fixes etc) but does - not require recompilation of existing applications, then increment - minor and set micro to 0. - (`M:m:u' becomes `M:m+1:0') -3. If there have been no interface or semantic changes since the last - public release but a new release is deemed necessary for some reason, - then increment micro. - (`M:m:u' becomes `M:m:u+1') - - -DLL compatibility numbering is an attempt to ensure that applications -always load a compatible pthreads-win32 DLL by using a DLL naming system -that is consistent with the version numbering system. It also allows -older and newer DLLs to coexist in the same filesystem so that older -applications can continue to be used. For pre .NET Windows systems, -this inevitably requires incompatible versions of the same DLLs to have -different names. +This release replaces an extremely brief 2.9.0 release and adds +some last minute non-code changes were made to embed better +descriptive properties in the dlls to indicate target architecture +and build environments. -pthreads-win32 has adopted the Cygwin convention of appending a single -integer number to the DLL name. The number used is simply the library's -major version number. +Some changes post 2011-02-26 in CVS may not be compatible with pre +Windows 2000 systems. -Consequently, DLL name/s will only change when the DLL's -backwards compatibility changes. Note that the addition of new -'interfaces' will not of itself change the DLL's compatibility for older -applications. +Use of other than the "C" version of the library is now discouraged. +That is, the "C++" version fails some tests and does not provide any +additional functionality. +Testing and verification +------------------------ +This version has been tested on SMP architecture (Intel x64 Hex Core) +by completing the included test suite, stress and bench tests. -Which of the several dll versions to use? ------------------------------------------ -or, ---- -What are all these pthread*.dll and pthread*.lib files? -------------------------------------------------------- +New Features +------------ +DLL properties now properly includes the target architecture, i.e. +right-click on the file pthreadVC2.dll in explorer and choose the Detail +tab will show the compiler and architecture in the description field, e.g. +"MS C x64" or "MS C x86". +- Ross Johnson + +(MSC and GNU builds) The statically linked library now automatically +initialises and cleans up on program start/exit, i.e. statically linked +applications need not call the routines pthread_win32_process_attach_np() +and pthread_win32_process_detach_np() explicitly. The per-thread routine +pthread_win32_thread_detach_np() is also called at program exit to cleanup +POSIX resources acquired by the primary Windows native thread, if I (RJ) +understand the process correctly. Other Windows native threads that call +POSIX API routines may need to call the thread detach routine on thread +exit if the application depends on reclaimed POSIX resources or running +POSIX TSD (TLS) destructors. +See README.NONPORTABLE for descriptions of these routines. +- Ramiro Polla + +Robust mutexes are implemented within the PROCESS_PRIVATE scope. NOTE that +pthread_mutex_* functions may return different error codes for robust +mutexes than they otherwise do in normal usage, e.g. pthread_mutex_unlock +is required to check ownership for all mutex types when the mutex is +robust, whereas this does not occur for the "normal" non-robust mutex type. +- Ross Johnson + +pthread_getunique_np is implemented for source level compatibility +with some other implementations. This routine returns a 64 bit +sequence number that is uniquely associated with a thread. It can be +used by applications to order or hash POSIX thread handles. +- Ross Johnson + +Bug fixes +--------- +Many more changes for 64 bit systems. +- Kai Tietz + +Various modifications and fixes to build and test for WinCE. +- Marcel Ruff, Sinan Kaya + +Fix pthread_cond_destroy() - should not be a cancellation point. Other +minor build problems fixed. +- Romano Paolo Tenca + +Remove potential deadlock condition from pthread_cond_destroy(). +- Eric Berge + +Various modifications to build and test for Win64. +- Kip Streithorst + +Various fixes to the QueueUserAPCEx async cancellation helper DLL +(this is a separate download) and pthreads code cleanups. +- Sebastian Gottschalk + +Removed potential NULL pointer reference. +- Robert Kindred + +Removed the requirement that applications restrict the number of threads +calling pthread_barrier_wait to just the barrier count. Also reduced the +contention between barrier_wait and barrier_destroy. This change will have +slowed barriers down slightly but halves the number of semaphores consumed +per barrier to one. +- Ross Johnson + +Fixed a handle leak in sched_[gs]etscheduler. +- Mark Pizzolato + +Removed all of the POSIX re-entrant function compatibility macros from pthread.h. +Some were simply not semanticly correct. +- Igor Lubashev + +Threads no longer attempt to pass uncaught exceptions out of thread scope (C++ +and SEH builds only). Uncaught exceptions now cause the thread to exit with +the return code PTHREAD_CANCELED. +- Ross Johnson + +Lots of casting fixes particularly for x64, Interlocked fixes and reworking +for x64. +- Daniel Richard G., John Kamp + +Other changes +------------- +Dependence on the winsock library is now discretionary via +#define RETAIN_WSALASTERROR in config.h. It is undefined by default unless +WINCE is defined (because RJ is unsure of the dependency there). +- Ramiro Polla -Simple, use either pthreadGCc.* if you use GCC, or pthreadVCc.* if you -use MSVC - where 'c' is the DLL versioning (compatibility) number. +Several static POSIX mutexes used for internal management were replaced by +MCS queue-based locks to reduce resource consumption, in particular use of Win32 +objects. +- Ross Johnson -Otherwise, you need to choose carefully and know WHY. +For security, the QuserEx.dll if used must now be installed in the Windows System +folder. +- Ross Johnson -The most important choice you need to make is whether to use a -version that uses exceptions internally, or not. There are versions -of the library that use exceptions as part of the thread -cancellation and exit implementation. The default version uses -setjmp/longjmp. +New tests +--------- +robust[1-5].c - Robust mutexes +sequence1.c - per-thread unique sequence numbers -If you use either pthreadVCE or pthreadGCE: +Modified tests and benchtests +----------------------------- +All mutex*.c tests wherever appropriate have been modified to also test +robust mutexes under the same conditions. +Added robust mutex benchtests to benchtest*.c wherever appropriate. -1. [See also the discussion in the FAQ file - Q2, Q4, and Q5] -If your application contains catch(...) blocks in your POSIX -threads then you will need to replace the "catch(...)" with the macro -"PtW32Catch", eg. +RELEASE 2.8.0 +------------- +(2006-12-22) - #ifdef PtW32Catch - PtW32Catch { - ... - } - #else - catch(...) { - ... - } - #endif +General +------- +New bug fixes in this release since 2.7.0 have not been applied to the +version 1.x.x series. It is probably time to drop version 1. -Otherwise neither pthreads cancellation nor pthread_exit() will work -reliably when using versions of the library that use C++ exceptions -for cancellation and thread exit. +Testing and verification +------------------------ +This release has not yet been tested on SMP architechtures. All tests pass +on a uni-processor system. +Bug fixes +--------- +Sem_destroy could return EBUSY even though no threads were waiting on the +semaphore. Other races around invalidating semaphore structs (internally) +have been removed as well. -Other name changes ------------------- +New tests +--------- +semaphore5.c - tests the bug fix referred to above. -All snapshots prior to and including snapshot 2000-08-13 -used "_pthread_" as the prefix to library internal -functions, and "_PTHREAD_" to many library internal -macros. These have now been changed to "ptw32_" and "PTW32_" -respectively so as to not conflict with the ANSI standard's -reservation of identifiers beginning with "_" and "__" for -use by compiler implementations only. - -If you have written any applications and you are linking -statically with the pthreads-win32 library then you may have -included a call to _pthread_processInitialize. You will -now have to change that to ptw32_processInitialize. - - -Cleanup code default style --------------------------- -Previously, if not defined, the cleanup style was determined automatically -from the compiler used, and one of the following was defined accordingly: +RELEASE 2.7.0 +------------- +(2005-06-04) + +General +------- +All new features in this release have been back-ported in release 1.11.0, +including the incorporation of MCS locks in pthread_once, however, versions +1 and 2 remain incompatible even though they are now identical in +performance and functionality. + +Testing and verification +------------------------ +This release has been tested (passed the test suite) on both uni-processor +and multi-processor systems. +- Tim Theisen + +Bug fixes +--------- +Pthread_once has been re-implemented to remove priority boosting and other +complexity to improve robustness. Races for Win32 handles that are not +recycle-unique have been removed. The general form of pthread_once is now +the same as that suggested earlier by Alexander Terekhov, but instead of the +'named mutex', a queue-based lock has been implemented which has the required +properties of dynamic self initialisation and destruction. This lock is also +efficient. The ABI is unaffected in as much as the size of pthread_once_t has +not changed and PTHREAD_ONCE_INIT has not changed, however, applications that +peek inside pthread_once_t, which is supposed to be opaque, will break. +- Vladimir Kliatchko + +New features +------------ +* Support for Mingw cross development tools added to GNUmakefile. +Mingw cross tools allow building the libraries on Linux. +- Mikael Magnusson - __CLEANUP_SEH MSVC only - __CLEANUP_CXX C++, including MSVC++, GNU G++ - __CLEANUP_C C, including GNU GCC, not MSVC -These defines determine the style of cleanup (see pthread.h) and, -most importantly, the way that cancellation and thread exit (via -pthread_exit) is performed (see the routine ptw32_throw()). +RELEASE 2.6.0 +------------- +(2005-05-19) -In short, the exceptions versions of the library throw an exception -when a thread is canceled, or exits via pthread_exit(). This exception is -caught by a handler in the thread startup routine, so that the -the correct stack unwinding occurs regardless of where the thread -is when it's canceled or exits via pthread_exit(). +General +------- +All of the bug fixes and new features in this release have been +back-ported in release 1.10.0. -In this snapshot, unless the build explicitly defines (e.g. via a -compiler option) __CLEANUP_SEH, __CLEANUP_CXX, or __CLEANUP_C, then -the build NOW always defaults to __CLEANUP_C style cleanup. This style -uses setjmp/longjmp in the cancellation and pthread_exit implementations, -and therefore won't do stack unwinding even when linked to applications -that have it (e.g. C++ apps). This is for consistency with most/all -commercial Unix POSIX threads implementations. +Testing and verification +------------------------ +This release has been tested (passed the test suite) on both uni-processor +and multi-processor systems. Thanks to Tim Theisen at TomoTherapy for +exhaustively running the MP tests and for providing crutial observations +and data when faults are detected. -Although it was not clearly documented before, it is still necessary to -build your application using the same __CLEANUP_* define as was -used for the version of the library that you link with, so that the -correct parts of pthread.h are included. That is, the possible -defines require the following library versions: +Bugs fixed +---------- - __CLEANUP_SEH pthreadVSE.dll - __CLEANUP_CXX pthreadVCE.dll or pthreadGCE.dll - __CLEANUP_C pthreadVC.dll or pthreadGC.dll +* pthread_detach() now reclaims remaining thread resources if called after +the target thread has terminated. Previously, this routine did nothing in +this case. -It is recommended that you let pthread.h use it's default __CLEANUP_C -for both library and application builds. That is, don't define any of -the above, and then link with pthreadVC.lib (MSVC or MSVC++) and -libpthreadGC.a (MinGW GCC or G++). The reason is explained below, but -another reason is that the prebuilt pthreadVCE.dll is currently broken. -Versions built with MSVC++ later than version 6 may not be broken, but I -can't verify this yet. +New tests +--------- -WHY ARE WE MAKING THE DEFAULT STYLE LESS EXCEPTION-FRIENDLY? -Because no commercial Unix POSIX threads implementation allows you to -choose to have stack unwinding. Therefore, providing it in pthread-win32 -as a default is dangerous. We still provide the choice but unless -you consciously choose to do otherwise, your pthreads applications will -now run or crash in similar ways irrespective of the pthreads platform -you use. Or at least this is the hope. +* detach1.c - tests that pthread_detach properly invalidates the target +thread, which indicates that the thread resources have been reclaimed. -Development Build Toolchains and Configurations ------------------------------------------------ +RELEASE 2.5.0 +------------- +(2005-05-09) -As of Release 2.10 all build configurations pass the full test suite -for the following toolchains and configurations: +General +------- -DLL and static library (full inlined and small) builds: -VC, VCE, VSE -GC, GCE +The package now includes a reference documentation set consisting of +HTML formatted Unix-style manual pages that have been edited for +consistency with pthreads-win32. The set can also be read online at: +http://sources.redhat.com/pthreads-win32manual/index.html -MSVS: -Intel Core i7 (6 Core HT) -Windows 7 64 bit -MSVS 2010 Express with SDK 7.1 (using the SDK command shell) -TARGET_CPU = x64 and x86 +Thanks again to Tim Theisen for running the test suite pre-release +on an MP system. -GNU: -Intel Core i7 (6 Core HT) -Windows 7 64 bit -MinGW64 multilib enabled -ARCH = -m32 and -m64 +All of the bug fixes and new features in this release have been +back-ported in release 1.9.0. +Bugs fixed +---------- -Building with MS Visual Studio (C, VC++ using C++ EH, or Structured EH) ------------------------------------------------------------------------ +* Thread Specific Data (TSD) key management has been ammended to +eliminate a source of (what was effectively) resource leakage (a HANDLE +plus memory for each key destruct routine/thread association). This was +not a true leak because these resources were eventually reclaimed when +pthread_key_delete was run AND each thread referencing the key had exited. +The problem was that these two conditions are often not met until very +late, and often not until the process is about to exit. -From the source directory run nmake without any arguments to list -help information. E.g. +The ammended implementation avoids the need for the problematic HANDLE +and reclaims the memory as soon as either the key is deleted OR the +thread exits, whichever is first. -$ nmake +Thanks to Richard Hughes at Aculab for identifying and locating the leak. -As examples, as at Release 2.10 the pre-built DLLs and static libraries -are built from the following command-lines: +* TSD key destructors are now processed up to PTHREAD_DESTRUCTOR_ITERATIONS +times instead of just once. PTHREAD_DESTRUCTOR_ITERATIONS has been +defined in pthread.h for some time but not used. -[Note: "setenv" comes with the SDK. "/2003" is used to override my build -system which is Win7 (at the time of writing) for backwards compatibility.] +* Fix a semaphore accounting race between sem_post/sem_post_multiple +and sem_wait cancellation. This is the same issue as with +sem_timedwait that was fixed in the last release. -$ setenv /x64 /2003 /Release -$ nmake realclean VC -$ nmake realclean VCE -$ nmake realclean VSE -$ nmake realclean VC-static -$ nmake realclean VCE-static -$ nmake realclean VSE-static -$ setenv /x86 /2003 /Release -$ nmake realclean VC -$ nmake realclean VCE -$ nmake realclean VSE -$ nmake realclean VC-static -$ nmake realclean VCE-static -$ nmake realclean VSE-static +* sem_init, sem_post, and sem_post_multiple now check that the +semaphore count never exceeds _POSIX_SEM_VALUE_MAX. -If you want to differentiate between libraries by their names you can use, -e.g.: +* Although sigwait() is nothing more than a no-op, it should at least +be a cancellation point to be consistent with the standard. -$ nmake realclean VC EXTRAVERSION="-w64" +New tests +--------- -The string provided via the variable EXTRAVERSION is appended to the dll -and .lib library names, e.g.: +* stress1.c - attempts to expose problems in condition variable +and semaphore timed wait logic. This test was inspired by Stephan +Mueller's sample test code used to identify the sem_timedwait bug +from the last release. It's not a part of the regular test suite +because it can take awhile to run. To run it: +nmake clean VC-stress -pthreadVC2-w64.dll -pthreadVC2-w64.lib +* tsd2.c - tests that key destructors are re-run if the tsd key value is +not NULL after the destructor routine has run. Also tests that +pthread_setspecific() and pthread_getspecific() are callable from +destructors. -To build and test all DLLs and static lib compatibility versions -(VC, VCE, VSE): -[Note that the EXTRAVERSION="..." option is passed to the tests Makefile -when you target "all-tests". If you change to the tests directory and -run the tests you will need to repeat the option explicitly to the test -"nmake" command-line.] +RELEASE 2.4.0 +------------- +(2005-04-26) + +General +------- + +There is now no plan to release a version 3.0.0 to fix problems in +pthread_once(). Other possible implementations of pthread_once +will still be investigated for a possible future release in an attempt +to reduce the current implementation's complexity. + +All of the bug fixes and new features in this release have been +back-ported for release 1.8.0. + +Bugs fixed +---------- + +* Fixed pthread_once race (failures on an MP system). Thanks to +Tim Theisen for running exhaustive pre-release testing on his MP system +using a range of compilers: + VC++ 6 + VC++ 7.1 + Intel C++ version 8.0 +All tests passed. +Some minor speed improvements were also done. + +* Fix integer overrun error in pthread_mutex_timedlock() - missed when +sem_timedwait() was fixed in release 2.2.0. This routine no longer returns +ENOTSUP when NEED_SEM is defined - it is supported (NEED_SEM is only +required for WinCE versions prior to 3.0). + +* Fix timeout bug in sem_timedwait(). +- Thanks to Stephan Mueller for reporting, providing diagnostic output +and test code. + +* Fix several problems in the NEED_SEM conditionally included code. +NEED_SEM included code is provided for systems that don't implement W32 +semaphores, such as WinCE prior to version 3.0. An alternate implementation +of POSIX semaphores is built using W32 events for these systems when +NEED_SEM is defined. This code has been completely rewritten in this +release to reuse most of the default POSIX semaphore code, and particularly, +to implement all of the sem_* routines supported by pthreads-win32. Tim +Theisen also run the test suite over the NEED_SEM code on his MP system. All +tests passed. + +* The library now builds without errors for the Borland Builder 5.5 compiler. + +New features +------------ -$ setenv /x64 /2003 /release -$ nmake all-tests +* pthread_mutex_timedlock() and all sem_* routines provided by +pthreads-win32 are now implemented for WinCE versions prior to 3.0. Those +versions did not implement W32 semaphores. Define NEED_SEM in config.h when +building the library for these systems. -You can run the testsuite by changing to the "tests" directory and -running nmake. E.g.: +Known issues in this release +---------------------------- -$ cd tests -$ nmake VC +* pthread_once is too complicated - but it works as far as testing can +determine.. -For failure analysis etc. individual tests can be built -and run, e.g: +* The Borland version of the dll fails some of the tests with a memory read +exception. The cause is not yet known but a compiler bug has not been ruled +out. -$ cd tests -$ nmake VC TESTS="foo bar" -This builds and runs all prerequisite tests as well as the individual -tests listed. Prerequisite tests are defined in tests\runorder.mk. +RELEASE 2.3.0 +------------- +(2005-04-12) -To build and run only those tests listed use, i.e. without the -additional prerequistite dependency tests: +General +------- -$ cd tests -$ nmake VC NO_DEPS=1 TESTS="foo bar" +Release 1.7.0 is a backport of features and bug fixes new in +this release. See earlier notes under Release 2.0.0/General. +Bugs fixed +---------- -Building with MinGW -------------------- +* Fixed pthread_once potential for post once_routine cancellation +hanging due to starvation. See comments in pthread_once.c. +Momentary priority boosting is used to ensure that, after a +once_routine is cancelled, the thread that will run the +once_routine is not starved by higher priority waiting threads at +critical times. Priority boosting occurs only AFTER a once_routine +cancellation, and is applied only to that once_control. The +once_routine is run at the thread's normal base priority. -Please use Mingw64 to build either 64 or 32 bit variants of the DLL that will -run on 64 bit systems. We have found that Mingw32 builds of the GCE library -variants fail when run on 64 bit systems. +New tests +--------- -From the source directory, run 'make' without arguments for help information. +* once4.c: Aggressively tests pthread_once() under realtime +conditions using threads with varying priorities. Windows' +random priority boosting does not occur for threads with realtime +priority levels. -$ make -With MinGW64 multilib installed the following variables can be defined -either on the make command line or in the shell environment: +RELEASE 2.2.0 +------------- +(2005-04-04) -ARCH - - possible values are "-m64" and "-m32". You will probably recognise - these as gcc flags however the GNUmakefile also converts these into - the appropriate windres options when building version.o. +General +------- -As examples, as at Release 2.10 the pre-built DLLs and static libraries -are built from the following command-lines: +* Added makefile targets to build static link versions of the library. +Both MinGW and MSVC. Please note that this does not imply any change +to the LGPL licensing, which still imposes psecific conditions on +distributing software that has been statically linked with this library. -$ nmake realclean GC ARCH=-m64 -$ nmake realclean GC ARCH=-m32 -$ nmake realclean GCE ARCH=-m64 -$ nmake realclean GCE ARCH=-m32 -$ nmake realclean GC-static ARCH=-m64 -$ nmake realclean GC-static ARCH=-m32 -$ nmake realclean GCE-static ARCH=-m64 -$ nmake realclean GCE-static ARCH=-m32 +* There is a known bug in pthread_once(). Cancellation of the init_routine +exposes a potential starvation (i.e. deadlock) problem if a waiting thread +has a higher priority than the initting thread. This problem will be fixed +in version 3.0.0 of the library. -If you want to differentiate between libraries by their names you can use, -e.g.: +Bugs fixed +---------- -$ make realclean GC ARCH="-m64" EXTRAVERSION="-w64" +* Fix integer overrun error in sem_timedwait(). +Kevin Lussier -The string provided via the variable EXTRAVERSION is appended to the dll -and .a library names, e.g.: +* Fix preprocessor directives for static linking. +Dimitar Panayotov -pthreadGC2-w64.dll -libpthreadGC2-w64.a -To build and test all DLLs and static lib compatibility variants (GC, GCE): +RELEASE 2.1.0 +------------- +(2005-03-16) -Note that the ARCH="..." and/or EXTRAVERSION="..." options are passed to the -tests GNUmakefile when you target "all-tests". If you change to the tests -directory and run the tests you will need to repeat those options explicitly -to the test "make" command-line. +Bugs fixed +---------- -$ make all-tests -or, with MinGW64 (multilib enabled): -$ make all-tests ARCH=-m64 -$ make all-tests ARCH=-m32 +* Reverse change to pthread_setcancelstate() in 2.0.0. -You can run the testsuite by changing to the "tests" directory and -running make. E.g.: -$ cd tests -$ make GC +RELEASE 2.0.0 +------------- +(2005-03-16) -For failure analysis etc. individual tests can be built and run, e.g: +General +------- -$ cd tests -$ make GC TESTS="foo bar" +This release represents an ABI change and the DLL version naming has +incremented from 1 to 2, e.g. pthreadVC2.dll. -This builds and runs all prerequisite tests as well as the individual -tests listed. Prerequisite tests are defined in tests\runorder.mk. +Version 1.4.0 back-ports the new functionality included in this +release. Please distribute DLLs built from that version with updates +to applications built on pthreads-win32 version 1.x.x. -To build and run only those tests listed use, i.e. without the additional -prerequistite dependency tests: +The package naming has changed, replacing the snapshot date with +the version number + descriptive information. E.g. this +release is "pthreads-win32-2-0-0-release". -$ cd tests -$ make GC NO_DEPS=1 TESTS="foo bar" +Bugs fixed +---------- +* pthread_setcancelstate() no longer checks for a pending +async cancel event if the library is using alertable async +cancel. See the README file (Prerequisites section) for info +on adding alertable async cancellation. -Building under Linux using the MinGW cross development tools ------------------------------------------------------------- +New features +------------ -You can build the library on Linux by using the MinGW cross development -toolchain. See http://www.libsdl.org/extras/win32/cross/ for tools and -info. The GNUmakefile contains some support for this, for example: +* pthread_once() now supports init_routine cancellability. -make CROSS=i386-mingw32msvc- clean GC +New tests +--------- -will build pthreadGCn.dll and libpthreadGCn.a (n=version#), provided your -cross-tools/bin directory is in your PATH (or use the cross-make.sh script -at the URL above). +* Agressively test pthread_once() init_routine cancellability. -Building the library as a statically linkable library ------------------------------------------------------ +SNAPSHOT 2005-03-08 +------------------- +Version 1.3.0 -General: PTW32_STATIC_LIB must be defined for both the library build and the -application build. The makefiles supplied and used by the following 'make' -command lines will define this for you. +Bug reports (fixed) +------------------- -MSVC (creates pthreadVCn.lib as a static link lib): +* Implicitly created threads leave Win32 handles behind after exiting. +- Dmitrii Semii -nmake clean VC-static +* pthread_once() starvation problem. +- Gottlob Frege +New tests +--------- -MinGW32 (creates libpthreadGCn.a as a static link lib): +* More intense testing of pthread_once(). -make clean GC-static -Define PTW32_STATIC_LIB also when building your application. +SNAPSHOT 2005-01-25 +------------------- +Version 1.2.0 -Building the library under Cygwin ---------------------------------- +Bug fixes +--------- -Cygwin implements it's own POSIX threads routines and these -will be the ones to use if you develop using Cygwin. +* Attempted acquisition of a recursive mutex could cause waiting threads +to not be woken when the mutex was released. +- Ralf Kubis +* Various package omissions have been fixed. -Ready to run binaries ---------------------- -For convenience, the following ready-to-run files can be downloaded -from the FTP site (see under "Availability" below): +SNAPSHOT 2005-01-03 +------------------- +Version 1.1.0 - pthread.h - semaphore.h - sched.h - pthreadVC2.dll - built with MSVC compiler using C setjmp/longjmp - pthreadVC2.lib - pthreadVCE2.dll - built with MSVC++ compiler using C++ EH - pthreadVCE2.lib - pthreadVSE2.dll - built with MSVC compiler using SEH - pthreadVSE2.lib - pthreadGC2.dll - built with Mingw32 GCC - libpthreadGC2.a - derived from pthreadGC.dll - pthreadGCE2.dll - built with Mingw32 G++ - libpthreadGCE2.a - derived from pthreadGCE.dll +Bug fixes +--------- -You may also need to include runtime DLLs from your SDK when -distributing your applications. +* Unlocking recursive or errorcheck mutexes would sometimes +unexpectedly return an EPERM error (bug introduced in +snapshot-2004-11-03). +- Konstantin Voronkov -Building applications with GNU compilers ----------------------------------------- -If you're using pthreadGC2.dll: +SNAPSHOT 2004-11-22 +------------------- +Version 1.0.0 -With the three header files, pthreadGC2.dll and libpthreadGC2.a in the -same directory as your application myapp.c, you could compile, link -and run myapp.c under MinGW as follows: +This snapshot primarily fixes the condvar bug introduced in +snapshot-2004-11-03. DLL versioning has also been included to allow +applications to runtime check the Microsoft compatible DLL version +information, and to extend the DLL naming system for ABI and major +(non-backward compatible) API changes. See the README file for details. - gcc -o myapp.exe myapp.c -I. -L. -lpthreadGC2 - myapp +Bug fixes +--------- -Or put pthreadGC2.dll in an appropriate directory in your PATH, -put libpthreadGC2.a in your system lib directory, and -put the three header files in your system include directory, -then use: +* Condition variables no longer deadlock (bug introduced in +snapshot-2004-11-03). +- Alexander Kotliarov and Nicolas at saintmac - gcc -o myapp.exe myapp.c -lpthreadGC - myapp +* DLL naming extended to avoid 'DLL hell' in the future, and to +accommodate the ABI change introduced in snapshot-2004-11-03. Snapshot +2004-11-03 will be removed from FTP sites. +New features +------------ -If you're using pthreadGCE2.dll: +* A Microsoft-style version resource has been added to the DLL for +applications that wish to check DLL compatibility at runtime. -With the three header files, pthreadGCE2.dll and libpthreadGCE2.a -in the same directory as your application myapp.c, you could compile, -link and run myapp.c under Mingw32 as follows: +* pthreads-win32 DLL naming has been extended to allow incompatible DLL +versions to co-exist in the same filesystem. See the README file for details, +but briefly: while the version information inside the DLL will change with +each release from now on, the DLL version names will only change if the new +DLL is not backward compatible with older applications. - gcc -x c++ -o myapp.exe myapp.c -I. -L. -lpthreadGCE2 - myapp +The versioning scheme has been borrowed from GNU Libtool, and the DLL +naming scheme is from Cygwin. Provided the Libtool-style numbering rules are +honoured, the Cygwin DLL naming scheme automatcally ensures that DLL name +changes are minimal and that applications will not load an incompatible +pthreads-win32 DLL. -Or put pthreadGCE.dll and gcc.dll in an appropriate directory in -your PATH, put libpthreadGCE.a in your system lib directory, and -put the three header files in your system include directory, -then use: +Those who use the pre-built DLLs will find that the DLL/LIB names have a new +suffix (1) in this snapshot. E.g. pthreadVC1.dll etc. - gcc -x c++ -o myapp.exe myapp.c -lpthreadGCE - myapp +* The POSIX thread ID reuse uniqueness feature introduced in the last snapshot +has been kept as default, but the behaviour can now be controlled when the DLL +is built to effectively switch it off. This makes the library much more +sensitive to applications that assume that POSIX thread IDs are unique, i.e. +are not strictly compliant with POSIX. See the PTW32_THREAD_ID_REUSE_INCREMENT +macro comments in config.h for details. +Other changes +------------- +Certain POSIX macros have changed. + +These changes are intended to conform to the Single Unix Specification version 3, +which states that, if set to 0 (zero) or not defined, then applications may use +sysconf() to determine their values at runtime. pthreads-win32 does not +implement sysconf(). + +The following macros are no longer undefined, but defined and set to -1 +(not implemented): + + _POSIX_THREAD_ATTR_STACKADDR + _POSIX_THREAD_PRIO_INHERIT + _POSIX_THREAD_PRIO_PROTECT + _POSIX_THREAD_PROCESS_SHARED + +The following macros are defined and set to 200112L (implemented): + + _POSIX_THREADS + _POSIX_THREAD_SAFE_FUNCTIONS + _POSIX_THREAD_ATTR_STACKSIZE + _POSIX_THREAD_PRIORITY_SCHEDULING + _POSIX_SEMAPHORES + _POSIX_READER_WRITER_LOCKS + _POSIX_SPIN_LOCKS + _POSIX_BARRIERS + +The following macros are defined and set to appropriate values: + + _POSIX_THREAD_THREADS_MAX + _POSIX_SEM_VALUE_MAX + _POSIX_SEM_NSEMS_MAX + PTHREAD_DESTRUCTOR_ITERATIONS + PTHREAD_KEYS_MAX + PTHREAD_STACK_MIN + PTHREAD_THREADS_MAX + + +SNAPSHOT 2004-11-03 +------------------- + +DLLs produced from this snapshot cannot be used with older applications without +recompiling the application, due to a change to pthread_t to provide unique POSIX +thread IDs. + +Although this snapshot passes the extended test suite, many of the changes are +fairly major, and some applications may show different behaviour than previously, +so adopt with care. Hopefully, any changed behaviour will be due to the library +being better at it's job, not worse. + +Bug fixes +--------- -Availability +* pthread_create() no longer accepts NULL as the thread reference arg. +A segfault (memory access fault) will result, and no thread will be +created. + +* pthread_barrier_wait() no longer acts as a cancellation point. + +* Fix potential race condition in pthread_once() +- Tristan Savatier + +* Changes to pthread_cond_destroy() exposed some coding weaknesses in several +test suite mini-apps because pthread_cond_destroy() now returns EBUSY if the CV +is still in use. + +New features ------------ -The complete source code in either unbundled, self-extracting -Zip file, or tar/gzipped format can be found at: +* Added for compatibility: +PTHREAD_RECURSIVE_MUTEX_INITIALIZER, +PTHREAD_ERRORCHECK_MUTEX_INITIALIZER, +PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP, +PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP + +* Initial support for Digital Mars compiler +- Anuj Goyal + +* Faster Mutexes. These have been been rewritten following a model provided by +Alexander Terekhov that reduces kernel space checks, and eliminates some additional +critical sections used to manage a race between timedlock expiration and unlock. +Please be aware that the new mutexes do not enforce strict absolute FIFO scheduling +of mutexes, however any out-of-order lock acquisition should be very rare. + +* Faster semaphores. Following a similar model to mutexes above, these have been +rewritten to use preliminary users space checks. + +* sem_getvalue() now returns the number of waiters. + +* The POSIX thread ID now has much stronger uniqueness characteristics. The library +garrantees not to reuse the same thread ID for at least 2^(wordsize) thread +destruction/creation cycles. + +New tests +--------- + +* semaphore4.c: Tests cancellation of the new sem_wait(). + +* semaphore4t.c: Likewise for sem_timedwait(). + +* rwlock8.c: Tests and times the slow execution paths of r/w locks, and the CVs, +mutexes, and semaphores that they're built on. + - ftp://sources.redhat.com/pub/pthreads-win32 +SNAPSHOT 2004-05-16 +------------------- + +Attempt to add Watcom to the list of compilers that can build the library. +This failed in the end due to it's non-thread-aware errno. The library +builds but the test suite fails. See README.Watcom for more details. -The pre-built DLL, export libraries and matching pthread.h can -be found at: +Bug fixes +--------- +* Bug and memory leak in sem_init() +- Alex Blanco - ftp://sources.redhat.com/pub/pthreads-win32/dll-latest +* ptw32_getprocessors() now returns CPU count of 1 for WinCE. +- James Ewing -Home page: +* pthread_cond_wait() could be canceled at a point where it should not +be cancelable. Fixed. +- Alexander Terekhov - http://sources.redhat.com/pthreads-win32/ +* sem_timedwait() had an incorrect timeout calculation. +- Philippe Di Cristo +* Fix a memory leak left behind after threads are destroyed. +- P. van Bruggen -Mailing list +New features ------------ +* Ported to AMD64. +- Makoto Kato + +* True pre-emptive asynchronous cancellation of threads. This is optional +and requires that Panagiotis E. Hadjidoukas's QueueUserAPCEx package be +installed. This package is included in the pthreads-win32 self-unpacking +Zip archive starting from this snapshot. See the README.txt file inside +the package for installation details. + +Note: If you don't use async cancellation in your application, or don't need +to cancel threads that are blocked on system resources such as network I/O, +then the default non-preemptive async cancellation is probably good enough. +However, pthreads-win32 auto-detects the availability of these components +at run-time, so you don't need to rebuild the library from source if you +change your mind later. + +All of the advice available in books and elsewhere on the undesirability +of using async cancellation in any application still stands, but this +feature is a welcome addition with respect to the library's conformance to +the POSIX standard. + +SNAPSHOT 2003-09-18 +------------------- -There is a mailing list for discussing pthreads on Win32. -To join, send email to: +Cleanup of thread priority management. In particular, setting of thread +priority now attempts to map invalid Win32 values within the range returned +by sched_get_priority_min/max() to useful values. See README.NONPORTABLE +under "Thread priority". - pthreads-win32-subscribe@sources.redhat.com +Bug fixes +--------- +* pthread_getschedparam() now returns the priority given by the most recent +call to pthread_setschedparam() or established by pthread_create(), as +required by the standard. Previously, pthread_getschedparam() incorrectly +returned the running thread priority at the time of the call, which may have +been adjusted or temporarily promoted/demoted. -Unsubscribe by sending mail to: +* sched_get_priority_min() and sched_get_priority_max() now return -1 on error +and set errno. Previously, they incorrectly returned the error value directly. - pthreads-win32-unsubscribe@sources.redhat.com +SNAPSHOT 2003-09-04 +------------------- -Acknowledgements ----------------- +Bug fixes +--------- +* ptw32_cancelableWait() now allows cancellation of waiting implicit POSIX +threads. -See the ANNOUNCE file for acknowledgements. -See the 'CONTRIBUTORS' file for the list of contributors. +New test +-------- +* cancel8.c tests cancellation of Win32 threads waiting at a POSIX cancellation +point. -As much as possible, the ChangeLog file attributes -contributions and patches that have been incorporated -in the library to the individuals responsible. -Finally, thanks to all those who work on and contribute to the -POSIX and Single Unix Specification standards. The maturity of an -industry can be measured by it's open standards. +SNAPSHOT 2003-09-03 +------------------- + +Bug fixes +--------- +* pthread_self() would free the newly created implicit POSIX thread handle if +DuplicateHandle failed instead of recycle it (very unlikely). + +* pthread_exit() was neither freeing nor recycling the POSIX thread struct +for implicit POSIX threads. + +New feature - cancellation of/by Win32 (non-POSIX) threads +--------------------------------------------------------- +Since John Bossom's original implementation, the library has allowed non-POSIX +initialised threads (Win32 threads) to call pthreads-win32 routines and +therefore interact with POSIX threads. This is done by creating an on-the-fly +POSIX thread ID for the Win32 thread that, once created, allows fully +reciprical interaction. This did not extend to thread cancellation (async or +deferred). Now it does. + +Any thread can be canceled by any other thread (Win32 or POSIX) if the former +thread's POSIX pthread_t value is known. It's TSD destructors and POSIX +cleanup handlers will be run before the thread exits with an exit code of +PTHREAD_CANCELED (retrieved with GetExitCodeThread()). + +This allows a Win32 thread to, for example, call POSIX CV routines in the same way +that POSIX threads would/should, with pthread_cond_wait() cancelability and +cleanup handlers (pthread_cond_wait() is a POSIX cancellation point). + +By adding cancellation, Win32 threads should now be able to call all POSIX +threads routines that make sense including semaphores, mutexes, condition +variables, read/write locks, barriers, spinlocks, tsd, cleanup push/pop, +cancellation, pthread_exit, scheduling, etc. + +Note that these on-the-fly 'implicit' POSIX thread IDs are initialised as detached +(not joinable) with deferred cancellation type. The POSIX thread ID will be created +automatically by any POSIX routines that need a POSIX handle (unless the routine +needs a pthread_t as a parameter of course). A Win32 thread can discover it's own +POSIX thread ID by calling pthread_self(), which will create the handle if +necessary and return the pthread_t value. + +New tests +--------- +Test the above new feature. + + +SNAPSHOT 2003-08-19 +------------------- + +This snapshot fixes some accidental corruption to new test case sources. +There are no changes to the library source code. + + +SNAPSHOT 2003-08-15 +------------------- + +Bug fixes +--------- + +* pthread.dsp now uses correct compile flags (/MD). +- Viv + +* pthread_win32_process_detach_np() fixed memory leak. +- Steven Reddie + +* pthread_mutex_destroy() fixed incorrect return code. +- Nicolas Barry + +* pthread_spin_destroy() fixed memory leak. +- Piet van Bruggen + +* Various changes to tighten arg checking, and to work with later versions of +MinGW32 and MsysDTK. + +* pthread_getschedparam() etc, fixed dangerous thread validity checking. +- Nicolas Barry + +* POSIX thread handles are now reused and their memory is not freed on thread exit. +This allows for stronger thread validity checking. + +New standard routine +-------------------- + +* pthread_kill() added to provide thread validity checking to applications. +It does not accept any non zero values for the signal arg. + +New test cases +-------------- + +* New test cases to confirm validity checking, pthread_kill(), and thread reuse. + + +SNAPSHOT 2003-05-10 +------------------- + +Bug fixes +--------- + +* pthread_mutex_trylock() now returns correct error values. +pthread_mutex_destroy() will no longer destroy a recursively locked mutex. +pthread_mutex_lock() is no longer inadvertantly behaving as a cancellation point. +- Thomas Pfaff + +* pthread_mutex_timedlock() no longer occasionally sets incorrect mutex +ownership, causing deadlocks in some applications. +- Robert Strycek and Alexander Terekhov + + +SNAPSHOT 2002-11-04 +------------------- + +Bug fixes +--------- + +* sem_getvalue() now returns the correct value under Win NT and WinCE. +- Rob Fanner + +* sem_timedwait() now uses tighter checks for unreasonable +abstime values - that would result in unexpected timeout values. + +* ptw32_cond_wait_cleanup() no longer mysteriously consumes +CV signals but may produce more spurious wakeups. It is believed +that the sem_timedwait() call is consuming a CV signal that it +shouldn't. +- Alexander Terekhov + +* Fixed a memory leak in ptw32_threadDestroy() for implicit threads. + +* Fixed potential for deadlock in pthread_cond_destroy(). +A deadlock could occur for statically declared CVs (PTHREAD_COND_INITIALIZER), +when one thread is attempting to destroy the condition variable while another +is attempting to dynamically initialize it. +- Michael Johnson + + +SNAPSHOT 2002-03-02 +------------------- + +Cleanup code default style. (IMPORTANT) +---------------------------------------------------------------------- +Previously, if not defined, the cleanup style was determined automatically +from the compiler/language, and one of the following was defined accordingly: + + PTW32_CLEANUP_SEH MSVC only + PTW32_CLEANUP_CXX C++, including MSVC++, GNU G++ + PTW32_CLEANUP_C C, including GNU GCC, not MSVC + +These defines determine the style of cleanup (see pthread.h) and, +most importantly, the way that cancellation and thread exit (via +pthread_exit) is performed (see the routine ptw32_throw() in private.c). + +In short, the exceptions versions of the library throw an exception +when a thread is canceled or exits (via pthread_exit()), which is +caught by a handler in the thread startup routine, so that the +the correct stack unwinding occurs regardless of where the thread +is when it's canceled or exits via pthread_exit(). + +In this and future snapshots, unless the build explicitly defines (e.g. +via a compiler option) PTW32_CLEANUP_SEH, PTW32_CLEANUP_CXX, or PTW32_CLEANUP_C, then +the build NOW always defaults to PTW32_CLEANUP_C style cleanup. This style +uses setjmp/longjmp in the cancellation and pthread_exit implementations, +and therefore won't do stack unwinding even when linked to applications +that have it (e.g. C++ apps). This is for consistency with most +current commercial Unix POSIX threads implementations. Compaq's TRU64 +may be an exception (no pun intended) and possible future trend. + +Although it was not clearly documented before, it is still necessary to +build your application using the same PTW32_CLEANUP_* define as was +used for the version of the library that you link with, so that the +correct parts of pthread.h are included. That is, the possible +defines require the following library versions: + + PTW32_CLEANUP_SEH pthreadVSE.dll + PTW32_CLEANUP_CXX pthreadVCE.dll or pthreadGCE.dll + PTW32_CLEANUP_C pthreadVC.dll or pthreadGC.dll + +E.g. regardless of whether your app is C or C++, if you link with +pthreadVC.lib or libpthreadGC.a, then you must define PTW32_CLEANUP_C. + + +THE POINT OF ALL THIS IS: if you have not been defining one of these +explicitly, then the defaults as described at the top of this +section were being used. + +THIS NOW CHANGES, as has been explained above, but to try to make this +clearer here's an example: + +If you were building your application with MSVC++ i.e. using C++ +exceptions and not explicitly defining one of PTW32_CLEANUP_*, then +PTW32_CLEANUP_C++ was automatically defined for you in pthread.h. +You should have been linking with pthreadVCE.dll, which does +stack unwinding. + +If you now build your application as you had before, pthread.h will now +automatically set PTW32_CLEANUP_C as the default style, and you will need to +link with pthreadVC.dll. Stack unwinding will now NOT occur when a thread +is canceled, or the thread calls pthread_exit(). + +Your application will now most likely behave differently to previous +versions, and in non-obvious ways. Most likely is that locally +instantiated objects may not be destroyed or cleaned up after a thread +is canceled. + +If you want the same behaviour as before, then you must now define +PTW32_CLEANUP_C++ explicitly using a compiler option and link with +pthreadVCE.dll as you did before. + + +WHY ARE WE MAKING THE DEFAULT STYLE LESS EXCEPTION-FRIENDLY? +Because no commercial Unix POSIX threads implementation allows you to +choose to have stack unwinding. Therefore, providing it in pthread-win32 +as a default is dangerous. We still provide the choice but unless +you consciously choose to do otherwise, your pthreads applications will +now run or crash in similar ways irrespective of the threads platform +you use. Or at least this is the hope. + + +WHY NOT REMOVE THE EXCEPTIONS VERSIONS OF THE LIBRARY ALTOGETHER? +There are a few reasons: +- because there are well respected POSIX threads people who believe + that POSIX threads implementations should be exceptions aware and + do the expected thing in that context. (There are equally respected + people who believe it should not be easily accessible, if it's there + at all, for unconditional conformity to other implementations.) +- because pthreads-win32 is one of the few implementations that has + the choice, perhaps the only freely available one, and so offers + a laboratory to people who may want to explore the effects; +- although the code will always be around somewhere for anyone who + wants it, once it's removed from the current version it will not be + nearly as visible to people who may have a use for it. + + +Source module splitting +----------------------- +In order to enable smaller image sizes to be generated +for applications that link statically with the library, +most routines have been separated out into individual +source code files. + +This is being done in such a way as to be backward compatible. +The old source files are reused to congregate the individual +routine files into larger translation units (via a bunch of +# includes) so that the compiler can still optimise wherever +possible, e.g. through inlining, which can only be done +within the same translation unit. + +It is also possible to build the entire library by compiling +the single file named "pthread.c", which just #includes all +the secondary congregation source files. The compiler +may be able to use this to do more inlining of routines. + +Although the GNU compiler is able to produce libraries with +the necessary separation (the -ffunction-segments switch), +AFAIK, the MSVC and other compilers don't have this feature. + +Finally, since I use makefiles and command-line compilation, +I don't know what havoc this reorganisation may wreak amongst +IDE project file users. You should be able to continue +using your existing project files without modification. + + +New non-portable functions +-------------------------- +pthread_num_processors_np(): + Returns the number of processors in the system that are + available to the process, as determined from the processor + affinity mask. + +pthread_timechange_handler_np(): + To improve tolerance against operator or time service initiated + system clock changes. + + This routine can be called by an application when it + receives a WM_TIMECHANGE message from the system. At present + it broadcasts all condition variables so that waiting threads + can wake up and re-evaluate their conditions and restart + their timed waits if required. + - Suggested by Alexander Terekhov + + +Platform dependence +------------------- +As Win95 doesn't provide one, the library now contains +it's own InterlockedCompareExchange() routine, which is used +whenever Windows doesn't provide it. InterlockedCompareExchange() +is used to implement spinlocks and barriers, and also in mutexes. +This routine relies on the CMPXCHG machine instruction which +is not available on i386 CPUs. This library (from snapshot +20010712 onwards) is therefore no longer supported on i386 +processor platforms. + + +New standard routines +--------------------- +For source code portability only - rwlocks cannot be process shared yet. + + pthread_rwlockattr_init() + pthread_rwlockattr_destroy() + pthread_rwlockattr_setpshared() + pthread_rwlockattr_getpshared() + +As defined in the new POSIX standard, and the Single Unix Spec version 3: + + sem_timedwait() + pthread_mutex_timedlock() - Alexander Terekhov and Thomas Pfaff + pthread_rwlock_timedrdlock() - adapted from pthread_rwlock_rdlock() + pthread_rwlock_timedwrlock() - adapted from pthread_rwlock_wrlock() + + +pthread.h no longer includes windows.h +-------------------------------------- +[Not yet for G++] + +This was done to prevent conflicts. + +HANDLE, DWORD, and NULL are temporarily defined within pthread.h if +they are not already. + + +pthread.h, sched.h and semaphore.h now use dllexport/dllimport +-------------------------------------------------------------- +Not only to avoid the need for the pthread.def file, but to +improve performance. Apparently, declaring functions with dllimport +generates a direct call to the function and avoids the overhead +of a stub function call. + +Bug fixes +--------- +* Fixed potential NULL pointer dereferences in pthread_mutexattr_init, +pthread_mutexattr_getpshared, pthread_barrierattr_init, +pthread_barrierattr_getpshared, and pthread_condattr_getpshared. +- Scott McCaskill + +* Removed potential race condition in pthread_mutex_trylock and +pthread_mutex_lock; +- Alexander Terekhov + +* The behaviour of pthread_mutex_trylock in relation to +recursive mutexes was inconsistent with commercial implementations. +Trylock would return EBUSY if the lock was owned already by the +calling thread regardless of mutex type. Trylock now increments the +recursion count and returns 0 for RECURSIVE mutexes, and will +return EDEADLK rather than EBUSY for ERRORCHECK mutexes. This is +consistent with Solaris. +- Thomas Pfaff + +* Found a fix for the library and workaround for applications for +the known bug #2, i.e. where PTW32_CLEANUP_CXX or PTW32_CLEANUP_SEH is defined. +See the "Known Bugs in this snapshot" section below. + +This could be made transparent to applications by replacing the macros that +define the current C++ and SEH versions of pthread_cleanup_push/pop +with the C version, but AFAIK cleanup handlers would not then run in the +correct sequence with destructors and exception cleanup handlers when +an exception occurs. + +* cancellation once started in a thread cannot now be inadvertantly +double canceled. That is, once a thread begins it's cancellation run, +cancellation is disabled and a subsequent cancel request will +return an error (ESRCH). + +* errno: An incorrect compiler directive caused a local version +of errno to be used instead of the Win32 errno. Both instances are +thread-safe but applications checking errno after a pthreads-win32 +call would be wrong. Fixing this also fixed a bad compiler +option in the testsuite (/MT should have been /MD) which is +needed to link with the correct library MSVCRT.LIB. + + +SNAPSHOT 2001-07-12 +------------------- + +To be added + + +SNAPSHOT 2001-07-03 +------------------- + +To be added + + +SNAPSHOT 2000-08-13 +------------------- + +New: +- Renamed DLL and LIB files: + pthreadVSE.dll (MS VC++/Structured EH) + pthreadVSE.lib + pthreadVCE.dll (MS VC++/C++ EH) + pthreadVCE.lib + pthreadGCE.dll (GNU G++/C++ EH) + libpthreadw32.a + + Both your application and the pthread dll should use the + same exception handling scheme. + +Bugs fixed: +- MSVC++ C++ exception handling. + +Some new tests have been added. + + +SNAPSHOT 2000-08-10 +------------------- + +New: +- asynchronous cancellation on X86 (Jason Nye) +- Makefile compatible with MS nmake to replace + buildlib.bat +- GNUmakefile for Mingw32 +- tests/Makefile for MS nmake replaces runall.bat +- tests/GNUmakefile for Mingw32 + +Bugs fixed: +- kernel32 load/free problem +- attempt to hide internel exceptions from application + exception handlers (__try/__except and try/catch blocks) +- Win32 thread handle leakage bug + (David Baggett/Paul Redondo/Eyal Lebedinsky) + +Some new tests have been added. + + +SNAPSHOT 1999-11-02 +------------------- + +Bugs fixed: +- ctime_r macro had an incorrect argument (Erik Hensema), +- threads were not being created + PTHREAD_CANCEL_DEFERRED. This should have + had little effect as deferred is the only + supported type. (Ross Johnson). + +Some compatibility improvements added, eg. +- pthread_setcancelstate accepts NULL pointer + for the previous value argument. Ditto for + pthread_setcanceltype. This is compatible + with Solaris but should not affect + standard applications (Erik Hensema) + +Some new tests have been added. + + +SNAPSHOT 1999-10-17 +------------------- + +Bug fix - cancellation of threads waiting on condition variables +now works properly (Lorin Hochstein and Peter Slacik) + + +SNAPSHOT 1999-08-12 +------------------- + +Fixed exception stack cleanup if calling pthread_exit() +- (Lorin Hochstein and John Bossom). + +Fixed bugs in condition variables - (Peter Slacik): + - additional contention checks + - properly adjust number of waiting threads after timed + condvar timeout. + + +SNAPSHOT 1999-05-30 +------------------- + +Some minor bugs have been fixed. See the ChangeLog file for details. + +Some more POSIX 1b functions are now included but ony return an +error (ENOSYS) if called. They are: + + sem_open + sem_close + sem_unlink + sem_getvalue + + +SNAPSHOT 1999-04-07 +------------------- + +Some POSIX 1b functions which were internally supported are now +available as exported functions: + + sem_init + sem_destroy + sem_wait + sem_trywait + sem_post + sched_yield + sched_get_priority_min + sched_get_priority_max + +Some minor bugs have been fixed. See the ChangeLog file for details. + + +SNAPSHOT 1999-03-16 +------------------- + +Initial release. ----- -Ross Johnson - \ No newline at end of file diff --git a/_ptw32.h b/_ptw32.h new file mode 100644 index 00000000..3e8d114d --- /dev/null +++ b/_ptw32.h @@ -0,0 +1,215 @@ +/* + * Module: _ptw32.h + * + * Purpose: + * pthreads-win32 internal macros, to be shared by other headers + * comprising the pthreads4w package. + * + * -------------------------------------------------------------------------- + * + * pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999-2021 pthreads-win32 / pthreads4w contributors + * + * Homepage1: http://sourceware.org/pthreads-win32/ + * Homepage2: http://sourceforge.net/projects/pthreads4w/ + * + * The current list of contributors is contained + * in the file CONTRIBUTORS included with the source + * code distribution. The list can also be seen at the + * following World Wide Web location: + * http://sources.redhat.com/pthreads-win32/contributors.html + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library in the file COPYING.LIB; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * -------------------------------------------------------------------------- + */ + +#ifndef PTW32_H +#define PTW32_H + +/* See the README file for an explanation of the pthreads4w + * version numbering scheme and how the DLL is named etc. + */ +#define PTW32_VERSION_MAJOR 3 +#define PTW32_VERSION_MINOR 0 +#define PTW32_VERSION_MICRO 2 +#define PTW32_VERION_BUILD 0 +#define PTW32_VERSION 3,0,2,0 +#define PTW32_VERSION_STRING "3, 0, 2, 0\0" + +#if defined(__GNUC__) +# pragma GCC system_header +# if ! defined __declspec +# error "Please upgrade your GNU compiler to one that supports __declspec." +# endif +#endif + +#if defined (__cplusplus) +# define PTW32_BEGIN_C_DECLS extern "C" { +# define PTW32_END_C_DECLS } +#else +# define PTW32_BEGIN_C_DECLS +# define PTW32_END_C_DECLS +#endif + +#if defined PTW32_STATIC_LIB +# define PTW32_DLLPORT + +#elif defined PTW32_BUILD +# define PTW32_DLLPORT __declspec (dllexport) +#else +# define PTW32_DLLPORT /*__declspec (dllimport)*/ +#endif + +#ifndef PTW32_CDECL +/* FIXME: another internal macro; should have two initial underscores; + * Nominally, we prefer to use __cdecl calling convention for all our + * functions, but we map it through this macro alias to facilitate the + * possible choice of alternatives; for example: + */ +# ifdef _OPEN_WATCOM_SOURCE + /* The Open Watcom C/C++ compiler uses a non-standard default calling + * convention, (similar to __fastcall), which passes function arguments + * in registers, unless the __cdecl convention is explicitly specified + * in exposed function prototypes. + * + * Our preference is to specify the __cdecl convention for all calls, + * even though this could slow Watcom code down slightly. If you know + * that the Watcom compiler will be used to build both the DLL and your + * application, then you may #define _OPEN_WATCOM_SOURCE, so disabling + * the forced specification of __cdecl for all function declarations; + * remember that this must be defined consistently, for both the DLL + * build, and the application build. + */ +# define PTW32_CDECL +# else +# define PTW32_CDECL __cdecl +# endif +#endif + +/* + * This is more or less a duplicate of what is in the autoconf config.h, + * which is only used when building the pthreads4w libraries. + */ + +#if !defined (PTW32_CONFIG_H) && !defined(PTW32_PSEUDO_CONFIG_H_SOURCED) +# define PTW32_PSEUDO_CONFIG_H_SOURCED +# if defined(WINCE) +# undef HAVE_CPU_AFFINITY +# define NEED_DUPLICATEHANDLE +# define NEED_CREATETHREAD +# define NEED_ERRNO +# define NEED_CALLOC +# define NEED_UNICODE_CONSTS +# define NEED_PROCESS_AFFINITY_MASK +/* This may not be needed */ +# define RETAIN_WSALASTERROR +# elif defined(_MSC_VER) +# if _MSC_VER >= 1900 +# define HAVE_STRUCT_TIMESPEC +# elif _MSC_VER < 1300 +# define PTW32_CONFIG_MSVC6 +# elif _MSC_VER < 1400 +# define PTW32_CONFIG_MSVC7 +# endif +# elif defined(_UWIN) +# define HAVE_MODE_T +# define HAVE_STRUCT_TIMESPEC +# define HAVE_SIGNAL_H +# endif +#endif + +/* + * If HAVE_ERRNO_H is defined then assume that autoconf has been used + * to overwrite config.h, otherwise the original config.h is in use + * at build-time or the above block of defines is in use otherwise + * and NEED_ERRNO is either defined or not defined. + */ +#if defined(HAVE_ERRNO_H) || !defined(NEED_ERRNO) +# include +#else +# include "need_errno.h" +#endif + +#if defined(__BORLANDC__) +# define int64_t LONGLONG +# define uint64_t ULONGLONG +#elif !defined(__MINGW32__) + typedef _int64 int64_t; + typedef unsigned _int64 uint64_t; +# if defined (PTW32_CONFIG_MSVC6) + typedef long intptr_t; +# endif +#elif defined(HAVE_STDINT_H) && HAVE_STDINT_H == 1 +# include +#endif + +/* + * In case ETIMEDOUT hasn't been defined above somehow. + */ +#if !defined(ETIMEDOUT) + /* + * note: ETIMEDOUT is no longer defined in winsock.h + * WSAETIMEDOUT is so use its value. + */ +# include +# if defined(WSAETIMEDOUT) +# define ETIMEDOUT WSAETIMEDOUT +# else +# define ETIMEDOUT 10060 /* This is the value of WSAETIMEDOUT in winsock.h. */ +# endif +#endif + +/* + * Several systems may not define some error numbers; + * defining those which are likely to be missing here will let + * us complete the library builds. + */ +#if !defined(ENOTSUP) +# define ENOTSUP 48 /* This is the value in Solaris. */ +#endif + +#if !defined(ENOSYS) +# define ENOSYS 140 /* Semi-arbitrary value */ +#endif + +#if !defined(EDEADLK) +# if defined(EDEADLOCK) +# define EDEADLK EDEADLOCK +# else +# define EDEADLK 36 /* This is the value in MSVC. */ +# endif +#endif + +/* POSIX 2008 - related to robust mutexes */ +#if PTW32_VERSION_MAJOR > 2 +# if !defined(EOWNERDEAD) +# define EOWNERDEAD 1000 +# endif +# if !defined(ENOTRECOVERABLE) +# define ENOTRECOVERABLE 1001 +# endif +#else +# if !defined(EOWNERDEAD) +# define EOWNERDEAD 42 +# endif +# if !defined(ENOTRECOVERABLE) +# define ENOTRECOVERABLE 43 +# endif +#endif + +#endif /* !PTW32_H */ diff --git a/aclocal.m4 b/aclocal.m4 new file mode 100644 index 00000000..79c1a781 --- /dev/null +++ b/aclocal.m4 @@ -0,0 +1,122 @@ +## aclocal.m4 +## -------------------------------------------------------------------------- +## +## pthreads-win32 / pthreads4w - POSIX Threads for Windows +## Copyright 1998 John E. Bossom +## Copyright(C) 1999-2021 pthreads-win32 / pthreads4w contributors +## +## Homepage: http://sources.redhat.com/pthreads-win32 +## +## The current list of contributors is contained +## in the file CONTRIBUTORS included with the source +## code distribution. The list can also be seen at the +## following World Wide Web location: +## +## https://sourceforge.net/p/pthreads4w/wiki/Contributors/ +## +## This library is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 3 of the License, or (at your option) any later version. +## +## This library is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with this library in the file COPYING.LIB; +## if not, write to the Free Software Foundation, Inc., +## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA +## +# +# PTW32_AC_CHECK_TYPEDEF( TYPENAME, [HEADER] ) +# -------------------------------------------- +# Set HAVE_TYPENAME in config.h, if either HEADER, or any default +# header which autoconf checks automatically, defines TYPENAME. +# +AC_DEFUN([PTW32_AC_CHECK_TYPEDEF],dnl +[m4_ifnblank([$2],[AC_CHECK_HEADERS_ONCE([$2])]) + AC_CHECK_TYPE([$1],dnl + [AC_DEFINE(AS_TR_CPP([HAVE_$1]),[1],[Define if your compiler knows about $1])],,dnl + [AC_INCLUDES_DEFAULT + m4_ifnblank([$2],[[ +#ifdef ]AS_TR_CPP([HAVE_$2])[ +# include <$2> +#endif +]])])dnl +]) + +# PTW32_AC_NEED_FUNC( WITNESS, FUNCNAME ) +# --------------------------------------- +# Add a WITNESS definition in config.h, if FUNCNAME is not provided +# by the standard library, and a replacement must be provided. +# +AC_DEFUN([PTW32_AC_NEED_FUNC],dnl +[AC_CHECK_FUNCS([$2],,[AC_DEFINE([$1],[1],[Define if you do not have $2])])dnl +]) + +# PTW32_AC_NEED_ERRNO +# ------------------- +# Check if the host provides the header, and supports the +# errno global symbol, otherwise, add a NEED_ERRNO request in config.h +# +AC_DEFUN([PTW32_AC_NEED_ERRNO],[dnl +AC_CHECK_HEADERS_ONCE([errno.h]) +AC_MSG_CHECKING([for errno]) +AC_LINK_IFELSE([AC_LANG_SOURCE([[ +#ifdef HAVE_ERRNO_H +# include +#endif +int main(){ return errno; } +]])],dnl +[AC_MSG_RESULT([yes])],dnl +[AC_DEFINE([NEED_ERRNO],[1],[Define if you do not have errno]) + AC_MSG_RESULT([no])dnl +]) +]) + +# PTW32_AC_CHECK_WINAPI_FUNC( FUNCNAME, ARGUMENTS, ... ) +# ------------------------------------------------------ +# Check if the WinAPI function FUNCNAME is available on the host; +# unlike __cdecl functions, which can be detected by AC_CHECK_FUNCS, +# WinAPI functions need a full argument list specification in the +# function call. (Additional 3rd and 4th arguments provide for +# qualification of the yes/no messages, respectively; they may +# be exploited, for example, to add config.h annotations). +# +AC_DEFUN([PTW32_AC_CHECK_WINAPI_FUNC], +[AC_MSG_CHECKING([for $1]) + AC_LINK_IFELSE([AC_LANG_SOURCE([[ +#include +int APIENTRY WinMain(HINSTANCE curr, HINSTANCE prev, LPSTR argv, int mode) +{ (void)($1($2)); return 0; } + ]])],dnl + [AC_MSG_RESULT([yes])$3], + [AC_MSG_RESULT([no])$4 + ]) +]) + +# PTW32_AC_NEED_WINAPI_FUNC( FUNCNAME, ARGUMENTS ) +# ------------------------------------------------ +# Check if WinAPI function FUNCNAME is available on the host; add a +# NEED_FUNCNAME annotation in config.h, if it is not. +# +AC_DEFUN([PTW32_AC_NEED_WINAPI_FUNC], +[PTW32_AC_CHECK_WINAPI_FUNC([$1],[$2],,dnl + [AC_DEFINE(AS_TR_CPP([NEED_$1]),[1],[Define if $1 is unsupported])dnl + ]) +]) + +# PTW32_AC_CHECK_CPU_AFFINITY +# --------------------------- +# Check if the host supports the GetProcessAffinityMask() WinAPI +# function; (all Windows versions since Win95 should, but WinCE may +# not). Add the HAVE_CPU_AFFINITY annotation in config.h, for hosts +# which do have this support. +# +AC_DEFUN([PTW32_AC_CHECK_CPU_AFFINITY], +[PTW32_AC_CHECK_WINAPI_FUNC([GetProcessAffinityMask],[NULL,NULL,NULL],dnl + [AC_DEFINE([HAVE_CPU_AFFINITY],[1],[Define if CPU_AFFINITY is supported])dnl + ]) +]) diff --git a/appveyor.yml b/appveyor.yml index 5672147d..841d4cb5 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,18 +1,109 @@ +version: 3.0.1.{build} + +shallow_clone: true +clone_depth: 1 + +branches: + only: + - cmake + +configuration: +- MinSizeRel +- Release +- Debug environment: - matrix: - - PLATFORM: x64 - PTHREAD: x64 - - PLATFORM: Win32 - PTHREAD: x86 + DIST_DIR: '%APPVEYOR_BUILD_FOLDER%\dist' + CMAKE_DIST_DIR: C:/projects/pthreads4w/dist + + matrix: + + - APPVEYOR_BUILD_WORKER_IMAGE: 'Visual Studio 2015' + VCVARSALL: '%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC\vcvarsall.bat' + ARCHITECTURE: amd64_x86 + ARCHIVE: VS2015_%CONFIGURATION%_x86_%APPVEYOR_BUILD_NUMBER% + GENERATOR: 'NMake Makefiles' + TESTING: OFF + + - APPVEYOR_BUILD_WORKER_IMAGE: 'Visual Studio 2015' + VCVARSALL: '%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC\vcvarsall.bat' + ARCHITECTURE: amd64 + ARCHIVE: VS2015_%CONFIGURATION%_x64_%APPVEYOR_BUILD_NUMBER% + GENERATOR: 'NMake Makefiles' + TESTING: OFF + + - APPVEYOR_BUILD_WORKER_IMAGE: 'Visual Studio 2015' + VCVARSALL: '%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC\vcvarsall.bat' + ARCHITECTURE: amd64_arm + ARCHIVE: VS2015_%CONFIGURATION%_ARM_%APPVEYOR_BUILD_NUMBER% + GENERATOR: 'NMake Makefiles' + TESTING: OFF + + + - APPVEYOR_BUILD_WORKER_IMAGE: 'Visual Studio 2017' + VCVARSALL: '%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsamd64_arm.bat' + ARCHIVE: VS2017_%CONFIGURATION%_ARM_%APPVEYOR_BUILD_NUMBER% + GENERATOR: 'NMake Makefiles' + TESTING: OFF -os: Visual Studio 2015 + - APPVEYOR_BUILD_WORKER_IMAGE: 'Visual Studio 2017' + VCVARSALL: '%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsamd64_arm64.bat' + ARCHIVE: VS2017_%CONFIGURATION%_ARM64_%APPVEYOR_BUILD_NUMBER% + GENERATOR: 'NMake Makefiles' + TESTING: OFF + + - APPVEYOR_BUILD_WORKER_IMAGE: 'Visual Studio 2017' + VCVARSALL: '%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars32.bat' + ARCHIVE: VS2017_%CONFIGURATION%_x86_%APPVEYOR_BUILD_NUMBER% + GENERATOR: 'NMake Makefiles' + TESTING: ON + + - APPVEYOR_BUILD_WORKER_IMAGE: 'Visual Studio 2017' + VCVARSALL: '%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat' + ARCHIVE: VS2017_%CONFIGURATION%_x64_%APPVEYOR_BUILD_NUMBER% + GENERATOR: 'NMake Makefiles' + TESTING: ON + +init: + - echo BUILD_NUMBER=%APPVEYOR_BUILD_NUMBER% + +install: + + # CMake + - cmake --version + +build: + parallel: true build_script: - - sed -i 's/4820;4668;4255;/4820;4668;4255;4711;4100;4312;/' pthread_lib.2015.vcxproj - - msbuild pthread.2015.sln /nologo /p:Configuration=Release /p:Platform=%PLATFORM% /t:pthread_lib + - if exist "%VCVARSALL%" ( call "%VCVARSALL%" %ARCHITECTURE% ) + + - cd %APPVEYOR_BUILD_FOLDER% + - mkdir build + - cd build + - cmake -G"%GENERATOR%" + -DCMAKE_BUILD_TYPE=%CONFIGURATION% + -DBUILD_NUMBER=%APPVEYOR_BUILD_NUMBER% + -DDIST_ROOT="%CMAKE_DIST_DIR%/%APPVEYOR_BUILD_WORKER_IMAGE%" + -DENABLE_TESTS=%TESTING% + .. + + cmake --build . --config %CONFIGURATION% --target install + +after_build: + - cd %DIST_DIR% + - 7z a -tzip %ARCHIVE%.zip "%APPVEYOR_BUILD_WORKER_IMAGE%" + - certutil -hashfile %ARCHIVE%.zip MD5 > %ARCHIVE%.md5 -notifications: +artifacts: + - path: dist\$(ARCHIVE).zip + - path: dist\$(ARCHIVE).md5 - - provider: Email - on_build_status_changed: false +test: +before_test: + - set PATH=%APPVEYOR_BUILD_FOLDER%\build;%PATH% +test_script: + - if exist %APPVEYOR_BUILD_FOLDER%\build\tests\ cd %APPVEYOR_BUILD_FOLDER%\build\tests + - if exist %APPVEYOR_BUILD_FOLDER%\build\tests\ ctest -C %CONFIGURATION% -V +after_test: + # TODO process CTest output \ No newline at end of file diff --git a/cmake/get_version.cmake b/cmake/get_version.cmake new file mode 100644 index 00000000..5afaebc1 --- /dev/null +++ b/cmake/get_version.cmake @@ -0,0 +1,21 @@ + +file(READ ${CMAKE_SOURCE_DIR}/_ptw32.h _PTW32_H_CONTENTS) + +string(REGEX MATCH "#define PTW32_VERSION_MAJOR ([a-zA-Z0-9_]+)" PTW32_VERSION_MAJOR "${_PTW32_H_CONTENTS}") +string(REPLACE "#define PTW32_VERSION_MAJOR " "" PTW32_VERSION_MAJOR "${PTW32_VERSION_MAJOR}") + +string(REGEX MATCH "#define PTW32_VERSION_MINOR ([a-zA-Z0-9_]+)" PTW32_VERSION_MINOR "${_PTW32_H_CONTENTS}") +string(REPLACE "#define PTW32_VERSION_MINOR " "" PTW32_VERSION_MINOR "${PTW32_VERSION_MINOR}") + +string(REGEX MATCH "#define PTW32_VERSION_MICRO ([a-zA-Z0-9_]+)" PTW32_VERSION_MICRO "${_PTW32_H_CONTENTS}") +string(REPLACE "#define PTW32_VERSION_MICRO " "" PTW32_VERSION_MICRO "${PTW32_VERSION_MICRO}") + +string(REGEX MATCH "#define PTW32_VERION_BUILD ([a-zA-Z0-9_]+)" PTW32_VERSION_BUILD "${_PTW32_H_CONTENTS}") +string(REPLACE "#define PTW32_VERION_BUILD " "" PTW32_VERSION_BUILD "${PTW32_VERSION_BUILD}") + +if(BUILD_NUMBER) + set(PTW32_VERSION_BUILD ${BUILD_NUMBER}) +endif() + +set(PTHREADS4W_VERSION ${PTW32_VERSION_MAJOR}.${PTW32_VERSION_MINOR}.${PTW32_VERSION_MICRO}.${PTW32_VERSION_BUILD}) + diff --git a/cmake/target_arch.cmake b/cmake/target_arch.cmake new file mode 100644 index 00000000..05450445 --- /dev/null +++ b/cmake/target_arch.cmake @@ -0,0 +1,36 @@ + +set(TARGET_ARCH_DETECT_CODE " + + #if defined(_M_ARM) + #error cmake_arch ARM + #elif defined(_M_ARM64) + #error cmake_arch ARM64 + #elif defined(_M_AMD64) + #error cmake_arch x86_64 + #elif defined(_M_X64) + #error cmake_arch x64 + #elif defined(_M_IX86) + #error cmake_arch x86 + #else + #error cmake_arch unknown + #endif +") + +function(get_target_arch out) + + file(WRITE + "${CMAKE_BINARY_DIR}/target_arch_detect.c" + "${TARGET_ARCH_DETECT_CODE}") + + try_run( + run_result_unused compile_result_unused + "${CMAKE_BINARY_DIR}" "${CMAKE_BINARY_DIR}/target_arch_detect.c" + COMPILE_OUTPUT_VARIABLE TARGET_ARCH) + + # parse compiler output + string(REGEX MATCH "cmake_arch ([a-zA-Z0-9_]+)" TARGET_ARCH "${TARGET_ARCH}") + string(REPLACE "cmake_arch " "" TARGET_ARCH "${TARGET_ARCH}") + + set(${out} "${TARGET_ARCH}" PARENT_SCOPE) + +endfunction() diff --git a/cmake/version.rc.in b/cmake/version.rc.in new file mode 100644 index 00000000..f348125e --- /dev/null +++ b/cmake/version.rc.in @@ -0,0 +1,434 @@ +/* This is an implementation of the threads API of POSIX 1003.1-2001. + * + * -------------------------------------------------------------------------- + * + * pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999-2021 pthreads-win32 / pthreads4w contributors + * + * Homepage1: http://sourceware.org/pthreads-win32/ + * Homepage2: http://sourceforge.net/projects/pthreads4w/ + * + * The current list of contributors is contained + * in the file CONTRIBUTORS included with the source + * code distribution. The list can also be seen at the + * following World Wide Web location: + * http://sources.redhat.com/pthreads-win32/contributors.html + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library in the file COPYING.LIB; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * -------------------------------------------------------------------------- + */ + +#include +#include "pthread.h" + +/* + * Note: the correct PTW32_CLEANUP_* macro must be defined corresponding to + * the definition used for the object file builds. This is done in the + * relevent makefiles for the command line builds, but users should ensure + * that their resource compiler knows what it is too. + * If using the default (no PTW32_CLEANUP_* defined), pthread.h will define it + * as PTW32_CLEANUP_C. + */ + +#if defined (PTW32_RC_MSC) +# if defined (PTW32_ARCHx64) || defined (PTW32_ARCHX64) || defined (PTW32_ARCHAMD64) +# if defined(PTW32_CLEANUP_C) +# define PTW32_VERSIONINFO_NAME "pthreadVC@PTW32_VER@.DLL\0" +# define PTW32_VERSIONINFO_DESCRIPTION "MS C x64\0" +# elif defined(PTW32_CLEANUP_CXX) +# define PTW32_VERSIONINFO_NAME "pthreadVCE@PTW32_VER@.DLL\0" +# define PTW32_VERSIONINFO_DESCRIPTION "MS C++ x64\0" +# elif defined(PTW32_CLEANUP_SEH) +# define PTW32_VERSIONINFO_NAME "pthreadVSE@PTW32_VER@.DLL\0" +# define PTW32_VERSIONINFO_DESCRIPTION "MS C SEH x64\0" +# endif +# elif defined (PTW32_ARCHx86) || defined (PTW32_ARCHX86) +# if defined(PTW32_CLEANUP_C) +# define PTW32_VERSIONINFO_NAME "pthreadVC@PTW32_VER@.DLL\0" +# define PTW32_VERSIONINFO_DESCRIPTION "MS C x86\0" +# elif defined(PTW32_CLEANUP_CXX) +# define PTW32_VERSIONINFO_NAME "pthreadVCE@PTW32_VER@.DLL\0" +# define PTW32_VERSIONINFO_DESCRIPTION "MS C++ x86\0" +# elif defined(PTW32_CLEANUP_SEH) +# define PTW32_VERSIONINFO_NAME "pthreadVSE@PTW32_VER@.DLL\0" +# define PTW32_VERSIONINFO_DESCRIPTION "MS C SEH x86\0" +# endif +# elif defined (PTW32_ARCHARM) || defined (PTW32_ARCHARM) +# if defined(PTW32_CLEANUP_C) +# define PTW32_VERSIONINFO_NAME "pthreadVC@PTW32_VER@.DLL\0" +# define PTW32_VERSIONINFO_DESCRIPTION "MS C ARM\0" +# elif defined(PTW32_CLEANUP_CXX) +# define PTW32_VERSIONINFO_NAME "pthreadVCE@PTW32_VER@.DLL\0" +# define PTW32_VERSIONINFO_DESCRIPTION "MS C++ ARM\0" +# elif defined(PTW32_CLEANUP_SEH) +# define PTW32_VERSIONINFO_NAME "pthreadVSE@PTW32_VER@.DLL\0" +# define PTW32_VERSIONINFO_DESCRIPTION "MS C SEH ARM\0" +# endif +# elif defined (PTW32_ARCHARM64) || defined (PTW32_ARCHARM64) +# if defined(PTW32_CLEANUP_C) +# define PTW32_VERSIONINFO_NAME "pthreadVC@PTW32_VER@.DLL\0" +# define PTW32_VERSIONINFO_DESCRIPTION "MS C ARM64\0" +# elif defined(PTW32_CLEANUP_CXX) +# define PTW32_VERSIONINFO_NAME "pthreadVCE@PTW32_VER@.DLL\0" +# define PTW32_VERSIONINFO_DESCRIPTION "MS C++ ARM64\0" +# elif defined(PTW32_CLEANUP_SEH) +# define PTW32_VERSIONINFO_NAME "pthreadVSE@PTW32_VER@.DLL\0" +# define PTW32_VERSIONINFO_DESCRIPTION "MS C SEH ARM64\0" +# endif +# endif +#elif defined(__GNUC__) +# if defined(_M_X64) +# define PTW32_ARCH "x64 (mingw64)" +# else +# define PTW32_ARCH "x86 (mingw32)" +# endif +# if defined(PTW32_CLEANUP_C) +# define PTW32_VERSIONINFO_NAME "pthreadGC@PTW32_VER@.DLL\0" +# define PTW32_VERSIONINFO_DESCRIPTION "GNU C " PTW32_ARCH "\0" +# elif defined(PTW32_CLEANUP_CXX) +# define PTW32_VERSIONINFO_NAME "pthreadGCE@PTW32_VER@.DLL\0" +# define PTW32_VERSIONINFO_DESCRIPTION "GNU C++ " PTW32_ARCH "\0" +# else +# error Resource compiler doesn't know which cleanup style you're using - see version.rc +# endif +#elif defined(__BORLANDC__) +# if defined(_M_X64) +# define PTW32_ARCH "x64 (Borland)" +# else +# define PTW32_ARCH "x86 (Borland)" +# endif +# if defined(PTW32_CLEANUP_C) +# define PTW32_VERSIONINFO_NAME "pthreadBC@PTW32_VER@.DLL\0" +# define PTW32_VERSIONINFO_DESCRIPTION "BORLAND C " PTW32_ARCH "\0" +# elif defined(PTW32_CLEANUP_CXX) +# define PTW32_VERSIONINFO_NAME "pthreadBCE@PTW32_VER@.DLL\0" +# define PTW32_VERSIONINFO_DESCRIPTION "BORLAND C++ " PTW32_ARCH "\0" +# else +# error Resource compiler doesn't know which cleanup style you're using - see version.rc +# endif +#elif defined(__WATCOMC__) +# if defined(_M_X64) +# define PTW32_ARCH "x64 (Watcom)" +# else +# define PTW32_ARCH "x86 (Watcom)" +# endif +# if defined(PTW32_CLEANUP_C) +# define PTW32_VERSIONINFO_NAME "pthreadWC@PTW32_VER@.DLL\0" +# define PTW32_VERSIONINFO_DESCRIPTION "WATCOM C " PTW32_ARCH "\0" +# elif defined(PTW32_CLEANUP_CXX) +# define PTW32_VERSIONINFO_NAME "pthreadWCE@PTW32_VER@.DLL\0" +# define PTW32_VERSIONINFO_DESCRIPTION "WATCOM C++ " PTW32_ARCH "\0" +# else +# error Resource compiler doesn't know which cleanup style you're using - see version.rc +# endif +#else +# error Resource compiler doesn't know which compiler you're using - see version.rc +#endif + + +VS_VERSION_INFO VERSIONINFO + FILEVERSION PTW32_VERSION + PRODUCTVERSION PTW32_VERSION + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK + FILEFLAGS 0 + FILEOS VOS__WINDOWS32 + FILETYPE VFT_DLL +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "ProductName", "POSIX Threads for Windows\0" + VALUE "ProductVersion", PTW32_VERSION_STRING + VALUE "FileVersion", PTW32_VERSION_STRING + VALUE "FileDescription", PTW32_VERSIONINFO_DESCRIPTION + VALUE "InternalName", PTW32_VERSIONINFO_NAME + VALUE "OriginalFilename", PTW32_VERSIONINFO_NAME + VALUE "CompanyName", "Open Source Software community\0" + VALUE "LegalCopyright(C) 1999-2021 pthreads-win32 / pthreads4w contributors 1999-2018\0" + VALUE "Comments", "https://sourceforge.net/p/pthreads4w/wiki/Contributors/\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END + +/* +VERSIONINFO Resource + +The VERSIONINFO resource-definition statement creates a version-information +resource. The resource contains such information about the file as its +version number, its intended operating system, and its original filename. +The resource is intended to be used with the Version Information functions. + +versionID VERSIONINFO fixed-info { block-statement...} + +versionID + Version-information resource identifier. This value must be 1. + +fixed-info + Version information, such as the file version and the intended operating + system. This parameter consists of the following statements. + + + Statement Description + -------------------------------------------------------------------------- + FILEVERSION + version Binary version number for the file. The version + consists of two 32-bit integers, defined by four + 16-bit integers. For example, "FILEVERSION 3,10,0,61" + is translated into two doublewords: 0x0003000a and + 0x0000003d, in that order. Therefore, if version is + defined by the DWORD values dw1 and dw2, they need + to appear in the FILEVERSION statement as follows: + HIWORD(dw1), LOWORD(dw1), HIWORD(dw2), LOWORD(dw2). + PRODUCTVERSION + version Binary version number for the product with which the + file is distributed. The version parameter is two + 32-bit integers, defined by four 16-bit integers. + For more information about version, see the + FILEVERSION description. + FILEFLAGSMASK + fileflagsmask Bits in the FILEFLAGS statement are valid. If a bit + is set, the corresponding bit in FILEFLAGS is valid. + FILEFLAGSfileflags Attributes of the file. The fileflags parameter must + be the combination of all the file flags that are + valid at compile time. For 16-bit Windows, this + value is 0x3f. + FILEOSfileos Operating system for which this file was designed. + The fileos parameter can be one of the operating + system values given in the Remarks section. + FILETYPEfiletype General type of file. The filetype parameter can be + one of the file type values listed in the Remarks + section. + FILESUBTYPE + subtype Function of the file. The subtype parameter is zero + unless the type parameter in the FILETYPE statement + is VFT_DRV, VFT_FONT, or VFT_VXD. For a list of file + subtype values, see the Remarks section. + +block-statement + Specifies one or more version-information blocks. A block can contain + string information or variable information. For more information, see + StringFileInfo Block or VarFileInfo Block. + +Remarks + +To use the constants specified with the VERSIONINFO statement, you must +include the Winver.h or Windows.h header file in the resource-definition file. + +The following list describes the parameters used in the VERSIONINFO statement: + +fileflags + A combination of the following values. + + Value Description + + VS_FF_DEBUG File contains debugging information or is compiled + with debugging features enabled. + VS_FF_PATCHED File has been modified and is not identical to the + original shipping file of the same version number. + VS_FF_PRERELEASE File is a development version, not a commercially + released product. + VS_FF_PRIVATEBUILD File was not built using standard release procedures. + If this value is given, the StringFileInfo block must + contain a PrivateBuild string. + VS_FF_SPECIALBUILD File was built by the original company using standard + release procedures but is a variation of the standard + file of the same version number. If this value is + given, the StringFileInfo block must contain a + SpecialBuild string. + +fileos + One of the following values. + + Value Description + + VOS_UNKNOWN The operating system for which the file was designed + is unknown. + VOS_DOS File was designed for MS-DOS. + VOS_NT File was designed for Windows Server 2003 family, + Windows XP, Windows 2000, or Windows NT. + VOS__WINDOWS16 File was designed for 16-bit Windows. + VOS__WINDOWS32 File was designed for 32-bit Windows. + VOS_DOS_WINDOWS16 File was designed for 16-bit Windows running with + MS-DOS. + VOS_DOS_WINDOWS32 File was designed for 32-bit Windows running with + MS-DOS. + VOS_NT_WINDOWS32 File was designed for Windows Server 2003 family, + Windows XP, Windows 2000, or Windows NT. + + The values 0x00002L, 0x00003L, 0x20000L and 0x30000L are reserved. + +filetype + One of the following values. + + Value Description + + VFT_UNKNOWN File type is unknown. + VFT_APP File contains an application. + VFT_DLL File contains a dynamic-link library (DLL). + VFT_DRV File contains a device driver. If filetype is + VFT_DRV, subtype contains a more specific + description of the driver. + VFT_FONT File contains a font. If filetype is VFT_FONT, + subtype contains a more specific description of the + font. + VFT_VXD File contains a virtual device. + VFT_STATIC_LIB File contains a static-link library. + + All other values are reserved for use by Microsoft. + +subtype + Additional information about the file type. + + If filetype specifies VFT_DRV, this parameter can be one of the + following values. + + Value Description + + VFT2_UNKNOWN Driver type is unknown. + VFT2_DRV_COMM File contains a communications driver. + VFT2_DRV_PRINTER File contains a printer driver. + VFT2_DRV_KEYBOARD File contains a keyboard driver. + VFT2_DRV_LANGUAGE File contains a language driver. + VFT2_DRV_DISPLAY File contains a display driver. + VFT2_DRV_MOUSE File contains a mouse driver. + VFT2_DRV_NETWORK File contains a network driver. + VFT2_DRV_SYSTEM File contains a system driver. + VFT2_DRV_INSTALLABLE File contains an installable driver. + VFT2_DRV_SOUND File contains a sound driver. + VFT2_DRV_VERSIONED_PRINTER File contains a versioned printer driver. + + If filetype specifies VFT_FONT, this parameter can be one of the + following values. + + Value Description + + VFT2_UNKNOWN Font type is unknown. + VFT2_FONT_RASTER File contains a raster font. + VFT2_FONT_VECTOR File contains a vector font. + VFT2_FONT_TRUETYPE File contains a TrueType font. + + If filetype specifies VFT_VXD, this parameter must be the virtual-device + identifier included in the virtual-device control block. + + All subtype values not listed here are reserved for use by Microsoft. + +langID + One of the following language codes. + + Code Language Code Language + + 0x0401 Arabic 0x0415 Polish + 0x0402 Bulgarian 0x0416 Portuguese (Brazil) + 0x0403 Catalan 0x0417 Rhaeto-Romanic + 0x0404 Traditional Chinese 0x0418 Romanian + 0x0405 Czech 0x0419 Russian + 0x0406 Danish 0x041A Croato-Serbian (Latin) + 0x0407 German 0x041B Slovak + 0x0408 Greek 0x041C Albanian + 0x0409 U.S. English 0x041D Swedish + 0x040A Castilian Spanish 0x041E Thai + 0x040B Finnish 0x041F Turkish + 0x040C French 0x0420 Urdu + 0x040D Hebrew 0x0421 Bahasa + 0x040E Hungarian 0x0804 Simplified Chinese + 0x040F Icelandic 0x0807 Swiss German + 0x0410 Italian 0x0809 U.K. English + 0x0411 Japanese 0x080A Mexican Spanish + 0x0412 Korean 0x080C Belgian French + 0x0413 Dutch 0x0C0C Canadian French + 0x0414 Norwegian – Bokmal 0x100C Swiss French + 0x0810 Swiss Italian 0x0816 Portuguese (Portugal) + 0x0813 Belgian Dutch 0x081A Serbo-Croatian (Cyrillic) + 0x0814 Norwegian – Nynorsk + +charsetID + One of the following character-set identifiers. + + Identifier Character Set + + 0 7-bit ASCII + 932 Japan (Shift %G–%@ JIS X-0208) + 949 Korea (Shift %G–%@ KSC 5601) + 950 Taiwan (Big5) + 1200 Unicode + 1250 Latin-2 (Eastern European) + 1251 Cyrillic + 1252 Multilingual + 1253 Greek + 1254 Turkish + 1255 Hebrew + 1256 Arabic + +string-name + One of the following predefined names. + + Name Description + + Comments Additional information that should be displayed for + diagnostic purposes. + CompanyName Company that produced the file%G—%@for example, + "Microsoft Corporation" or "Standard Microsystems + Corporation, Inc." This string is required. + FileDescription File description to be presented to users. This + string may be displayed in a list box when the user + is choosing files to install%G—%@for example, + "Keyboard Driver for AT-Style Keyboards". This + string is required. + FileVersion Version number of the file%G—%@for example, + "3.10" or "5.00.RC2". This string is required. + InternalName Internal name of the file, if one exists — for + example, a module name if the file is a dynamic-link + library. If the file has no internal name, this + string should be the original filename, without + extension. This string is required. + LegalCopyright Copyright notices that apply to the file. This + should include the full text of all notices, legal + symbols, copyright dates, and so on — for example, + "Copyright (C) Microsoft Corporation 1990–1999". + This string is optional. + LegalTrademarks Trademarks and registered trademarks that apply to + the file. This should include the full text of all + notices, legal symbols, trademark numbers, and so on. + This string is optional. + OriginalFilename Original name of the file, not including a path. + This information enables an application to determine + whether a file has been renamed by a user. The + format of the name depends on the file system for + which the file was created. This string is required. + PrivateBuild Information about a private version of the file — for + example, "Built by TESTER1 on \TESTBED". This string + should be present only if VS_FF_PRIVATEBUILD is + specified in the fileflags parameter of the root + block. + ProductName Name of the product with which the file is + distributed. This string is required. + ProductVersion Version of the product with which the file is + distributed — for example, "3.10" or "5.00.RC2". + This string is required. + SpecialBuild Text that indicates how this version of the file + differs from the standard version — for example, + "Private build for TESTER1 solving mouse problems + on M250 and M250E computers". This string should be + present only if VS_FF_SPECIALBUILD is specified in + the fileflags parameter of the root block. + */ diff --git a/common.mk b/common.mk index c8752939..92a8e0df 100755 --- a/common.mk +++ b/common.mk @@ -7,8 +7,11 @@ RESOURCE_OBJS = \ DLL_OBJS = \ pthread.$(OBJEXT) -# Separate modules for minimising the size of statically linked images STATIC_OBJS = \ + pthread.$(OEXT) + +# Separate modules for minimising the size of statically linked images +STATIC_OBJS_SMALL = \ cleanup.$(OBJEXT) \ create.$(OBJEXT) \ dll.$(OBJEXT) \ @@ -153,7 +156,6 @@ STATIC_OBJS = \ sem_trywait.$(OBJEXT) \ sem_unlink.$(OBJEXT) \ sem_wait.$(OBJEXT) \ - signal.$(OBJEXT) \ w32_CancelableWait.$(OBJEXT) PTHREAD_SRCS = \ diff --git a/config.h b/config.h index 5e69ed57..379371d5 100644 --- a/config.h +++ b/config.h @@ -1,14 +1,14 @@ /* config.h */ -#ifndef PTW32_CONFIG_H -#define PTW32_CONFIG_H +#ifndef PTW32_CONFIG_H +#define PTW32_CONFIG_H /********************************************************************* * Defaults: see target specific redefinitions below. *********************************************************************/ /* We're building the pthreads-win32 library */ -#define PTW32_BUILD +#define PTW32_BUILD /* CPU affinity */ #define HAVE_CPU_AFFINITY @@ -34,9 +34,6 @@ /* Define if you don't have Win32 calloc. (eg. WinCE) */ #undef NEED_CALLOC -/* Define if you don't have Win32 ftime. (eg. WinCE) */ -#undef NEED_FTIME - /* Define if you don't have Win32 semaphores. (eg. WinCE 2.1 or earlier) */ #undef NEED_SEM @@ -80,7 +77,7 @@ # applications that make assumptions that POSIX does not guarantee are # not strictly compliant and may fail or misbehave with some settings. # -# PTW32_THREAD_ID_REUSE_INCREMENT +# PTW32_THREAD_ID_REUSE_INCREMENT # Purpose: # POSIX says that applications should assume that thread IDs can be # recycled. However, Solaris (and some other systems) use a [very large] @@ -98,11 +95,11 @@ # (i.e. will wrap sooner). This might be useful to emulate some embedded # systems. # -# define PTW32_THREAD_ID_REUSE_INCREMENT 0 +# define PTW32_THREAD_ID_REUSE_INCREMENT 0 # # ---------------------------------------------------------------------- */ -#undef PTW32_THREAD_ID_REUSE_INCREMENT +#undef PTW32_THREAD_ID_REUSE_INCREMENT /********************************************************************* @@ -112,34 +109,27 @@ * to the pthreads-win32 maintainer. Thanks. *********************************************************************/ #if defined(WINCE) -#undef HAVE_CPU_AFFINITY -#define NEED_DUPLICATEHANDLE -#define NEED_CREATETHREAD -#define NEED_ERRNO -#define NEED_CALLOC -#define NEED_FTIME -/* #define NEED_SEM */ -#define NEED_UNICODE_CONSTS -#define NEED_PROCESS_AFFINITY_MASK +# undef HAVE_CPU_AFFINITY +# define NEED_DUPLICATEHANDLE +# define NEED_CREATETHREAD +# define NEED_ERRNO +# define NEED_CALLOC +# define NEED_FTIME +/* # define NEED_SEM */ +# define NEED_UNICODE_CONSTS +# define NEED_PROCESS_AFFINITY_MASK /* This may not be needed */ -#define RETAIN_WSALASTERROR +# define RETAIN_WSALASTERROR #endif #if defined(_UWIN) -#define HAVE_MODE_T -#define HAVE_STRUCT_TIMESPEC -#define HAVE_SIGNAL_H +# define HAVE_MODE_T +# define HAVE_STRUCT_TIMESPEC +# define HAVE_SIGNAL_H #endif #if defined(__GNUC__) -#define HAVE_C_INLINE -#endif - -#if defined(__MINGW64__) -#define HAVE_MODE_T -#define HAVE_STRUCT_TIMESPEC -#elif defined(__MINGW32__) -#define HAVE_MODE_T +# define HAVE_C_INLINE #endif #if defined(__BORLANDC__) @@ -157,4 +147,4 @@ #define HAVE_STRUCT_TIMESPEC #endif -#endif /* PTW32_CONFIG_H */ +#endif /* PTW32_CONFIG_H */ diff --git a/configure.ac b/configure.ac new file mode 100644 index 00000000..d63207b2 --- /dev/null +++ b/configure.ac @@ -0,0 +1,88 @@ +# configure.ac +# -------------------------------------------------------------------------- +# +# pthreads-win32 / pthreads4w - POSIX Threads for Windows +# Copyright 1998 John E. Bossom +# Copyright(C) 1999-2021 pthreads-win32 / pthreads4w contributors +# +# Homepage: http://sources.redhat.com/pthreads-win32 +# +# The current list of contributors is contained +# in the file CONTRIBUTORS included with the source +# code distribution. The list can also be seen at the +# following World Wide Web location: +# +# https://sourceforge.net/p/pthreads4w/wiki/Contributors/ +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library in the file COPYING.LIB; +# if not, write to the Free Software Foundation, Inc., +# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA +# +AC_INIT([pthreads4w],[git]) +AC_CONFIG_HEADERS([config.h]) + +# Checks for build tools. +# +AC_PROG_CC +AC_PROG_CXX +AC_CHECK_TOOLS([AR],[ar],[ar]) +AC_CHECK_TOOLS([DLLTOOL],[dlltool],[dlltool]) +AC_CHECK_TOOLS([OBJDUMP],[objdump],[objdump]) +AC_CHECK_TOOLS([RC],[windres],[windres]) +AC_PROG_RANLIB + +# Autoconf doesn't normally guard config.h, but we prefer it so; +# this is also a convenient place to force HAVE_C_INLINE, because +# AC_C_INLINE makes it available, even if the build compiler does +# not normally support it. +# +AH_TOP(dnl +[#ifndef PTW32_CONFIG_H] +[#define PTW32_CONFIG_H]dnl +) +# FIXME: AC_C_INLINE defines 'inline' to work with any C compiler, +# whether or not it supports inline code expansion, but it does NOT +# define HAVE_C_INLINE; can we use this standard autoconf feature, +# without also needing to define HAVE_C_INLINE? +# +AC_C_INLINE +AH_BOTTOM([#define HAVE_C_INLINE]) +AH_BOTTOM([#endif]) + +# Checks for data types and structures. +# +PTW32_AC_CHECK_TYPEDEF([mode_t]) +PTW32_AC_CHECK_TYPEDEF([sigset_t],[signal.h]) +PTW32_AC_CHECK_TYPEDEF([struct timespec],[time.h]) + +# Checks for __cdecl functions. +# +PTW32_AC_NEED_ERRNO +PTW32_AC_NEED_FUNC([NEED_CALLOC],[calloc]) +PTW32_AC_NEED_FUNC([NEED_CREATETHREAD],[_beginthreadex]) +PTW32_AC_CHECK_CPU_AFFINITY + +# WinAPI functions need a full argument list for detection. +# +PTW32_AC_NEED_WINAPI_FUNC([DuplicateHandle],[NULL,NULL,NULL,NULL,0,0,0]) + +# Checks for installation tools. +# +AC_PROG_MKDIR_P +AC_PROG_INSTALL + +# Build system generation, as configured. +# +AC_CONFIG_FILES([GNUmakefile tests/GNUmakefile]) +AC_OUTPUT diff --git a/context.h b/context.h index d8efaf32..bf573170 100644 --- a/context.h +++ b/context.h @@ -37,40 +37,40 @@ * -------------------------------------------------------------------------- */ -#ifndef PTW32_CONTEXT_H -#define PTW32_CONTEXT_H +#ifndef PTW32_CONTEXT_H +#define PTW32_CONTEXT_H -#undef PTW32_PROGCTR +#undef PTW32_PROGCTR #if defined(_M_IX86) || (defined(_X86_) && !defined(__amd64__)) -#define PTW32_PROGCTR(Context) ((Context).Eip) +#define PTW32_PROGCTR(Context) ((Context).Eip) #endif #if defined (_M_IA64) || defined(_IA64) -#define PTW32_PROGCTR(Context) ((Context).StIIP) +#define PTW32_PROGCTR(Context) ((Context).StIIP) #endif #if defined(_MIPS_) || defined(MIPS) -#define PTW32_PROGCTR(Context) ((Context).Fir) +#define PTW32_PROGCTR(Context) ((Context).Fir) #endif #if defined(_ALPHA_) -#define PTW32_PROGCTR(Context) ((Context).Fir) +#define PTW32_PROGCTR(Context) ((Context).Fir) #endif #if defined(_PPC_) -#define PTW32_PROGCTR(Context) ((Context).Iar) +#define PTW32_PROGCTR(Context) ((Context).Iar) #endif #if defined(_AMD64_) || defined(__amd64__) -#define PTW32_PROGCTR(Context) ((Context).Rip) +#define PTW32_PROGCTR(Context) ((Context).Rip) #endif #if defined(_ARM_) || defined(ARM) || defined(_M_ARM) || defined(_M_ARM64) #define PTW32_PROGCTR(Context) ((Context).Pc) #endif -#if !defined(PTW32_PROGCTR) +#if !defined (PTW32_PROGCTR) #error Module contains CPU-specific code; modify and recompile. #endif diff --git a/create.c b/create.c index 562d3faf..6ffdb53f 100644 --- a/create.c +++ b/create.c @@ -19,17 +19,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., @@ -51,7 +51,7 @@ int pthread_create (pthread_t * tid, const pthread_attr_t * attr, - void *(PTW32_CDECL *start) (void *), void *arg) + void * (PTW32_CDECL *start) (void *), void *arg) /* * ------------------------------------------------------ * DOCPUBLIC @@ -226,7 +226,7 @@ pthread_create (pthread_t * tid, * finished with it here. */ -#if ! defined (PTW32_CONFIG_MINGW) || defined (__MSVCRT__) || defined (__DMC__) +#if ! defined (__MINGW32__) || defined (__MSVCRT__) || defined (__DMC__) tp->threadH = threadH = diff --git a/dll.c b/dll.c index d6ebd787..cdc7e090 100644 --- a/dll.c +++ b/dll.c @@ -19,17 +19,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., @@ -40,12 +40,6 @@ #ifdef HAVE_CONFIG_H # include "config.h" -#endif - -#if defined(PTW32_STATIC_LIB) && defined(_MSC_VER) && _MSC_VER >= 1400 && defined(_WINDLL) -# undef PTW32_STATIC_LIB -# define PTW32_STATIC_TLSLIB -#endif /* [i_a] sanity build checks */ #if defined(_MSC_VER) && (defined(_WIN32) || defined(_WIN64)) @@ -59,7 +53,7 @@ #include "pthread.h" #include "implement.h" -#if !defined(PTW32_STATIC_LIB) +#if !defined (PTW32_STATIC_LIB) #if defined(_MSC_VER) /* @@ -69,14 +63,9 @@ #pragma warning( disable : 4100 ) #endif -#if defined(__cplusplus) -/* - * Dear c++: Please don't mangle this name. -thanks - */ -extern "C" -#endif /* __cplusplus */ - BOOL WINAPI -DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved) +PTW32_BEGIN_C_DECLS + +BOOL WINAPI DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved) { BOOL result = PTW32_TRUE; @@ -110,42 +99,17 @@ DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved) return (result); } /* DllMain */ +PTW32_END_C_DECLS + #endif /* !PTW32_STATIC_LIB */ -#if ! defined(PTW32_BUILD_INLINED) +#if ! defined (PTW32_BUILD_INLINED) /* * Avoid "translation unit is empty" warnings */ typedef int foo; #endif -/* Visual Studio 8+ can leverage PIMAGE_TLS_CALLBACK CRT segments, which - * give a static lib its very own DllMain. - */ -#ifdef PTW32_STATIC_TLSLIB - -static void WINAPI -TlsMain(PVOID h, DWORD r, PVOID u) -{ - (void)DllMain((HINSTANCE)h, r, u); -} - -#ifdef _M_X64 -# pragma comment (linker, "/INCLUDE:_tls_used") -# pragma comment (linker, "/INCLUDE:_xl_b") -# pragma const_seg(".CRT$XLB") -EXTERN_C const PIMAGE_TLS_CALLBACK _xl_b = TlsMain; -# pragma const_seg() -#else -# pragma comment (linker, "/INCLUDE:__tls_used") -# pragma comment (linker, "/INCLUDE:__xl_b") -# pragma data_seg(".CRT$XLB") -EXTERN_C PIMAGE_TLS_CALLBACK _xl_b = TlsMain; -# pragma data_seg() -#endif /* _M_X64 */ - -#endif /* PTW32_STATIC_TLSLIB */ - #if defined(PTW32_STATIC_LIB) /* @@ -153,7 +117,7 @@ EXTERN_C PIMAGE_TLS_CALLBACK _xl_b = TlsMain; * on thread exit. Code here can only do process init and exit functions. */ -#if defined(PTW32_CONFIG_MINGW) || defined(_MSC_VER) +#if defined(__MINGW32__) || defined(_MSC_VER) /* For an explanation of this code (at least the MSVC parts), refer to * @@ -188,7 +152,7 @@ extern int ptw32_on_process_exit(void) return 0; } -#if defined(PTW32_CONFIG_MINGW) +#if defined(__GNUC__) __attribute__((section(".ctors"), used)) extern int (*gcc_ctor)(void) = ptw32_on_process_init; __attribute__((section(".dtors"), used)) extern int (*gcc_dtor)(void) = ptw32_on_process_exit; #elif defined(_MSC_VER) @@ -206,7 +170,9 @@ extern int (*msc_dtor)(void) = ptw32_on_process_exit; # endif #endif -#endif /* defined(PTW32_CONFIG_MINGW) || defined(_MSC_VER) */ +#endif /* defined(__MINGW32__) || defined(_MSC_VER) */ + +PTW32_BEGIN_C_DECLS /* This dummy function exists solely to be referenced by other modules * (specifically, in implement.h), so that the linker can't optimize away @@ -218,5 +184,7 @@ extern int (*msc_dtor)(void) = ptw32_on_process_exit; */ void ptw32_autostatic_anchor(void) { abort(); } -#endif /* PTW32_STATIC_LIB */ +PTW32_END_C_DECLS + +#endif /* PTW32_STATIC_LIB */ diff --git a/docs/ANNOUNCE.md b/docs/ANNOUNCE.md index 8bbe1f6d..85b531aa 100644 --- a/docs/ANNOUNCE.md +++ b/docs/ANNOUNCE.md @@ -1,30 +1,49 @@ -PTHREADS4W RELEASE 2.10.0 (2014-05-29) +PTHREADS4W RELEASE 3.0.0 (2017-01-01) -------------------------------------- -Web Site: http://sourceforge.net/projects/pthreads4w/ - http://sourceware.org/pthreads-win32/ -Repository: http://sourceforge.net/p/pthreads4w/code - https://sourceware.org/cgi-bin/cvsweb.cgi/pthreads/?cvsroot=pthreads-win32 -Releases: http://sourceforge.net/projects/pthreads4w/files - ftp://sourceware.org/pub/pthreads-win32 +Web Site: http://sources.redhat.com/pthreads-win32 +Repository: https://sourceforge.net/p/pthreads4w/code +Releases: http://sources.redhat.com/pthreads-win32files Maintainer: Ross Johnson -We are pleased to announce the availability of a new release of -pthreads4w (a.k.a. pthreads-win32), an Open Source Software implementation of the -Threads component of the SUSV3 Standard for Microsoft's -Windows (x86 and x64). Some relevant functions from other sections -of SUSV3 are also supported including semaphores and scheduling -functions. See the Conformance section below for details. +We are pleased to announce the availability of a new release of pthreads-win32 +(a.k.a. pthreads-win32), an Open Source Software implementation of +the Threads component of the SUSV3 Standard for Microsoft's Windows +(x86 and x64). Some relevant functions from other sections of SUSV3 are +also supported including semaphores and scheduling functions. See the +Conformance section below for details. Some common non-portable functions are also implemented for additional compatibility, as are a few functions specific to pthreads4w for easier integration with Windows applications. -pthreads4w is free software, distributed under the GNU Lesser -General Public License (LGPL). +pthreads-win32 is free software. With the exception of four files noted later, +Version 3.0.0 is distributed under the Apache License version 2.0 (APLv2). +The APLv2 is compatible with the GPLv3 and LGPLv3 licenses and therefore +this code may continue to be legally included within GPLv3 and LGPLv3 +projects. -For those who want to try the most recent changes, the SourceForge Git repository -is the one to use. The Sourceware CVS repository is synchronised less often. +All version 1 and 2 releases will remain LGPL but version 2.11 will be +released under v3 of that license so that any modifications to pthreads4w +version 3 code that we backport to v2 will not pollute that code. + +The four files that will remain LGPL but change to v3 are files used to +configure the GNU environment builds: + + aclocal.m4 + configure.ac + GNUmakefile.in + tests/GNUmakefile.in + +For those who want to try the most recent changes, the SourceForge Git +repository is the one to use. The Sourceware CVS repository is synchronised +much less often and may be abandoned altogether. + +Release 2.9.1 was probably the last to provide pre-built libraries. The +supported compilers are now all available free for personal use. The MSVS +version should build out of the box using nmake. The GCC versions now make +use of GNU autoconf to generate a configure script which in turn creates a +custom config.h for the environment you use: MinGW or MinGW64, etc. Acknowledgements @@ -60,7 +79,7 @@ were extracted from it. There is also a separate CONTRIBUTORS file. This file and others are on the web site: - http://sourceware.org/pthreads-win32 + https://sourceforge.net/p/pthreads4w/wiki/Contributors/ As much as possible, the ChangeLog file acknowledges contributions to the code base in more detail. @@ -297,13 +316,9 @@ The following functions are implemented: PTHREAD_MUTEX_TIMED_NP) pthread_num_processors_np pthread_win32_getabstime_np - (The following four routines may be required when linking statically. - The process_* routines should not be needed for MSVC or GCC.) + (The following four routines should no longer be required.) pthread_win32_process_attach_np pthread_win32_process_detach_np - (The following routines should only be needed to manage implicit - POSIX handles i.e. when Win native threads call POSIX thread routines - (other than pthread_create)) pthread_win32_thread_attach_np pthread_win32_thread_detach_np @@ -401,89 +416,10 @@ The following functions are not implemented: rand_r -Availability ------------- - -The prebuilt DLL, export libs (for both MSVC and Mingw32), and the header -files (pthread.h, semaphore.h, sched.h) are available along with the -complete source code. - -The source code can be found at: - - ftp://sources.redhat.com/pub/pthreads-win32 - -and as individual source code files at - - ftp://sources.redhat.com/pub/pthreads-win32/source - -The pre-built DLL, export libraries and include files can be found at: - - ftp://sources.redhat.com/pub/pthreads-win32/dll-latest - - - -Mailing List ------------- - -There is a mailing list for discussing pthreads on Win32. To join, -send email to: - - pthreads-win32-subscribe@sourceware.cygnus.com - - Application Development Environments ------------------------------------ See the README file for more information. - -MSVC: -MSVC using SEH works. Distribute pthreadVSE.dll with your application. -MSVC using C++ EH works. Distribute pthreadVCE.dll with your application. -MSVC using C setjmp/longjmp works. Distribute pthreadVC.dll with your application. - - -Mingw32: -See the FAQ, Questions 6 and 10. - -Mingw using C++ EH works. Distribute pthreadGCE.dll with your application. -Mingw using C setjmp/longjmp works. Distribute pthreadGC.dll with your application. - - -Cygwin: (http://sourceware.cygnus.com/cygwin/) -Developers using Cygwin do not need pthreads-win32 since it has POSIX threads -support. Refer to its documentation for details and extent. - - -UWIN: -UWIN is a complete Unix-like environment for Windows from AT&T. pthreads-win32 -doesn't currently support UWIN (and vice versa), but that may change in the -future. - -Generally: -For convenience, the following pre-built files are available on the FTP site -(see Availability above): - - pthread.h - for POSIX threads - semaphore.h - for POSIX semaphores - sched.h - for POSIX scheduling - pthreadVCE.dll - built with MSVC++ compiler using C++ EH - pthreadVCE.lib - pthreadVC.dll - built with MSVC compiler using C setjmp/longjmp - pthreadVC.lib - pthreadVSE.dll - built with MSVC compiler using SEH - pthreadVSE.lib - pthreadGCE.dll - built with Mingw32 G++ 2.95.2-1 - pthreadGC.dll - built with Mingw32 GCC 2.95.2-1 using setjmp/longjmp - libpthreadGCE.a - derived from pthreadGCE.dll - libpthreadGC.a - derived from pthreadGC.dll - gcc.dll - needed if distributing applications that use - pthreadGCE.dll (but see the FAQ Q 10 for the latest - related information) - -These are the only files you need in order to build POSIX threads -applications for Win32 using either MSVC or Mingw32. - -See the FAQ file in the source tree for additional information. Documentation @@ -505,15 +441,6 @@ available: By Bradford Nichols, Dick Buttlar & Jacqueline Proulx Farrell O'Reilly (pub) -On the web: see the links at the bottom of the pthreads-win32 site: - - http://sources.redhat.com/pthreads-win32/ - - Currently, there is no documentation included in the package apart - from the copious comments in the source code. - - - Enjoy! Ross Johnson diff --git a/docs/BUGS.md b/docs/BUGS.md index 285ba4eb..748e4442 100644 --- a/docs/BUGS.md +++ b/docs/BUGS.md @@ -119,23 +119,3 @@ Known bugs in applications relying on cancellation/cleanup AND using optimisations for creation of production code is highly unreliable for the current version of the pthreads library. - -3. The Borland Builder 5.5 version of the library produces memory read exceptions -in some tests. - -4. pthread_barrier_wait() can deadlock if the number of potential calling -threads for a particular barrier is greater than the barrier count parameter -given to pthread_barrier_init() for that barrier. - -This is due to the very lightweight implementation of pthread-win32 barriers. -To cope with more than "count" possible waiters, barriers must effectively -implement all the same safeguards as condition variables, making them much -"heavier" than at present. - -The workaround is to ensure that no more than "count" threads attempt to wait -at the barrier. - -5. Canceling a thread blocked on pthread_once appears not to work in the MSVC++ -version of the library "pthreadVCE.dll". The test case "once3.c" hangs. I have no -clues on this at present. All other versions pass this test ok - pthreadsVC.dll, -pthreadsVSE.dll, pthreadsGC.dll and pthreadsGCE.dll. diff --git a/docs/ChangeLog.md b/docs/ChangeLog.md index d61fb3e4..c7be476d 100644 --- a/docs/ChangeLog.md +++ b/docs/ChangeLog.md @@ -159,6 +159,22 @@ * (3573556) Removed line since see no need to enable switches * (eea3c89) Combined Readme and added changes to readme + + + + + + +2019-11-03 +---------- + +2019-11-03 Ross Johnson + + * NOTICE: Remove third party code acknowledgments because files have been + removed from distro. + + + @@ -222,6 +238,18 @@ * (1ed67a4) support uwp platform + + + + + +2018-08-19 +---------- + +2018-08-19 Ross Johnson + + * context.h (PTW32_PROCPTR): Added missing '__' prefix for v3. + @@ -231,6 +259,72 @@ * (85f21e7) pthread for windows updated + + + + + +2018-08-10 +---------- + +2018-08-10 Ross Johnson + + * Makefile (clean): remove *.idb files. + * dll.c: replace 'extern "C"' with macros PTW32_BEGIN_C_DECLS/PTW32_BEGIN_C_DECLS + for consistency tidy-up; add comment re ptw32_autostatic_anchor() function; + make our static constructor/destructors "extern" to avoid optimisers. + * implement.h (ptw32_autostatic_anchor): add PTW32_BEGIN_C_DECLS/PTW32_BEGIN_C_DECLS + envelope. + + + + + +2018-08-08 +---------- + +2018-08-08 Ross Johnson + + * Makefile: "nmake realclean VC VC-static" and similar wasn't remaking pthread.obj. + * common.mk: changes to accommodate the above. + * GNUmakefile: use changes in common.mk but still has problem with + "make realclean GC GC-static" and similar. + * configure.ac (AC_INIT): package name change. + +2018-08-08 Mark Pizzolato + + * config.h (NEED_FTIME): Removed + * _ptw32.h (NEED_FTIME): Removed. + * ptw32_timespec.c (NEED_FTIME): Removed conditional. + * ptw32_relmillisecs: Fix long-standing bug in NEED_FTIME code; remove NEED_FTIME + and all !NEED_FTIME code; compare nanoseconds and convert to milliseconds + at the end. + * implement.h (NEED_FTIME): remove conditionals. + * pthread.h: Remove Borland compiler time types no longer needed. + * configure.ac (NEED_FTIME): Removed check. + + + + + +2018-08-07 +---------- + +2018-08-07 Ross Johnson + + * GNUmakefile.in (DLL_VER): rename as PTW32_VER. + * Makefile (DLL_VER): Likewise. + * Bmakefile (DLL_VER): Likewise; does anyone use this anymore? + * pthread.h: Move internal library stuff from pthread.h to _pthw32.h + * _ptw32.h: As above. + * ANNOUNCE: Update. + * NEWS: Update. + * Makefile: Static libraries renamed to libpthreadV* + + + + + @@ -240,6 +334,36 @@ * (89d7bd5..8d58eb2) Added VS2015 project files. + + + + + +2018-07-22 +---------- + +2018-07-22 Mark Pizzolato + + * _ptw32.h: Restore support for compiling as static (with /MT or /MTd); + define int64_t and uint64_t as typedefs rather than #defines. + * dll.c: Likewise. + * implement.h: Likewise. + * need_errno.h: Likewise. + * pthread_detach.c: Likewise. + +2018-07-22 Carlo Bramini + + * context.h (ARM): Additional macros checked for ARM processors. + +2018-07-22 Ross Johnson + + * Makefile (all-tests-md): New; run the /MD build and tests from + all-tests-cflags. + * Makefile (all-tests-mt): New; run the /MT build and tests from + all-tests-cflags. + * Makefile (all-tests-cflags): retain; require all-tests-md and + all-tests-mt. + @@ -268,6 +392,204 @@ + + + +2016-12-25 +---------- + +2016-12-25 Ross Johnson + + * Change all license notices to the Apache License 2.0 + * LICENCE: New Apache License file + * NOTICE: New file. + * COPYING: Removed. + * COPYING.GPL: Removed. + + + + + + +2016-12-20 +---------- + +2016-12-20 Ross Johnson + + * implement.h (PThreadStateReuse): this thread state enum value + must be less than PThreadStateRunning to reflect an invalid thread + handle. + * pthread_kill.c: changed conditions for return of ESRCH. + * ptw32_destroy.c: copy HANDLEs rather than whole thread struct; + edit comment. + * pthread_self.c: set implicit thread handle state to PThreadStateRunning. + * pthread_create.c: set thread state to PThreadStateSuspended + regardless because it must have state >= PThreadStateRunning on return. + +2016-12-20 Ross Johnson + + * all (PTW32_*): rename to PTW32_*. + (ptw32_*): rename to ptw32_*. + (PtW32*): rename to __PtW32*. + * pthread.h (PTW32_VERSION_MAJOR): = 3 + (PTW32_VERSION_MINOR): = 0 + * GNUmakefile: removed; must now configure from GNUmakefile.in. + I.e. For either MinGW or MinGW-w64: + # autoheader + # autoconf + # ./configure + * pthread.h (PTHREAD_ONCE_INIT): for PTW32_VERSION_MAJOR > 2, + reverse element values to conform to new pthread_once_t. + + + + + + +2016-12-18 +---------- + +2016-12-18 Ross Johnson + + * implement.h (PTW32_TEST_SNEAK_PEEK): Defined in tests/test.h + to control what some tests see when sneaking a peek inside this + header. + * GNUMakefile.in: call tests "make realclean" + + + + + +2016-12-17 +---------- + +2016-12-17 Ross Johnson + + * _ptw32.h: MINGW(all) include stdint.h to define all specific + size integers (int64_t etc). + +2016-12-17 Kyle Schwarz + + * _ptw32.h: MINGW6464 define pid_t as __int64. + + + + + +2016-04-01 +---------- + +2016-04-01 Ross Johnson + + * _ptw32.h: Move more header stuff into here. + * pthread.h: Move stuff from here into _ptw32.h. + * implement.h: Likewise. + * sched.h (struct timespec): Wrap with extra condition check. + * pthread_win32_attach_detach.c: Source stdlib.h to define + _countof et. al. + + + + + +2016-03-31 +---------- + +2016-03-31 Keith Marshall + + * aclocal.m4: New from MinGW32 patches for autoconf. + * configure.ac: Likewise. + * GNUmakefile.in: Likewise. + * install-sh: Likewise. + * _ptw32.h: Likewise. + * implement.h: Patched. + * pthread.h: Patched. + * sched.h: Patched. + * sem_open.c: Patched. + * semaphore.h: Patched. + * pthread_self.c: Patched. + + + + + +2016-03-28 +---------- + +2016-03-28 Ross Johnson + + * ptw32_relmillisecs.c (pthread_win32_getabstime_np): New + platform-aware function to return the current time plus optional + offset. + * pthread.h (pthread_win32_getabstime_np): New exported function. + * ptw32_timespec.c: Conditionally compile only if NEED_FTIME config + flagged. + * sched.h: Update platform config flags for applications. + * semaphore.h: Likewise. + * pthread.h: Likewise. + + + + +2016-03-25 +---------- + + +2016-03-25 Bill Parker + + * pthread_mutex_init.c: Memory allocation of robust mutex element + was not being checked. + + + + +2016-02-29 +---------- + +2016-02-29 Ross Johnson + + * GNUmakefile (MINGW_HAVE_SECURE_API): Moved to config.h. Undefined + for __MINGW32__; remove (make optional) forcing a specific C std. + * implement.h (uint64_t): Define for Visual Studio. + +2016-02-29 Keith Marshall + + * ptw32_timespec.c: Fix C90 warnings from GCC; int64_t -> uint64_t + + + + +2016-02-18 +---------- + +2016-02-18 Carey Gister + + * dll.c (DllMain): Should not be defined for static library builds. + Doing so prevents static linking with a dll library. + + + + +2015-11-01 +---------- + +2015-11-01 Anurag Sharma + + * ptw32_MCS_lock.c: Fix a race condition causing crashes. + This race condition was also analysed and reported with a slightly + different fix independently by Jonathan Brown at VMware. + +2015-11-01 Mark Smith + + * ptw32_relmillisecs.c: Fix erroneous 0-time waits, symptomizing as + busy-spinning eating CPU. When the time to wait is specified to be less + than 1 millisecond were erroneously rounded down to 0; Modify WinCE + dependency. + * ptw32_timespec.c: Remove NEED_FTIME conditionality. + + + + 2015-10-20 ---------- @@ -1297,15 +1619,15 @@ * README.NONPORTABLE: It's "DllMain", not "dllMain". * common.mk: Start of an attempt to define dependencies for pthread.$(OBJEXT). - * implement.h: Generalized PTW32_BROKEN_ERRNO into + * implement.h: Generalized PTW32_BROKEN_ERRNO into PTW32_USES_SEPARATE_CRT; don't do the autostatic-anchoring thing if we're not building the library! - * pthread.h: Moved the PTW32_CDECL bit into sched.h. pthread.h + * pthread.h: Moved the PTW32_CDECL bit into sched.h. pthread.h already #includes sched.h, so the latter is a good place to put definitions that need to be shared in common; severely simplified the errno declaration for Open Watcom, made it applicable only to Open Watcom, and made the comment less ambiguous; updated the long - comment describing PTW32_BROK^WPTW32_USES_SEPARATE_CRT; added + comment describing PTW32_BROK^WPTW32_USES_SEPARATE_CRT; added (conditional) declaration of pthread_win32_set_terminate_np(), as well as ptw32_terminate_handler (so that eh.h doesn't have to get involved). @@ -1317,25 +1639,25 @@ * ptw32_threadStart.c: Big rewrite of ptw32_threadStart(). Everything passes with this, except for GCE (and I can't figure out why). - * sched.h: Moved the PTW32_CDECL section here (and made it + * sched.h: Moved the PTW32_CDECL section here (and made it idempotent); need to #include for size_t (one of the test programs #includes sched.h as the very first thing); moved the DWORD_PTR definition up, since it groups better with the pid_t definition; also need ULONG_PTR, don't need PDWORD_PTR; can't use PTW32_CONFIG_MSVC6, because if you only #include sched.h you don't get that bit in pthread.h; use a cpp symbol - (PTW32_HAVE_DWORD_PTR) to inhibit defining *_PTR if needed. Note + (PTW32_HAVE_DWORD_PTR) to inhibit defining *_PTR if needed. Note that this isn't #defined inside the conditional, because there are no other instances of these typedefs that need to be disabled, and sched.h itself is already protected against multiple inclusion; DWORD_PTR can't be size_t, because (on MSVC6) the former is "unsigned long" and the latter is "unsigned int" and C++ doesn't see them as interchangeable; minor edit to the comment... I don't like saying - "VC++" without the "Microsoft" qualifier; use PTW32_CDECL instead of - a literal __cdecl (this was why I moved the PTW32_CDECL bit into this + "VC++" without the "Microsoft" qualifier; use PTW32_CDECL instead of + a literal __cdecl (this was why I moved the PTW32_CDECL bit into this file). - * semaphore.h: Put in another idempotentized PTW32_CDECL bit here; - use PTW32_CDECL instead of __cdecl, and fixed indentation of function + * semaphore.h: Put in another idempotentized PTW32_CDECL bit here; + use PTW32_CDECL instead of __cdecl, and fixed indentation of function formal parameters. @@ -1482,7 +1804,7 @@ 2012-09-05 Daniel Richard. G * implement.h: whitespace adjustment. - * dll.c: Facilitate PTW32_STATIC_LIB being defined in a header file. + * dll.c: Facilitate PTW32_STATIC_LIB being defined in a header file. @@ -1616,8 +1938,8 @@ 2012-08-29 Daniel Richard. G - * implement.h (PTW32_INTERLOCKED_SIZE): Define as long or LONGLONG. - (PTW32_INTERLOCKED_SIZEPTR): Define as long* or LONGLONG*. + * implement.h (PTW32_INTERLOCKED_SIZE): Define as long or LONGLONG. + (PTW32_INTERLOCKED_SIZEPTR): Define as long* or LONGLONG*. * pthread_attr_getschedpolicy.c (SCHED_MAX): Fix cast. * ptw32_mutex_check_need_init.c: Fix static mutexattr_t struct initializations. * ptw32_threadStart.c (ExceptionFilter): Add cast. @@ -1696,9 +2018,9 @@ 2012-08-16 Daniel Richard. G - * pthread.h (PTW32_CONFIG_MINGW): Defined to simplify complex macro combination. - * (PTW32_CONFIG_MSVC6): Likewise. - * (PTW32_CONFIG_MSVC8): Likewise. + * pthread.h (PTW32_CONFIG_MINGW): Defined to simplify complex macro combination. + * (PTW32_CONFIG_MSVC6): Likewise. + * (PTW32_CONFIG_MSVC8): Likewise. * autostatic.c: Substitute new macros. * create.c: Likewise. * pthread_cond_wait.c: Likewise. @@ -2059,7 +2381,7 @@ 2011-07-01 Ross Johnson - * *.[ch] (PTW32_INTERLOCKED_*): Redo 23 and 64 bit versions of these + * *.[ch] (PTW32_INTERLOCKED_*): Redo 23 and 64 bit versions of these macros and re-apply in code to undo the incorrect changes from 2011-06-29; remove some size_t casts which should not be required and may be problematic.a @@ -2095,7 +2417,7 @@ 2011-06-29 Ross Johnson - * *.[ch] (PTW32_INTERLOCKED_*): These macros should now work for + * *.[ch] (PTW32_INTERLOCKED_*): These macros should now work for both 32 and 64 bit builds. The MingW versions are all inlined asm while the MSVC versions expand to their Interlocked* or Interlocked*64 counterparts appropriately. The argument type have also been changed @@ -2111,7 +2433,7 @@ compilers such as the Intel compilter icl. * implement.h (#if): Fix forms like #if HAVE_SOMETHING. * pthread.h: Likewise. - * sched.h: Likewise; PTW32_LEVEL_* becomes PTW32_SCHED_LEVEL_*. + * sched.h: Likewise; PTW32_LEVEL_* becomes PTW32_SCHED_LEVEL_*. * semaphore.h: Likewise. 2011-05-11 Ross Johnson @@ -2153,7 +2475,7 @@ 2011-03-11 Ross Johnson - * implement.h (PTW32_INTERLOCKED_*CREMENT macros): increment/decrement + * implement.h (PTW32_INTERLOCKED_*CREMENT macros): increment/decrement using ++/-- instead of add/subtract 1. * ptw32_MCS_lock.c: Make casts consistent. @@ -2194,7 +2516,7 @@ 2011-03-04 Ross Johnson - * implement.h (PTW32_INTERLOCKED_*): Mingw32 does not provide + * implement.h (PTW32_INTERLOCKED_*): Mingw32 does not provide the __sync_* intrinsics so implemented them here as macro assembler routines. MSVS Interlocked* are emmitted as intrinsics wherever possible, so we want mingw to match it; Extended to @@ -2400,7 +2722,7 @@ 2007-01-04 Kip Streithorst - * implement.h (PTW32_INTERLOCKED_COMPARE_EXCHANGE): Add Win64 + * implement.h (PTW32_INTERLOCKED_COMPARE_EXCHANGE): Add Win64 support. 2006-12-20 Ross Johnson @@ -2691,7 +3013,7 @@ * pthread.h: Fix conditional defines for static linking. * sched.h: Liekwise. * semaphore.h: Likewise. - * dll.c (PTW32_STATIC_LIB): Module is conditionally included + * dll.c (PTW32_STATIC_LIB): Module is conditionally included in the build. 2005-03-16 Ross Johnson ^M @@ -2808,14 +3130,14 @@ 2004-11-19 Ross Johnson - * config.h (PTW32_THREAD_ID_REUSE_INCREMENT): Added to allow + * config.h (PTW32_THREAD_ID_REUSE_INCREMENT): Added to allow building the library for either unique thread IDs like Solaris or non-unique thread IDs like Linux; allows application developers to override the library's default insensitivity to some apps that may not be strictly POSIX compliant. * version.rc: New resource module to encode version information within the DLL. - * pthread.h: Added PTW32_VERSION* defines and grouped sections + * pthread.h: Added PTW32_VERSION* defines and grouped sections required by resource compiler together; bulk of file is skipped if RC_INVOKED. Defined some error numbers and other names for Borland compiler. @@ -2824,7 +3146,7 @@ * pthread_cond_wait.c (ptw32_cond_wait_cleanup): Lock CV mutex at start of cleanup handler rather than at the end. - * implement.h (PTW32_THREAD_REUSE_EMPTY): Renamed from *_BOTTOM. + * implement.h (PTW32_THREAD_REUSE_EMPTY): Renamed from *_BOTTOM. (ptw32_threadReuseBottom): New global variable. * global.c (ptw32_threadReuseBottom): Declare new variable. * ptw32_reuse.c (ptw32_reuse): Change reuse LIFO stack to LILO queue @@ -2952,9 +3274,9 @@ * pthread_mutex_unlock.c (pthread_mutex_unlock): Similarly. * ptw32_InterlockedCompareExchange.c (ptw32_InterlockExchange): New function. - (PTW32_INTERLOCKED_EXCHANGE): Sets up macro to use inlined + (PTW32_INTERLOCKED_EXCHANGE): Sets up macro to use inlined ptw32_InterlockedExchange. - * implement.h (PTW32_INTERLOCKED_EXCHANGE): Set default to + * implement.h (PTW32_INTERLOCKED_EXCHANGE): Set default to InterlockedExchange(). * Makefile: Building using /Ob2 so that asm sections within inline functions are inlined. @@ -2981,7 +3303,7 @@ * pthread_spin_unlock.c (pthread_spin_unlock):Likewise. * ptw32_InterlockedCompareExchange.c: Sets up macro for inlined use. * implement.h (pthread_mutex_t_): Remove Critical Section element. - (PTW32_INTERLOCKED_COMPARE_EXCHANGE): Set to default non-inlined + (PTW32_INTERLOCKED_COMPARE_EXCHANGE): Set to default non-inlined version of InterlockedCompareExchange(). * private.c: Include ptw32_InterlockedCompareExchange.c first for inlining. @@ -3439,7 +3761,7 @@ * errno.c: Compiler directive was incorrectly including code. * pthread.h: Conditionally added some #defines from config.h needed when not building the library. e.g. NEED_ERRNO, NEED_SEM. - (PTW32_DLLPORT): Now only defined if _DLL defined. + (PTW32_DLLPORT): Now only defined if _DLL defined. (_errno): Compiler directive was incorrectly including prototype. * sched.h: Conditionally added some #defines from config.h needed when not building the library. @@ -3824,9 +4146,9 @@ 2002-01-15 Ross Johnson - * pthread.h: Unless the build explicitly defines __CLEANUP_SEH, - __CLEANUP_CXX, or __CLEANUP_C, then the build defaults to - __CLEANUP_C style cleanup. This style uses setjmp/longjmp + * pthread.h: Unless the build explicitly defines PTW32_CLEANUP_SEH, + PTW32_CLEANUP_CXX, or PTW32_CLEANUP_C, then the build defaults to + PTW32_CLEANUP_C style cleanup. This style uses setjmp/longjmp in the cancellation and thread exit implementations and therefore won't do stack unwinding if linked to applications that have it (e.g. C++ apps). This is currently consistent with most/all @@ -3915,9 +4237,9 @@ WSAGetLastError() and WSASetLastError(). * Makefile (wsock32.lib): Likewise. * create.c: Minor mostly inert changes. - * implement.h (PTW32_MAX): Move into here and renamed + * implement.h (PTW32_MAX): Move into here and renamed from sched.h. - (PTW32_MIN): Likewise. + (PTW32_MIN): Likewise. * GNUmakefile (TEST_ICE): Define if testing internal implementation of InterlockedCompareExchange. * Makefile (TEST_ICE): Likewise. @@ -3935,7 +4257,7 @@ 2001-10-17 Ross Johnson * barrier.c: Move _LONG and _LPLONG defines into - implement.h; rename to PTW32_INTERLOCKED_LONG and + implement.h; rename to PTW32_INTERLOCKED_LONG and PTW32_INTERLOCKED_LPLONG respectively. * spin.c: Likewise; ptw32_interlocked_compare_exchange used in place of InterlockedCompareExchange directly. @@ -4545,7 +4867,7 @@ (pthread_mutexattr_destroy): Set attribute to NULL before freeing it's memory - to avoid contention. - * implement.h (PTW32_EPS_CANCEL/PTW32_EPS_EXIT): + * implement.h (PTW32_EPS_CANCEL/PTW32_EPS_EXIT): Must be defined for all compilers - used as generic exception selectors by ptw32_throw(). @@ -4560,14 +4882,14 @@ * mutex.c (pthread_mutexattr_setforcecs_np): Moved to new file "nonportable.c". - * pthread.h (PTW32_BUILD): Only redefine __except + * pthread.h (PTW32_BUILD): Only redefine __except and catch compiler keywords if we aren't building - the library (ie. PTW32_BUILD is not defined) - + the library (ie. PTW32_BUILD is not defined) - this is safer than defining and then undefining if not building the library. * implement.h: Remove __except and catch undefines. - * Makefile (CFLAGS): Define PTW32_BUILD. - * GNUmakefile (CFLAGS): Define PTW32_BUILD. + * Makefile (CFLAGS): Define PTW32_BUILD. + * GNUmakefile (CFLAGS): Define PTW32_BUILD. * All appropriate: Change Pthread_exception* to ptw32_exception* to be consistent with internal @@ -4589,7 +4911,7 @@ (pthread_cancel): Ditto. * misc.c (CancelableWait): Ditto. * exit.c (pthread_exit): Ditto. - * All applicable: Change PTW32_ prefix to + * All applicable: Change PTW32_ prefix to PTW32_ prefix to remove leading underscores from private library identifiers. @@ -4626,7 +4948,7 @@ casting for functions that will be passed as parameters. (~PThreadCleanup): add cast and group expression. (_errno): Add _MD compile conditional. - (PtW32NoCatchWarn): Change pragma message. + (__PtW32NoCatchWarn): Change pragma message. * implement.h: Move and change PT_STDCALL define. @@ -4657,7 +4979,7 @@ * pthread.h: Add compile-time message when using MSC_VER compiler and C++ EH to warn application - programmers to use PtW32Catch instead of catch(...) + programmers to use __PtW32Catch instead of catch(...) if they want cancellation and pthread_exit to work. * implement.h: Remove #include ; we @@ -4703,9 +5025,9 @@ 2000-08-05 Ross Johnson - * pthread.h (PtW32CatchAll): Add macro. When compiling + * pthread.h (__PtW32CatchAll): Add macro. When compiling applications using VC++ with C++ EH rather than SEH - 'PtW32CatchAll' must be used in place of any 'catch( ... )' + '__PtW32CatchAll' must be used in place of any 'catch( ... )' if the application wants pthread cancellation or pthread_exit() to work. @@ -5107,14 +5429,14 @@ Tue Aug 17 20:00:08 1999 Mumit Khan 1999-07-09 Ross Johnson - * misc.c (CancelableWait): PTW32_EPS_CANCEL (SEH) and + * misc.c (CancelableWait): PTW32_EPS_CANCEL (SEH) and ptw32_exception_cancel (C++) used to identify the exception. - * cancel.c (pthread_testcancel): PTW32_EPS_CANCEL (SEH) and + * cancel.c (pthread_testcancel): PTW32_EPS_CANCEL (SEH) and ptw32_exception_cancel (C++) used to identify the exception. * exit.c (pthread_exit): throw/raise an exception to return to - ptw32_threadStart() to exit the thread. PTW32_EPS_EXIT (SEH) + ptw32_threadStart() to exit the thread. PTW32_EPS_EXIT (SEH) and ptw32_exception_exit (C++) used to identify the exception. * private.c (ptw32_threadStart): Add pthread_exit exception trap; @@ -5436,7 +5758,7 @@ Tue Feb 2 18:07:43 1999 Kevin Ruland Reverse LHS/RHS bitwise assignments. * pthread.h: Remove #include . - (PTW32_ATTR_VALID): Add cast. + (PTW32_ATTR_VALID): Add cast. (struct pthread_t_): Add sigmask element. * dll.c: Add "extern C" for DLLMain. @@ -5979,7 +6301,7 @@ Sat Oct 24 18:34:59 1998 Ross Johnson Fri Oct 23 00:08:09 1998 Ross Johnson - * implement.h (PTW32_TSD_KEY_REUSE): Add enum. + * implement.h (PTW32_TSD_KEY_REUSE): Add enum. * private.c (ptw32_delete_thread): Add call to ptw32_destructor_run_all() to clean up the threads keys. @@ -6065,8 +6387,8 @@ Mon Oct 12 00:00:44 1998 Ross Johnson * implement.h (ptw32_destructor_push): Remove. (ptw32_destructor_pop): Remove. (ptw32_destructor_run_all): Rename from ptw32_destructor_pop_all. - (PTW32_TSD_KEY_DELETED): Add enum. - (PTW32_TSD_KEY_INUSE): Add enum. + (PTW32_TSD_KEY_DELETED): Add enum. + (PTW32_TSD_KEY_INUSE): Add enum. * cleanup.c (ptw32_destructor_push): Remove. (ptw32_destructor_pop): Remove. @@ -6272,7 +6594,7 @@ Thu Aug 6 15:19:22 1998 Ross Johnson * private.c (ptw32_new_thread): Typecast (HANDLE) NULL. (ptw32_delete_thread): Ditto. - * implement.h: (PTW32_MAX_THREADS): Add define. This keeps + * implement.h: (PTW32_MAX_THREADS): Add define. This keeps changing in an attempt to make thread administration data types opaque and cleanup DLL startup. @@ -6418,9 +6740,9 @@ Mon Aug 3 21:19:57 1998 Ross Johnson member initialisation - cancelstate, canceltype, cancel_pending. (is_attr): Make arg "attr" a const. - * implement.h (PTW32_HANDLER_POP_LIFO): Remove definition. - (PTW32_HANDLER_POP_FIFO): Ditto. - (PTW32_VALID): Add missing newline escape (\). + * implement.h (PTW32_HANDLER_POP_LIFO): Remove definition. + (PTW32_HANDLER_POP_FIFO): Ditto. + (PTW32_VALID): Add missing newline escape (\). (ptw32_handler_node): Make element "next" a pointer. 1998-08-02 Ben Elliston @@ -6482,8 +6804,8 @@ Fri Jul 31 00:05:45 1998 Ross Johnson * condvar.c (windows.h): Add include. - * implement.h (PTW32_THIS): Remove - no longer required. - (PTW32_STACK): Use pthread_self() instead of PTW32_THIS. + * implement.h (PTW32_THIS): Remove - no longer required. + (PTW32_STACK): Use pthread_self() instead of PTW32_THIS. Thu Jul 30 23:12:45 1998 Ross Johnson @@ -6500,7 +6822,7 @@ Thu Jul 30 23:12:45 1998 Ross Johnson local storage. * implement.h: Add ptw32_threadID_TlsIndex. - Add ()s around PTW32_VALID expression. + Add ()s around PTW32_VALID expression. * misc.c (pthread_self): Re-implement using Win32 TLS to store the threads own ID. @@ -6519,7 +6841,7 @@ Wed Jul 29 11:39:03 1998 Ross Johnson Tue Jul 28 14:04:29 1998 Ross Johnson - * implement.h: Add PTW32_VALID macro. + * implement.h: Add PTW32_VALID macro. * sync.c (pthread_join): Modify to use the new thread type and ptw32_delete_thread(). Rename "target" to "thread". @@ -6535,14 +6857,14 @@ Tue Jul 28 14:04:29 1998 Ross Johnson * private.c (ptw32_find_thread): Fix return type and arg. - * implement.h: Remove PTW32_YES and PTW32_NO. + * implement.h: Remove PTW32_YES and PTW32_NO. (ptw32_new_thread): Add prototype. (ptw32_find_thread): Ditto. (ptw32_delete_thread): Ditto. (ptw32_new_thread_entry): Remove prototype. (ptw32_find_thread_entry): Ditto. (ptw32_delete_thread_entry): Ditto. - ( PTW32_NEW, PTW32_INUSE, PTW32_EXITED, PTW32_REUSE): + ( PTW32_NEW, PTW32_INUSE, PTW32_EXITED, PTW32_REUSE): Add. @@ -6725,7 +7047,7 @@ Sat Jul 25 00:00:13 1998 Ross Johnson * exit.c (pthread_exit): Fix indirection mistake. - * implement.h (PTW32_THREADS_TABLE_INDEX): Add. + * implement.h (PTW32_THREADS_TABLE_INDEX): Add. * exit.c (ptw32_vacuum): Fix incorrect args to ptw32_handler_pop_all() calls. @@ -6733,7 +7055,7 @@ Sat Jul 25 00:00:13 1998 Ross Johnson * sync.c (pthread_join): Add multiple join and async detach handling. - * implement.h (PTW32_THREADS_TABLE_INDEX): Add. + * implement.h (PTW32_THREADS_TABLE_INDEX): Add. * global.c (ptw32_threads_mutex_table): Add. @@ -6771,8 +7093,8 @@ Fri Jul 24 21:13:55 1998 Ross Johnson * exit.c (pthread_exit): Add comment explaining the longjmp(). * implement.h (ptw32_threads_thread_t): New member cancelthread. - (PTW32_YES): Define. - (PTW32_NO): Define. + (PTW32_YES): Define. + (PTW32_NO): Define. (RND_SIZEOF): Remove. * create.c (pthread_create): Rename cancelability to cancelstate. @@ -6888,7 +7210,7 @@ Fri Jul 24 00:21:21 1998 Ross Johnson (pthread_attr_getdetachstate): Implement. (pthread_attr_setdetachstate): Likewise. - * implement.h (PTW32_CANCEL_DEFAULTS): Remove. Bit fields + * implement.h (PTW32_CANCEL_DEFAULTS): Remove. Bit fields proved to be too cumbersome. Set the defaults in attr.c using the public PTHREAD_CANCEL_* constants. @@ -7074,7 +7396,7 @@ Mon Jul 20 02:31:05 1998 Ross Johnson non-sharable static data within the pthread DLL. * implement.h: Add ptw32_cleanup_stack_t, ptw32_cleanup_node_t - and PTW32_HASH_INDEX. + and PTW32_HASH_INDEX. * exit.c (pthread_exit): Begin work on cleanup and de-allocate thread-private storage. diff --git a/docs/FAQ.md b/docs/FAQ.md index ba838534..eb165feb 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -156,9 +156,9 @@ Up to and including snapshot 2001-07-12, if not defined, the cleanup style was determined automatically from the compiler used, and one of the following was defined accordingly: - __CLEANUP_SEH MSVC only - __CLEANUP_CXX C++, including MSVC++, GNU G++ - __CLEANUP_C C, including GNU GCC, not MSVC + PTW32_CLEANUP_SEH MSVC only + PTW32_CLEANUP_CXX C++, including MSVC++, GNU G++ + PTW32_CLEANUP_C C, including GNU GCC, not MSVC These defines determine the style of cleanup (see pthread.h) and, most importantly, the way that cancellation and thread exit (via @@ -171,22 +171,22 @@ the correct stack unwinding occurs regardless of where the thread is when it's canceled or exits via pthread_exit(). After snapshot 2001-07-12, unless your build explicitly defines (e.g. -via a compiler option) __CLEANUP_SEH, __CLEANUP_CXX, or __CLEANUP_C, then -the build now ALWAYS defaults to __CLEANUP_C style cleanup. This style +via a compiler option) PTW32_CLEANUP_SEH, PTW32_CLEANUP_CXX, or PTW32_CLEANUP_C, then +the build now ALWAYS defaults to PTW32_CLEANUP_C style cleanup. This style uses setjmp/longjmp in the cancellation and pthread_exit implementations, and therefore won't do stack unwinding even when linked to applications that have it (e.g. C++ apps). This is for consistency with most/all commercial Unix POSIX threads implementations. Although it was not clearly documented before, it is still necessary to -build your application using the same __CLEANUP_* define as was +build your application using the same PTW32_CLEANUP_* define as was used for the version of the library that you link with, so that the correct parts of pthread.h are included. That is, the possible defines require the following library versions: - __CLEANUP_SEH pthreadVSE.dll - __CLEANUP_CXX pthreadVCE.dll or pthreadGCE.dll - __CLEANUP_C pthreadVC.dll or pthreadGC.dll + PTW32_CLEANUP_SEH pthreadVSE.dll + PTW32_CLEANUP_CXX pthreadVCE.dll or pthreadGCE.dll + PTW32_CLEANUP_C pthreadVC.dll or pthreadGC.dll THE POINT OF ALL THIS IS: if you have not been defining one of these explicitly, then the defaults have been set according to the compiler @@ -197,12 +197,12 @@ THIS NOW CHANGES, as has been explained above. For example: If you were building your application with MSVC++ i.e. using C++ exceptions (rather than SEH) and not explicitly defining one of -__CLEANUP_*, then __CLEANUP_C++ was defined for you in pthread.h. +PTW32_CLEANUP_*, then PTW32_CLEANUP_C++ was defined for you in pthread.h. You should have been linking with pthreadVCE.dll, which does stack unwinding. If you now build your application as you had before, pthread.h will now -set __CLEANUP_C as the default style, and you will need to link +set PTW32_CLEANUP_C as the default style, and you will need to link with pthreadVC.dll. Stack unwinding will now NOT occur when a thread is canceled, nor when the thread calls pthread_exit(). @@ -212,7 +212,7 @@ objects may not be destroyed or cleaned up after a thread is canceled. If you want the same behaviour as before, then you must now define -__CLEANUP_C++ explicitly using a compiler option and link with +PTW32_CLEANUP_C++ explicitly using a compiler option and link with pthreadVCE.dll as you did before. @@ -408,18 +408,35 @@ Q 11 Why isn't pthread_t defined as a scalar (e.g. pointer or int) like it is for other POSIX threads implementations? ---- -Originally pthread_t was defined as a pointer (to the opaque pthread_t_ -struct) and later it was changed to a struct containing the original -pointer plus a sequence counter. This is allowed under both the original -POSIX Threads Standard and the current Single Unix Specification. - -When pthread_t is a simple pointer to a struct some very difficult to -debug problems arise from the process of freeing and later allocing -thread structs because new pthread_t handles can acquire the identity of -previously detached threads. The change to a struct was made, along with -some changes to their internal managment, in order to guarantee (for -practical applications) that the pthread_t handle will be unique over the -life of the running process. +The change from scalar to vector was made in response to the numerous +queries we received at that time either requesting assistance to debug +applications or reporting problems with the library that turned out to be +application bugs. Since the change we have only received requests that +we change back to scalar in order to support applications that are not +compliant with POSIX. + +Originally we defined pthread_t as a pointer (to the opaque pthread_t_ +struct) and later we changed it to a struct containing the original +pointer plus a sequence counter. This is not only allowed under both +the original POSIX Threads Standard and the current Single Unix +Specification, it is expected if the implemented chooses and is why +the standard requires pthread_t to be an opaque type. + +When pthread_t is a simple pointer some very difficult thread management +problems arise because the process of freeing and later allocing +thread structs means that new pthread_t handles can acquire the identity of +previously detached threads. There are solutions to manage this risk but +they can easily introduce their own bugs and require all developers to +spend significant time solving a problem that is not "core" to their work +and that others have already solved. The problem is rarely solved in +a portable and POSIX compliant way. It can't be because pthread_t is opaque, +i.e. a developer is not supposed to assume anything about pthread_t. Several +pthreads implmentations do provide non-portable aids, such as API calls to +return unique sequence numbers etc. + +The change to a struct was made, along with some changes to their internal +managment, in order to guarantee (for practical applications) that the +pthread_t handle will be unique over the life of the running process. Where application code attempts to compare one pthread_t against another directly, a compiler error will be emitted because structs can't be @@ -446,6 +463,6 @@ handles will remain at the peak level until the process exits. While it may be inconvenient for developers to be forced away from making assumptions about the internals of pthread_t, the advantage for the future development of pthread-win32, as well as those applications that -use it and other pthread implementations, is that the library is free to -change pthread_t internals and management as better methods arise. +use it, is that the library is free to change pthread_t internals and +management as better methods arise. diff --git a/docs/LICENSE.md b/docs/LICENSE.md new file mode 100644 index 00000000..7a4a3ea2 --- /dev/null +++ b/docs/LICENSE.md @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/docs/NEWS.md b/docs/NEWS.md index 35b8fdea..6789f55a 100644 --- a/docs/NEWS.md +++ b/docs/NEWS.md @@ -1,3 +1,196 @@ +RELEASE 3.0.0 +-------------- +(2018-08-08) + +General +------- +Note that this is a new major release. The major version increment +introduces two ABI changes along with other naming changes that will +require recompilation of linking applications and possibly some textual +changes to compile-time macro references in configuration and source +files, e.g. PTW32_* changes to PTW32_*, ptw32_* to ptw32_*, etc. + +License Change +-------------- +With the agreement of all substantial relevant contributors pthreads-win32 +version 3, with the exception of four files, is being released under the +terms of the Apache License v2.0. The APLv2 is compatible with the GPLv3 +and LGPLv3 licenses and therefore this code may continue to be legally +included within GPLv3 and LGPLv3 projects. + +A substantial relevant contributor was defined as one who has contributed +original code that implements a capability present in the releases going +forward. This excludes several contributors who have contributed code +that has been obsoleted, or have provided patches that fix bugs, +reorganise code for aesthetic or practical purposes, or improve build +processes. This distinction was necessary in order to move forward in the +likelyhood that not all contributors would be contactable. All +contributors are listed in the file CONTRIBUTORS. + +The four files that will remain LGPL but change to v3 are files used to +configure the GNU environment builds: + + aclocal.m4 + configure.ac + GNUmakefile.in + tests/GNUmakefile.in + +Contributors who have either requested this change or agreed to it when +consulted are: + +John Bossom +Alexander Terekhov +Vladimir Kliatchko +Ross Johnson + +pthreads-win32 version 2 releases will remain LGPL but version 2.11 and later +will be released under v3 of that license so that any additions to +pthreads4w version 3 code that is backported to v2 will not pollute that +code. + +Backporting and Support of Legacy Windows Releases +-------------------------------------------------- +Some changes from 2011-02-26 onward may not be compatible with pre +Windows 2000 systems. + +New bug fixes in all releases since 2.8.0 have NOT been applied to the +1.x.x series. + +Testing and verification +------------------------ +The MSVC, MinGW and MinGW64 builds have been tested on SMP architecture +(Intel x64 Hex Core) by completing the included test suite, as well as the +stress and bench tests. + +Be sure to run your builds against the test suite. If you see failures +then please consider how your toolchains might be contributing to the +failure. See the README file for more detailed descriptions of the +toolchains and test systems that we have used to get the tests to pass +successfully. + +We recommend MinGW64 over MinGW for both 64 and 32 bit GNU CC builds +only because the MinGW DWARF2 exception handling with C++ builds causes some +problems with thread cancelation. + +MinGW64 also includes its own native pthreads implementation, which you may +prefer to use. If you wish to build our library you will need to select the +Win32 native threads option at install time. We recommend also selecting the +SJLJ exception handling method for MinGW64-w32 builds. For MinGW64-w64 builds +either the SJLJ or SEH exception handling method should work. + +New Features +------------ +Other than the following, this release is feature-equivalent to v2.11.0. + +This release introduces a change to pthread_t and pthread_once_t that will +affect applications that link with the library. + +pthread_t: remains a struct but extends the reuse counter from 32 bits to 64 +bits. On 64 bit machines the overall size of the object will not increase, we +simply put 4 bytes of padding to good use reducing the risk that the counter +could wrap around in very long-running applications from small to, effectively, +zero. The 64 bit reuse counter extends risk-free run time from months +(assuming an average thread lifetime of 1ms) to centuries (assuming an +average thread lifetime of 1ns). + +pthread_once_t: removes two long-obsoleted elements and reduces it's size. + + +RELEASE 2.11.0 +-------------- +(2018-08-08) + +General +------- +New bug fixes in all releases since 2.8.0 have NOT been applied to the +1.x.x series. + +Some changes from 2011-02-26 onward may not be compatible with +pre Windows 2000 systems. + +License Change to LGPL v3 +------------------------- +pthreads-win32 version 2.11 and all future 2.x versions will be released +under the Lesser GNU Public License version 3 (LGPLv3). + +Planned Release Under the Apache License v2 +------------------------------------------- +The next major version of this software (version 3) will be released +under the Apache License version 2.0 (ALv2). Releasing 2.11 under LGPLv3 +will allow modifications to version 3 of this software to be backported +to version 2 going forward. Further to this, any GPL projects currently +using this library will be able to continue to use either version 2 or 3 +of this code in their projects. + +For more information please see: +https://www.apache.org/licenses/GPL-compatibility.html + +In order to remain consistent with this change, from this point on +modifications to this library will only be accepted against version 3 +of this software under the terms of the ALv2. They will then, where +appropriate, be backported to version 2. + +We hope to release version 3 at the same time as we release version 2.11. + +Testing and verification +------------------------ +This version has been tested on SMP architecture (Intel x64 Hex Core) +by completing the included test suite, as well as the stress and bench +tests. + +Be sure to run your builds against the test suite. If you see failures +then please consider how your toolchains might be contributing to the +failure. See the README file for more detailed descriptions of the +toolchains and test systems that we have used to get the tests to pass +successfully. We recommend MinGW64 over MinGW32 for both 64 and 32 bit +GNU CC builds. MinGW64 also includes its own independent pthreads +implementation, which you may prefer to use. + +New Features or Changes +----------------------- +For Microsoft toolchain builds: +(1) Static linking requires both this library and any linking +libraries or applications to be compiled with /MT consistently. + +(2) Static libraries have been renamed as libpthreadV*.lib +to differentiate them from DLL import libs pthreadV*.lib. + +(3) If you are using mixed linkage, e.g. linking the static /MT version +of the library to an application linked with /MD you may be able to use +GetLastError() to interrogate the error code because the library sets +both errno (via _set_errno()) and SetLastError(). + +Bug Fixes +--------- +Remove the attempt to set PTW32_USES_SEPARATE_CRT in the headers which +can cause unexpected results. In certain situations a user may want to +define it explicitly in their environment to invoke it's effects, either +when buidling the library or an application or both. See README.NONPORTABLE. +-- Ross Johnson + +The library should be more reliable under fully statically linked +scenarios. Note: we have removed the PIMAGE_TLS_CALLBACK code and +reverted to the earlier method that appears to be more reliable +across all compiler editions. +- Mark Pizzolato + +Various corrections to GNUmakefile. Although this file has been removed, +for completeness the changes have been recorded as commits to the +repository. +- Kyle Schwarz + +MinGW64-w64 defines pid_t as __int64. sched.h now reflects that. +- Kyle Schwarz + +Several tests have been fixed that were seen to fail on machines under +load. Other tests that used similar crude mechanisms to synchronise +threads (these are unit tests) had the same improvements applied: +semaphore5.c recognises that sem_destroy can legitimately return +EBUSY; mutex6*.c, mutex7*.c and mutex8*.c all replaced a single +Sleep() with a polling loop. +- Ross Johnson + + RELEASE 2.10.0 -------------- (2016-09-18) @@ -21,8 +214,8 @@ then please consider how your toolchains might be contributing to the failure. See the README file for more detailed descriptions of the toolchains and test systems that we have used to get the tests to pass successfully. We recommend MinGW64 over MinGW32 for both 64 and 32 bit -builds. MinGW also includes its own independent pthreads implementation, -which you may prefer to use. +GNU CC builds. MinGW64 also includes its own independent pthreads +implementation, which you may prefer to use. New Features ------------ @@ -59,13 +252,22 @@ pthread_win32_getabstime_np() - Return the current time plus an optional offset in a platform-aware way that is compatible with POSIX timed calls (returns the struct timespec address which is the first argument). Intended primarily to make it - easier to write tests but may be useful for applications generally. + easier to write tests but may be useful for applications generally. + +GNU compiler environments (MinGW32 and MinGW64) now have the option of using +autoconf to automatically configure the build. Builds: New makefile targets have been added and existing targets modified or removed. For example, targets to build and test all of the possible configurations of both dll and static libs. +GNU compiler builds are now explicitly using ISO C and C++ 2011 standards +compatibility. If your GNU compiler doesn't support this please consider +updating. Auto configuration is now possible via 'configure' script. The +script must be generated using autoconf - see the README file. Thanks to +Keith Marshall from the MinGW project. + Static linking: The autostatic functionality has been moved to dll.c, and extended so that builds using MSVC8 and later no longer require apps to call @@ -1035,9 +1237,9 @@ Cleanup code default style. (IMPORTANT) Previously, if not defined, the cleanup style was determined automatically from the compiler/language, and one of the following was defined accordingly: - __CLEANUP_SEH MSVC only - __CLEANUP_CXX C++, including MSVC++, GNU G++ - __CLEANUP_C C, including GNU GCC, not MSVC + PTW32_CLEANUP_SEH MSVC only + PTW32_CLEANUP_CXX C++, including MSVC++, GNU G++ + PTW32_CLEANUP_C C, including GNU GCC, not MSVC These defines determine the style of cleanup (see pthread.h) and, most importantly, the way that cancellation and thread exit (via @@ -1050,8 +1252,8 @@ the correct stack unwinding occurs regardless of where the thread is when it's canceled or exits via pthread_exit(). In this and future snapshots, unless the build explicitly defines (e.g. -via a compiler option) __CLEANUP_SEH, __CLEANUP_CXX, or __CLEANUP_C, then -the build NOW always defaults to __CLEANUP_C style cleanup. This style +via a compiler option) PTW32_CLEANUP_SEH, PTW32_CLEANUP_CXX, or PTW32_CLEANUP_C, then +the build NOW always defaults to PTW32_CLEANUP_C style cleanup. This style uses setjmp/longjmp in the cancellation and pthread_exit implementations, and therefore won't do stack unwinding even when linked to applications that have it (e.g. C++ apps). This is for consistency with most @@ -1059,17 +1261,17 @@ current commercial Unix POSIX threads implementations. Compaq's TRU64 may be an exception (no pun intended) and possible future trend. Although it was not clearly documented before, it is still necessary to -build your application using the same __CLEANUP_* define as was +build your application using the same PTW32_CLEANUP_* define as was used for the version of the library that you link with, so that the correct parts of pthread.h are included. That is, the possible defines require the following library versions: - __CLEANUP_SEH pthreadVSE.dll - __CLEANUP_CXX pthreadVCE.dll or pthreadGCE.dll - __CLEANUP_C pthreadVC.dll or pthreadGC.dll + PTW32_CLEANUP_SEH pthreadVSE.dll + PTW32_CLEANUP_CXX pthreadVCE.dll or pthreadGCE.dll + PTW32_CLEANUP_C pthreadVC.dll or pthreadGC.dll E.g. regardless of whether your app is C or C++, if you link with -pthreadVC.lib or libpthreadGC.a, then you must define __CLEANUP_C. +pthreadVC.lib or libpthreadGC.a, then you must define PTW32_CLEANUP_C. THE POINT OF ALL THIS IS: if you have not been defining one of these @@ -1080,13 +1282,13 @@ THIS NOW CHANGES, as has been explained above, but to try to make this clearer here's an example: If you were building your application with MSVC++ i.e. using C++ -exceptions and not explicitly defining one of __CLEANUP_*, then -__CLEANUP_C++ was automatically defined for you in pthread.h. +exceptions and not explicitly defining one of PTW32_CLEANUP_*, then +PTW32_CLEANUP_C++ was automatically defined for you in pthread.h. You should have been linking with pthreadVCE.dll, which does stack unwinding. If you now build your application as you had before, pthread.h will now -automatically set __CLEANUP_C as the default style, and you will need to +automatically set PTW32_CLEANUP_C as the default style, and you will need to link with pthreadVC.dll. Stack unwinding will now NOT occur when a thread is canceled, or the thread calls pthread_exit(). @@ -1096,7 +1298,7 @@ instantiated objects may not be destroyed or cleaned up after a thread is canceled. If you want the same behaviour as before, then you must now define -__CLEANUP_C++ explicitly using a compiler option and link with +PTW32_CLEANUP_C++ explicitly using a compiler option and link with pthreadVCE.dll as you did before. @@ -1239,7 +1441,7 @@ consistent with Solaris. - Thomas Pfaff * Found a fix for the library and workaround for applications for -the known bug #2, i.e. where __CLEANUP_CXX or __CLEANUP_SEH is defined. +the known bug #2, i.e. where PTW32_CLEANUP_CXX or PTW32_CLEANUP_SEH is defined. See the "Known Bugs in this snapshot" section below. This could be made transparent to applications by replacing the macros that diff --git a/docs/NOTICE.md b/docs/NOTICE.md new file mode 100644 index 00000000..60dff2b6 --- /dev/null +++ b/docs/NOTICE.md @@ -0,0 +1,7 @@ +pthreads-win32 / pthreads4w - POSIX threads for Windows +Copyright 1998 John E. Bossom +Copyright(C) 1999-2021 pthreads-win32 / pthreads4w contributors + +This product includes software developed through the colaborative +effort of several individuals, each of whom is listed in the file +CONTRIBUTORS included with this software. \ No newline at end of file diff --git a/docs/PROGRESS.md b/docs/PROGRESS.md index 9abf0bca..763183a4 100644 --- a/docs/PROGRESS.md +++ b/docs/PROGRESS.md @@ -1,4 +1,4 @@ Please see the ANNOUNCE file "Level of Standards Conformance" or the web page: -http://sources.redhat.com/pthreads-win32/conformance.html +http://sources.redhat.com/pthreads-win32conformance.html diff --git a/docs/README.CV.md b/docs/README.CV.md index 735196c3..cdbbebed 100644 --- a/docs/README.CV.md +++ b/docs/README.CV.md @@ -694,7 +694,7 @@ Sleep( 1 ); // @AT * if we are canceled. */ if (ptw32_sem_timedwait (&(cv->sema), abstime) == -1) { - result = PTW32_GET_ERRNO(); + result = PTW32_GET_ERRNO(); } } @@ -1137,7 +1137,7 @@ pthread_cond_destroy (pthread_cond_t * cond) return EINVAL; } - if (*cond != (pthread_cond_t) PTW32_OBJECT_AUTO_INIT) + if (*cond != (pthread_cond_t) PTW32_OBJECT_AUTO_INIT) {(*cond cv = *cond; @@ -1189,7 +1189,7 @@ pthread_cond_destroy (pthread_cond_t * cond) /* * Check again. */ - if (*cond == (pthread_cond_t) PTW32_OBJECT_AUTO_INIT) + if (*cond == (pthread_cond_t) PTW32_OBJECT_AUTO_INIT) {(*cond /* * This is all we need to do to destroy a statically @@ -1272,7 +1272,7 @@ ptw32_cond_wait_cleanup(void * args) */ if (sem_post(&(cv->semBlockLock)) != 0) {(sem_post(&(cv->semBlockLock)) - *resultPtr = PTW32_GET_ERRNO(); + *resultPtr = PTW32_GET_ERRNO(); return; } } @@ -1286,7 +1286,7 @@ ptw32_cond_wait_cleanup(void * args) */ if (sem_post(&(cv->semBlockQueue)) != 0) {(sem_post(&(cv->semBlockQueue)) - *resultPtr = PTW32_GET_ERRNO(); + *resultPtr = PTW32_GET_ERRNO(); return; } } @@ -1322,7 +1322,7 @@ ptw32_cond_timedwait (pthread_cond_t * cond, * again inside the guarded section of ptw32_cond_check_need_init() * to avoid race conditions. */ - if (*cond == (pthread_cond_t) PTW32_OBJECT_AUTO_INIT) + if (*cond == (pthread_cond_t) PTW32_OBJECT_AUTO_INIT) {(*cond result = ptw32_cond_check_need_init(cond); } @@ -1385,7 +1385,7 @@ ptw32_cond_timedwait (pthread_cond_t * cond, */ if (ptw32_sem_timedwait (&(cv->semBlockQueue), abstime) != 0) {(ptw32_sem_timedwait - result = PTW32_GET_ERRNO(); + result = PTW32_GET_ERRNO(); } } @@ -1421,7 +1421,7 @@ ptw32_cond_unblock (pthread_cond_t * cond, * No-op if the CV is static and hasn't been initialised yet. * Assuming that any race condition is harmless. */ - if (cv == (pthread_cond_t) PTW32_OBJECT_AUTO_INIT) + if (cv == (pthread_cond_t) PTW32_OBJECT_AUTO_INIT) {(cv return 0; } diff --git a/docs/README.NONPORTABLE.md b/docs/README.NONPORTABLE.md index 5bc05737..fe30cbde 100644 --- a/docs/README.NONPORTABLE.md +++ b/docs/README.NONPORTABLE.md @@ -395,24 +395,33 @@ the API function pthread_equal() to test for equality. The problem -Certain applications would like to be able to access only the 'pure' pthread_t -id values, primarily to use as keys into data structures to manage threads or +Certain applications would like to be able to access a scalar pthread_t, +primarily to use as keys into data structures to manage threads or thread-related data, but this is not possible in a maximally portable and standards compliant way for current POSIX threads implementations. -For implementations that define pthread_t as a scalar, programmers often employ -direct relational and equality operators on pthread_t. This code will break when -ported to an implementation that defines pthread_t as an aggregate type. +This use is often required because pthread_t values are not unique through +the life of the process and so it is necessary for the application to keep +track of a threads status itself, and ironically this is because they are +scalar types in the first place. + +To my knowledge the only platform that provides a scalar pthread_t that is +unique through the life of a process is Solaris. Other platforms, including +HPUX, will not provide support to applications that do this. + +For implementations that define pthread_t as a scalar, programmers often +employ direct relational and equality operators with pthread_t. This code +will break when ported to a standard-comforming implementation that defines +pthread_t as an aggregate type. For implementations that define pthread_t as an aggregate, e.g. a struct, programmers can use memcmp etc., but then face the prospect that the struct may include alignment padding bytes or bits as well as extra implementation-specific members that are not part of the unique identifying value. -[While this is not currently the case for pthreads-win32, opacity also -means that an implementation is free to change the definition, which should -generally only require that applications be recompiled and relinked, not -rewritten.] +Opacity also means that an implementation is free to change the definition, +which should generally only require that applications be recompiled and relinked, +not rewritten. Doesn't the compiler take care of padding? @@ -456,9 +465,9 @@ How can we force the behaviour we need? Solutions Adding new functions to the standard API or as non-portable extentions is -the only reliable and portable way to provide the necessary operations. -Remember also that POSIX is not tied to the C language. The most common -functions that have been suggested are: +the only reliable to provide the necessary operations. Remember also that +POSIX is not tied to the C language. The most common functions that have +been suggested are: pthread_null() pthread_compare() @@ -779,7 +788,8 @@ extention: provided the union contains a member of the same type as the object then the object may be cast to the union itself. We could use this feature to speed up the pthrcmp() function from example 2 -above by casting rather than assigning the pthread_t arguments to the union, e.g.: +above by directly referencing rather than copying the pthread_t arguments to +the local union variables, e.g.: int pthcmp(pthread_t left, pthread_t right) { diff --git a/docs/README.md b/docs/README.md index 41147b3c..441472d1 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,23 +1,16 @@ -PTHREADS-WIN32 -============== - -pthreads-win32 is free software, distributed under the GNU Lesser -General Public License (LGPL). See the file 'COPYING.LIB' for terms -and conditions. Also see the file 'COPYING' for information -specific to pthreads-win32, copyrights and the LGPL. - +PTHREADS4W (a.k.a. PTHREADS-WIN32) +================================== What is it? ----------- -pthreads-win32 (a.k.a. pthreads4w) is an Open Source Software -implementation of the Threads component of the POSIX 1003.1c 1995 -Standard (or later) for Microsoft's Windows environment. Some functions -from POSIX 1003.1b are also supported, including semaphores. Other -related functions include the set of read-write lock functions. The -library also supports some of the functionality of the Open -Group's Single Unix specification, namely mutex types, plus some common -and pthreads-win32 specific non-portable routines (see README.NONPORTABLE). +pthreads-win32 / pthreads4w is an Open Source Software implementation of the Threads +component of the POSIX 1003.1c 1995 Standard (or later) for Microsoft's +Windows environment. Some functions from POSIX 1003.1b are also supported, +including semaphores. Other related functions include the set of read-write +lock functions. The library also supports some of the functionality of the +Open Group's Single Unix specification, namely mutex types, plus some common +and pthreads4w specific non-portable routines (see README.NONPORTABLE). See the file "ANNOUNCE" for more information including standards conformance details and the list of supported and unsupported @@ -26,7 +19,7 @@ routines. Prerequisites ------------- -MSVC or GNU C (MinGW32 or MinGW64 MSys development kit) +MSVC or GNU C (MinGW or MinGW64 with AutoConf Tools) To build from source. QueueUserAPCEx by Panagiotis E. Hadjidoukas @@ -37,15 +30,15 @@ QueueUserAPCEx by Panagiotis E. Hadjidoukas For true async cancellation of threads (including blocked threads). This is a DLL and Windows driver that provides pre-emptive APC by forcing threads into an alertable state when the APC is queued. - Both the DLL and driver are provided with the pthreads-win32.exe - self-unpacking ZIP, and on the pthreads-win32 FTP site (in source + Both the DLL and driver are provided with the pthreads4w.exe + self-unpacking ZIP, and on the pthreads4w FTP site (in source and pre-built forms). Currently this is a separate LGPL package to - pthreads-win32. See the README in the QueueUserAPCEx folder for + pthreads4w. See the README in the QueueUserAPCEx folder for installation instructions. - pthreads-win32 will automatically detect if the QueueUserAPCEx DLL + pthreads4w will automatically detect if the QueueUserAPCEx DLL QuserEx.DLL is available and whether the driver AlertDrv.sys is - loaded. If it is not available, pthreads-win32 will simulate async + loaded. If it is not available, pthreads4w will simulate async cancellation, which means that it can async cancel only threads that are runnable. The simulated async cancellation cannot cancel blocked threads. @@ -206,16 +199,16 @@ of the library that use exceptions as part of the thread cancellation and exit implementation. The default version uses setjmp/longjmp. -If you use either pthreadVCE or pthreadGCE: +If you use either pthreadVCE[2] or pthreadGCE[2]: 1. [See also the discussion in the FAQ file - Q2, Q4, and Q5] If your application contains catch(...) blocks in your POSIX threads then you will need to replace the "catch(...)" with the macro -"PtW32Catch", eg. +"__PtW32Catch", eg. - #ifdef PtW32Catch - PtW32Catch { + #ifdef __PtW32Catch + __PtW32Catch { ... } #else @@ -228,6 +221,13 @@ Otherwise neither pthreads cancellation nor pthread_exit() will work reliably when using versions of the library that use C++ exceptions for cancellation and thread exit. +NB: [lib]pthreadGCE[2] does not support asynchronous cancellation. Any +attempt to cancel a thread set for asynchronous cancellation using +this version of the library will cause the applicaton to terminate. +We believe this is due to the "unmanaged" context switch that is +disrupting the stack unwinding mechanism and which is used +to cancel blocked threads. See pthread_cancel.c + Other name changes ------------------ @@ -252,9 +252,9 @@ Cleanup code default style Previously, if not defined, the cleanup style was determined automatically from the compiler used, and one of the following was defined accordingly: - __CLEANUP_SEH MSVC only - __CLEANUP_CXX C++, including MSVC++, GNU G++ - __CLEANUP_C C, including GNU GCC, not MSVC + PTW32_CLEANUP_SEH MSVC only + PTW32_CLEANUP_CXX C++, including MSVC++, GNU G++ + PTW32_CLEANUP_C C, including GNU GCC, not MSVC These defines determine the style of cleanup (see pthread.h) and, most importantly, the way that cancellation and thread exit (via @@ -267,24 +267,24 @@ the correct stack unwinding occurs regardless of where the thread is when it's canceled or exits via pthread_exit(). In this snapshot, unless the build explicitly defines (e.g. via a -compiler option) __CLEANUP_SEH, __CLEANUP_CXX, or __CLEANUP_C, then -the build NOW always defaults to __CLEANUP_C style cleanup. This style +compiler option) PTW32_CLEANUP_SEH, PTW32_CLEANUP_CXX, or PTW32_CLEANUP_C, then +the build NOW always defaults to PTW32_CLEANUP_C style cleanup. This style uses setjmp/longjmp in the cancellation and pthread_exit implementations, and therefore won't do stack unwinding even when linked to applications that have it (e.g. C++ apps). This is for consistency with most/all commercial Unix POSIX threads implementations. Although it was not clearly documented before, it is still necessary to -build your application using the same __CLEANUP_* define as was +build your application using the same PTW32_CLEANUP_* define as was used for the version of the library that you link with, so that the correct parts of pthread.h are included. That is, the possible defines require the following library versions: - __CLEANUP_SEH pthreadVSE.dll - __CLEANUP_CXX pthreadVCE.dll or pthreadGCE.dll - __CLEANUP_C pthreadVC.dll or pthreadGC.dll + PTW32_CLEANUP_SEH pthreadVSE.dll + PTW32_CLEANUP_CXX pthreadVCE.dll or pthreadGCE.dll + PTW32_CLEANUP_C pthreadVC.dll or pthreadGC.dll -It is recommended that you let pthread.h use it's default __CLEANUP_C +It is recommended that you let pthread.h use it's default PTW32_CLEANUP_C for both library and application builds. That is, don't define any of the above, and then link with pthreadVC.lib (MSVC or MSVC++) and libpthreadGC.a (MinGW GCC or G++). The reason is explained below, but @@ -328,16 +328,23 @@ MinGW64 multilib disabled Building with MS Visual Studio (C, VC++ using C++ EH, or Structured EH) ----------------------------------------------------------------------- +NOTE: A VS project/solution/whatever file is included as a contributed +work and is not used of maintained in development. All building and +testing is done using makefiles. We use the native make system for each +toolchain, which is 'nmake' in this case. + From the source directory run nmake without any arguments to list help information. E.g. $ nmake As examples, as at Release 2.10 the pre-built DLLs and static libraries -are built from the following command-lines: +can be built using one of the following command-lines: -[Note: "setenv" comes with the SDK. "/2003" is used to override my build -system which is Win7 (at the time of writing) for backwards compatibility.] +[Note: "setenv" comes with the SDK which is not required to build the library. +I use it to build and test both 64 and 32 bit versions of the library. +"/2003" is used to override my build system which is Win7 (at the time of +writing) for backwards compatibility.] $ setenv /x64 /2003 /Release $ nmake realclean VC @@ -354,7 +361,7 @@ $ nmake realclean VC-static $ nmake realclean VCE-static $ nmake realclean VSE-static -If you want to differentiate between libraries by their names you can use, +If you want to differentiate or customise library naming you can use, e.g.: $ nmake realclean VC EXTRAVERSION="-w64" @@ -368,11 +375,6 @@ pthreadVC2-w64.lib To build and test all DLLs and static lib compatibility versions (VC, VCE, VSE): -[Note that the EXTRAVERSION="..." option is passed to the tests Makefile -when you target "all-tests". If you change to the tests directory and -run the tests you will need to repeat the option explicitly to the test -"nmake" command-line.] - $ setenv /x64 /2003 /release $ nmake all-tests @@ -382,6 +384,11 @@ running nmake. E.g.: $ cd tests $ nmake VC +Note: the EXTRAVERSION="..." option is passed to the tests Makefile +when you target "all-tests". If you build the library then change to the +tests directory to run the tests you will need to repeat the option +explicitly to the test "nmake" command-line. + For failure analysis etc. individual tests can be built and run, e.g: @@ -391,8 +398,7 @@ $ nmake VC TESTS="foo bar" This builds and runs all prerequisite tests as well as the individual tests listed. Prerequisite tests are defined in tests\runorder.mk. -To build and run only those tests listed use, i.e. without the -additional prerequistite dependency tests: +To build and run only the tests listed use: $ cd tests $ nmake VC NO_DEPS=1 TESTS="foo bar" @@ -401,13 +407,27 @@ $ nmake VC NO_DEPS=1 TESTS="foo bar" Building with MinGW ------------------- -Please use Mingw64 to build either 64 or 32 bit variants of the DLL that will -run on 64 bit systems. We have found that Mingw32 builds of the GCE library -variants fail when run on 64 bit systems. +NOTE: All building and testing is done using makefiles. We use the native +make system for each toolchain, which is 'make' in this case. + +We have found that Mingw builds of the GCE library variants can fail when +run on 64 bit systems, believed to be due to the DWARF2 exception handling +being a 32 bit mechanism. The GC variants are fine. MinGW64 offers +SJLJ or SEH exception handling so choose one of those. + +From the source directory: + +run 'autoheader' to rewrite the config.h file +run 'autoconf' to rewrite the GNUmakefiles (library and tests) +run './configure' to create config.h and GNUmakefile. +run 'make' without arguments to list possible targets. -From the source directory, run 'make' without arguments for help information. +E.g. -$ make +$ autoheader +$ autoconf +$ ./configure +$ make realclean all-tests With MinGW64 multilib installed the following variables can be defined either on the make command line or in the shell environment: @@ -442,11 +462,6 @@ libpthreadGC2-w64.a To build and test all DLLs and static lib compatibility variants (GC, GCE): -Note that the ARCH="..." and/or EXTRAVERSION="..." options are passed to the -tests GNUmakefile when you target "all-tests". If you change to the tests -directory and run the tests you will need to repeat those options explicitly -to the test "make" command-line. - $ make all-tests or, with MinGW64 (multilib enabled): $ make all-tests ARCH=-m64 @@ -458,6 +473,11 @@ running make. E.g.: $ cd tests $ make GC +Note that the ARCH="..." and/or EXTRAVERSION="..." options are passed to the +tests GNUmakefile when you target "all-tests". If you change to the tests +directory and run the tests you will need to repeat those options explicitly +to the test "make" command-line. + For failure analysis etc. individual tests can be built and run, e.g: $ cd tests @@ -466,8 +486,7 @@ $ make GC TESTS="foo bar" This builds and runs all prerequisite tests as well as the individual tests listed. Prerequisite tests are defined in tests\runorder.mk. -To build and run only those tests listed use, i.e. without the additional -prerequistite dependency tests: +To build and run only those tests listed use: $ cd tests $ make GC NO_DEPS=1 TESTS="foo bar" @@ -512,98 +531,27 @@ Cygwin implements it's own POSIX threads routines and these will be the ones to use if you develop using Cygwin. -Ready to run binaries +Building applications --------------------- -For convenience, the following ready-to-run files can be downloaded -from the FTP site (see under "Availability" below): +The files you will need for your application build are: +The four header files: + _ptw32.h pthread.h semaphore.h sched.h - pthreadVC2.dll - built with MSVC compiler using C setjmp/longjmp - pthreadVC2.lib - pthreadVCE2.dll - built with MSVC++ compiler using C++ EH - pthreadVCE2.lib - pthreadVSE2.dll - built with MSVC compiler using SEH - pthreadVSE2.lib - pthreadGC2.dll - built with Mingw32 GCC - libpthreadGC2.a - derived from pthreadGC.dll - pthreadGCE2.dll - built with Mingw32 G++ - libpthreadGCE2.a - derived from pthreadGCE.dll - -You may also need to include runtime DLLs from your SDK when -distributing your applications. - -Building applications with GNU compilers ----------------------------------------- - -If you're using pthreadGC2.dll: - -With the three header files, pthreadGC2.dll and libpthreadGC2.a in the -same directory as your application myapp.c, you could compile, link -and run myapp.c under MinGW as follows: - - gcc -o myapp.exe myapp.c -I. -L. -lpthreadGC2 - myapp - -Or put pthreadGC2.dll in an appropriate directory in your PATH, -put libpthreadGC2.a in your system lib directory, and -put the three header files in your system include directory, -then use: - gcc -o myapp.exe myapp.c -lpthreadGC - myapp +The DLL library files that you built: + pthread*.dll + plus the matching *.lib (MSVS) or *.a file (GNU) +or, the static link library that you built: + pthread*.lib (MSVS) or libpthread*.a (GNU) -If you're using pthreadGCE2.dll: - -With the three header files, pthreadGCE2.dll and libpthreadGCE2.a -in the same directory as your application myapp.c, you could compile, -link and run myapp.c under Mingw32 as follows: - - gcc -x c++ -o myapp.exe myapp.c -I. -L. -lpthreadGCE2 - myapp - -Or put pthreadGCE.dll and gcc.dll in an appropriate directory in -your PATH, put libpthreadGCE.a in your system lib directory, and -put the three header files in your system include directory, -then use: - - gcc -x c++ -o myapp.exe myapp.c -lpthreadGCE - myapp - - -Availability ------------- - -The complete source code in either unbundled, self-extracting -Zip file, or tar/gzipped format can be found at: - - ftp://sources.redhat.com/pub/pthreads-win32 - -The pre-built DLL, export libraries and matching pthread.h can -be found at: - - ftp://sources.redhat.com/pub/pthreads-win32/dll-latest - -Home page: - - http://sources.redhat.com/pthreads-win32/ - - -Mailing list ------------- - -There is a mailing list for discussing pthreads on Win32. -To join, send email to: - - pthreads-win32-subscribe@sources.redhat.com - -Unsubscribe by sending mail to: - - pthreads-win32-unsubscribe@sources.redhat.com - +Place them in the appropriate directories for your build, which may be the +standard compiler locations or, locations specific to your project (you +might have a separate third-party dependency tree for example). Acknowledgements ---------------- @@ -621,12 +569,4 @@ industry can be measured by it's open standards. ---- Ross Johnson - - - - - - - - - + diff --git a/docs/TODO.md b/docs/TODO.md index a07a2ab5..f5ad0dca 100644 --- a/docs/TODO.md +++ b/docs/TODO.md @@ -6,21 +6,4 @@ IMO, to do this in a source code compatible way requires implementation of POSIX shared memory functions, etc. - -2. For version 3 onwards: the following types need to change, resulting in an ABI - change: - - a) ptw32_handle_t (a.k.a. pthread_t) - Change the reuse counter from unsigned int to size_t. Type "int" on 32 bit - and 64 bit Windows is 32 bits wide. - - To give an indication of relative effectiveness of the current "unsigned int", - consider an application that creates and detaches threads at the rate of 1 - per millisecond. At this rate the reuse counter will max out after 49 days. - - After changing to "size_t" an application compiled for x64 and creating and - detaching a thread every nanosecond would max out after 584 years. - - b) pthread_once_t - Remove unused elements. - \ No newline at end of file + \ No newline at end of file diff --git a/errno.c b/errno.c index 968e8918..2c978ab3 100644 --- a/errno.c +++ b/errno.c @@ -19,17 +19,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/global.c b/global.c index 0f743dc6..17934a31 100644 --- a/global.c +++ b/global.c @@ -19,17 +19,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/implement.h b/implement.h index 1f4f0a60..7f756b88 100644 --- a/implement.h +++ b/implement.h @@ -11,24 +11,25 @@ * Copyright(C) 1998 John E. Bossom * Copyright(C) 1999-2021 pthreads-win32 / pthreads4w contributors * - * Contact Email: Ross.Johnson@homemail.com.au + * Homepage1: http://sourceware.org/pthreads-win32/ + * Homepage2: http://sourceforge.net/projects/pthreads4w/ * * The current list of contributors is contained * in the file CONTRIBUTORS included with the source * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., @@ -40,16 +41,20 @@ #if !defined(_IMPLEMENT_H) #define _IMPLEMENT_H -#if !defined(PTW32_CONFIG_H) && !defined(_PTHREAD_TEST_H_) +#if !defined (PTW32_CONFIG_H) # error "config.h was not #included" #endif +#include <_ptw32.h> + #if !defined(_WIN32_WINNT) # define _WIN32_WINNT 0x0400 #endif -#include +#define WIN32_LEAN_AND_MEAN +#include +#include /* * In case windows.h doesn't define it (e.g. WinCE perhaps) */ @@ -60,54 +65,39 @@ typedef VOID (APIENTRY *PAPCFUNC)(DWORD dwParam); /* * Designed to allow error values to be set and retrieved in builds where * MSCRT libraries are statically linked to DLLs. + * + * This does not handle the case where a static pthreads4w lib is linked + * to a static linked app. Compiling and linking pthreads.c with app.c + * as one does work with the right macros defined. See tests/Makefile + * for clues or just "cd tests && nmake clean VC-static". */ #if ! defined(WINCE) && \ - (( defined(PTW32_CONFIG_MINGW) && __MSVCRT_VERSION__ >= 0x0800 ) || \ + (( defined(__MINGW32__) && __MSVCRT_VERSION__ >= 0x0800 ) || \ ( defined(_MSC_VER) && _MSC_VER >= 1400 )) /* MSVC8+ */ -# if defined(PTW32_CONFIG_MINGW) +# if defined(__MINGW32__) __attribute__((unused)) # endif static int ptw32_get_errno(void) { int err = 0; _get_errno(&err); return err; } # define PTW32_GET_ERRNO() ptw32_get_errno() -# if defined(PTW32_USES_SEPARATE_CRT) -# if defined(PTW32_CONFIG_MINGW) +# if defined(__MINGW32__) __attribute__((unused)) -# endif +# endif static void ptw32_set_errno(int err) { _set_errno(err); SetLastError(err); } # define PTW32_SET_ERRNO(err) ptw32_set_errno(err) -# else -# define PTW32_SET_ERRNO(err) _set_errno(err) -# endif #else # define PTW32_GET_ERRNO() (errno) -# if defined(PTW32_USES_SEPARATE_CRT) -# if defined(PTW32_CONFIG_MINGW) +# if defined(__MINGW32__) __attribute__((unused)) -# endif +# endif static void ptw32_set_errno(int err) { errno = err; SetLastError(err); } # define PTW32_SET_ERRNO(err) ptw32_set_errno(err) -# else -# define PTW32_SET_ERRNO(err) (errno = (err)) -# endif -#endif - -/* - * note: ETIMEDOUT is correctly defined in winsock.h - */ -#include - -/* - * In case ETIMEDOUT hasn't been defined above somehow. - */ -#if !defined(ETIMEDOUT) -# define ETIMEDOUT 10060 /* This is the value in winsock.h. */ #endif #if !defined(malloc) # include #endif -#if defined(__CLEANUP_C) +#if defined(PTW32_CLEANUP_C) # include #endif @@ -128,20 +118,20 @@ static void ptw32_set_errno(int err) { errno = err; SetLastError(err); } /* MSVC 7.1 doesn't like complex #if expressions */ #define INLINE -#if defined(PTW32_BUILD_INLINED) +#if defined (PTW32_BUILD_INLINED) # if defined(HAVE_C_INLINE) || defined(__cplusplus) # undef INLINE # define INLINE inline # endif #endif -#if defined(PTW32_CONFIG_MSVC6) +#if defined (PTW32_CONFIG_MSVC6) /* * MSVC 6 does not use the "volatile" qualifier */ -# define PTW32_INTERLOCKED_VOLATILE +# define PTW32_INTERLOCKED_VOLATILE #else -# define PTW32_INTERLOCKED_VOLATILE volatile +# define PTW32_INTERLOCKED_VOLATILE volatile #endif #define PTW32_INTERLOCKED_LONG long @@ -167,7 +157,7 @@ static void ptw32_set_errno(int err) { errno = err; SetLastError(err); } #endif #define PTW32_INTERLOCKED_PVOID_PTR PTW32_INTERLOCKED_VOLATILE PVOID* -#if defined(PTW32_CONFIG_MINGW) +#if defined(__MINGW32__) # include #elif defined(__BORLANDC__) # define int64_t ULONGLONG @@ -182,11 +172,13 @@ static void ptw32_set_errno(int err) { errno = err; SetLastError(err); } * Don't allow the linker to optimize away dll.obj (dll.o) in static builds. */ #if defined (PTW32_STATIC_LIB) && defined (PTW32_BUILD) && !defined (PTW32_TEST_SNEAK_PEEK) +PTW32_BEGIN_C_DECLS void ptw32_autostatic_anchor(void); -# if defined(PTW32_CONFIG_MINGW) +# if defined(__GNUC__) __attribute__((unused, used)) # endif static void (*local_autostatic_anchor)(void) = ptw32_autostatic_anchor; +PTW32_END_C_DECLS #endif typedef enum @@ -231,9 +223,9 @@ struct ptw32_thread_t_ void *parms; void *keys; void *nextAssoc; -#if defined(__CLEANUP_C) +#if defined(PTW32_CLEANUP_C) jmp_buf start_mark; /* Jump buffer follows void* so should be aligned */ -#endif /* __CLEANUP_C */ +#endif /* PTW32_CLEANUP_C */ #if defined(HAVE_SIGSET_T) sigset_t sigmask; #endif /* HAVE_SIGSET_T */ @@ -262,7 +254,7 @@ struct ptw32_thread_t_ /* * Special value to mark attribute objects as valid. */ -#define PTW32_ATTR_VALID ((unsigned long) 0xC4C0FFEE) +#define PTW32_ATTR_VALID ((unsigned long) 0xC4C0FFEE) struct pthread_attr_t_ { @@ -299,8 +291,8 @@ struct sem_t_ #endif }; -#define PTW32_OBJECT_AUTO_INIT ((void *)(size_t) -1) -#define PTW32_OBJECT_INVALID NULL +#define PTW32_OBJECT_AUTO_INIT ((void *)(size_t) -1) +#define PTW32_OBJECT_INVALID NULL struct pthread_mutex_t_ { @@ -323,9 +315,9 @@ struct pthread_mutex_t_ enum ptw32_robust_state_t_ { - PTW32_ROBUST_CONSISTENT, - PTW32_ROBUST_INCONSISTENT, - PTW32_ROBUST_NOTRECOVERABLE + PTW32_ROBUST_CONSISTENT, + PTW32_ROBUST_INCONSISTENT, + PTW32_ROBUST_NOTRECOVERABLE }; typedef enum ptw32_robust_state_t_ ptw32_robust_state_t; @@ -349,15 +341,15 @@ struct pthread_mutexattr_t_ }; /* - * Possible values, other than PTW32_OBJECT_INVALID, + * Possible values, other than PTW32_OBJECT_INVALID, * for the "interlock" element in a spinlock. * * In this implementation, when a spinlock is initialised, * the number of cpus available to the process is checked. * If there is only one cpu then "interlock" is set equal to - * PTW32_SPIN_USE_MUTEX and u.mutex is an initialised mutex. + * PTW32_SPIN_USE_MUTEX and u.mutex is an initialised mutex. * If the number of cpus is greater than 1 then "interlock" - * is set equal to PTW32_SPIN_UNLOCKED and the number is + * is set equal to PTW32_SPIN_UNLOCKED and the number is * stored in u.cpus. This arrangement allows the spinlock * routines to attempt an InterlockedCompareExchange on "interlock" * immediately and, if that fails, to try the inferior mutex. @@ -365,10 +357,10 @@ struct pthread_mutexattr_t_ * "u.cpus" isn't used for anything yet, but could be used at * some point to optimise spinlock behaviour. */ -#define PTW32_SPIN_INVALID (0) -#define PTW32_SPIN_UNLOCKED (1) -#define PTW32_SPIN_LOCKED (2) -#define PTW32_SPIN_USE_MUTEX (3) +#define PTW32_SPIN_INVALID (0) +#define PTW32_SPIN_UNLOCKED (1) +#define PTW32_SPIN_LOCKED (2) +#define PTW32_SPIN_USE_MUTEX (3) struct pthread_spinlock_t_ { @@ -412,7 +404,7 @@ struct pthread_barrierattr_t_ struct pthread_key_t_ { DWORD key; - void (PTW32_CDECL *destructor) (void *); + void (PTW32_CDECL *destructor) (void *); ptw32_mcs_lock_t keyLock; void *threads; }; @@ -423,7 +415,7 @@ typedef struct ThreadParms ThreadParms; struct ThreadParms { pthread_t tid; - void *(PTW32_CDECL *start) (void *); + void * (PTW32_CDECL *start) (void *); void *arg; }; @@ -451,7 +443,7 @@ struct pthread_condattr_t_ int pshared; }; -#define PTW32_RWLOCK_MAGIC 0xfacade2 +#define PTW32_RWLOCK_MAGIC 0xfacade2 struct pthread_rwlock_t_ { @@ -585,7 +577,7 @@ struct ThreadKeyAssoc }; -#if defined(__CLEANUP_SEH) +#if defined(PTW32_CLEANUP_SEH) /* * -------------------------------------------------------------- * MAKE_SOFTWARE_EXCEPTION @@ -622,13 +614,13 @@ struct ThreadKeyAssoc */ #define EXCEPTION_PTW32_SERVICES \ MAKE_SOFTWARE_EXCEPTION( SE_ERROR, \ - PTW32_SERVICES_FACILITY, \ - PTW32_SERVICES_ERROR ) + PTW32_SERVICES_FACILITY, \ + PTW32_SERVICES_ERROR ) -#define PTW32_SERVICES_FACILITY 0xBAD -#define PTW32_SERVICES_ERROR 0xDEED +#define PTW32_SERVICES_FACILITY 0xBAD +#define PTW32_SERVICES_ERROR 0xDEED -#endif /* __CLEANUP_SEH */ +#endif /* PTW32_CLEANUP_SEH */ /* * Services available through EXCEPTION_PTW32_SERVICES @@ -636,20 +628,20 @@ struct ThreadKeyAssoc * generic exception selectors. */ -#define PTW32_EPS_EXIT (1) -#define PTW32_EPS_CANCEL (2) +#define PTW32_EPS_EXIT (1) +#define PTW32_EPS_CANCEL (2) /* Useful macros */ -#define PTW32_MAX(a,b) ((a)<(b)?(b):(a)) -#define PTW32_MIN(a,b) ((a)>(b)?(b):(a)) +#define PTW32_MAX(a,b) ((a)<(b)?(b):(a)) +#define PTW32_MIN(a,b) ((a)>(b)?(b):(a)) /* Declared in pthread_cancel.c */ extern DWORD (*ptw32_register_cancellation) (PAPCFUNC, HANDLE, DWORD); /* Thread Reuse stack bottom marker. Must not be NULL or any valid pointer to memory. */ -#define PTW32_THREAD_REUSE_EMPTY ((ptw32_thread_t *)(size_t) 1) +#define PTW32_THREAD_REUSE_EMPTY ((ptw32_thread_t *)(size_t) 1) extern int ptw32_processInitialized; extern ptw32_thread_t * ptw32_threadReuseTop; @@ -678,10 +670,7 @@ extern ptw32_mcs_lock_t ptw32_spinlock_test_init_lock; extern int pthread_count; #endif -#if defined(__cplusplus) -extern "C" -{ -#endif /* __cplusplus */ +PTW32_BEGIN_C_DECLS /* * ===================== @@ -726,7 +715,7 @@ extern "C" void PTW32_CDECL ptw32_rwlock_cancelwrwait (void *arg); /* matches type ptw32_cleanup_callback_t this way */ -#if ! defined (PTW32_CONFIG_MINGW) || (defined (__MSVCRT__) && ! defined (__DMC__)) +#if ! defined (__MINGW32__) || (defined (__MSVCRT__) && ! defined (__DMC__)) unsigned __stdcall #else void @@ -751,12 +740,11 @@ extern "C" void ptw32_mcs_node_transfer (ptw32_mcs_local_node_t * new_node, ptw32_mcs_local_node_t * old_node); -#if defined(NEED_FTIME) void ptw32_timespec_to_filetime (const struct timespec *ts, FILETIME * ft); + void ptw32_filetime_to_timespec (const FILETIME * ft, struct timespec *ts); -#endif -/* Declared in misc.c */ +/* Declared in pthw32_calloc.c */ #if defined(NEED_CALLOC) #define calloc(n, s) ptw32_calloc(n, s) void *ptw32_calloc (size_t n, size_t s); @@ -764,32 +752,16 @@ extern "C" char *ptw32_strdup (const char *s); -/* Declared in private.c */ -#if defined(_MSC_VER) -/* - * Ignore the warning: - * "C++ exception specification ignored except to indicate that - * the function is not __declspec(nothrow)." - */ -#pragma warning(disable:4290) -#endif - void ptw32_throw (DWORD exception) -#if defined(__CLEANUP_CXX) - throw(ptw32_exception_cancel,ptw32_exception_exit) -#endif -; - -#if defined(__cplusplus) -} -#endif /* __cplusplus */ +/* Declared in ptw32_throw.c */ +void ptw32_throw (DWORD exception); +PTW32_END_C_DECLS #if defined(_UWIN_) # if defined(_MT) -# if defined(__cplusplus) -extern "C" -{ -# endif + +PTW32_BEGIN_C_DECLS + _CRTIMP unsigned long __cdecl _beginthread (void (__cdecl *) (void *), unsigned, void *); _CRTIMP void __cdecl _endthread (void); @@ -797,9 +769,9 @@ extern "C" unsigned (__stdcall *) (void *), void *, unsigned, unsigned *); _CRTIMP void __cdecl _endthreadex (unsigned); -# if defined(__cplusplus) -} -# endif + +PTW32_END_C_DECLS + # endif #else # if ! defined(WINCE) @@ -841,14 +813,14 @@ extern "C" * The above aren't available in Mingw32 as of gcc 4.5.2 so define our own. */ #if defined(__cplusplus) -# define PTW32_TO_VLONG64PTR(ptr) reinterpret_cast(ptr) +# define PTW32_TO_VLONG64PTR(ptr) reinterpret_cast(ptr) #else -# define PTW32_TO_VLONG64PTR(ptr) (ptr) +# define PTW32_TO_VLONG64PTR(ptr) (ptr) #endif #if defined(__GNUC__) # if defined(_WIN64) -# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_64(location, value, comparand) \ +# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_64(location, value, comparand) \ ({ \ __typeof (value) _result; \ __asm__ __volatile__ \ @@ -860,7 +832,7 @@ extern "C" :"memory", "cc"); \ _result; \ }) -# define PTW32_INTERLOCKED_EXCHANGE_64(location, value) \ +# define PTW32_INTERLOCKED_EXCHANGE_64(location, value) \ ({ \ __typeof (value) _result; \ __asm__ __volatile__ \ @@ -871,7 +843,7 @@ extern "C" :"memory", "cc"); \ _result; \ }) -# define PTW32_INTERLOCKED_EXCHANGE_ADD_64(location, value) \ +# define PTW32_INTERLOCKED_EXCHANGE_ADD_64(location, value) \ ({ \ __typeof (value) _result; \ __asm__ __volatile__ \ @@ -883,9 +855,9 @@ extern "C" :"memory", "cc"); \ _result; \ }) -# define PTW32_INTERLOCKED_INCREMENT_64(location) \ +# define PTW32_INTERLOCKED_INCREMENT_64(location) \ ({ \ - PTW32_INTERLOCKED_LONG _temp = 1; \ + PTW32_INTERLOCKED_LONG _temp = 1; \ __asm__ __volatile__ \ ( \ "lock\n\t" \ @@ -895,9 +867,9 @@ extern "C" :"memory", "cc"); \ ++_temp; \ }) -# define PTW32_INTERLOCKED_DECREMENT_64(location) \ +# define PTW32_INTERLOCKED_DECREMENT_64(location) \ ({ \ - PTW32_INTERLOCKED_LONG _temp = -1; \ + PTW32_INTERLOCKED_LONG _temp = -1; \ __asm__ __volatile__ \ ( \ "lock\n\t" \ @@ -908,7 +880,7 @@ extern "C" --_temp; \ }) #endif -# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG(location, value, comparand) \ +# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG(location, value, comparand) \ ({ \ __typeof (value) _result; \ __asm__ __volatile__ \ @@ -920,7 +892,7 @@ extern "C" :"memory", "cc"); \ _result; \ }) -# define PTW32_INTERLOCKED_EXCHANGE_LONG(location, value) \ +# define PTW32_INTERLOCKED_EXCHANGE_LONG(location, value) \ ({ \ __typeof (value) _result; \ __asm__ __volatile__ \ @@ -931,7 +903,7 @@ extern "C" :"memory", "cc"); \ _result; \ }) -# define PTW32_INTERLOCKED_EXCHANGE_ADD_LONG(location, value) \ +# define PTW32_INTERLOCKED_EXCHANGE_ADD_LONG(location, value) \ ({ \ __typeof (value) _result; \ __asm__ __volatile__ \ @@ -943,9 +915,9 @@ extern "C" :"memory", "cc"); \ _result; \ }) -# define PTW32_INTERLOCKED_INCREMENT_LONG(location) \ +# define PTW32_INTERLOCKED_INCREMENT_LONG(location) \ ({ \ - PTW32_INTERLOCKED_LONG _temp = 1; \ + PTW32_INTERLOCKED_LONG _temp = 1; \ __asm__ __volatile__ \ ( \ "lock\n\t" \ @@ -955,9 +927,9 @@ extern "C" :"memory", "cc"); \ ++_temp; \ }) -# define PTW32_INTERLOCKED_DECREMENT_LONG(location) \ +# define PTW32_INTERLOCKED_DECREMENT_LONG(location) \ ({ \ - PTW32_INTERLOCKED_LONG _temp = -1; \ + PTW32_INTERLOCKED_LONG _temp = -1; \ __asm__ __volatile__ \ ( \ "lock\n\t" \ @@ -967,52 +939,52 @@ extern "C" :"memory", "cc"); \ --_temp; \ }) -# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_PTR(location, value, comparand) \ - PTW32_INTERLOCKED_COMPARE_EXCHANGE_SIZE((PTW32_INTERLOCKED_SIZEPTR)location, \ - (PTW32_INTERLOCKED_SIZE)value, \ - (PTW32_INTERLOCKED_SIZE)comparand) -# define PTW32_INTERLOCKED_EXCHANGE_PTR(location, value) \ - PTW32_INTERLOCKED_EXCHANGE_SIZE((PTW32_INTERLOCKED_SIZEPTR)location, \ - (PTW32_INTERLOCKED_SIZE)value) +# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_PTR(location, value, comparand) \ + PTW32_INTERLOCKED_COMPARE_EXCHANGE_SIZE ((PTW32_INTERLOCKED_SIZEPTR)location, \ + (PTW32_INTERLOCKED_SIZE)value, \ + (PTW32_INTERLOCKED_SIZE)comparand) +# define PTW32_INTERLOCKED_EXCHANGE_PTR(location, value) \ + PTW32_INTERLOCKED_EXCHANGE_SIZE ((PTW32_INTERLOCKED_SIZEPTR)location, \ + (PTW32_INTERLOCKED_SIZE)value) #else # if defined(_WIN64) -# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_64(p,v,c) InterlockedCompareExchange64(PTW32_TO_VLONG64PTR(p),(v),(c)) -# define PTW32_INTERLOCKED_EXCHANGE_64(p,v) InterlockedExchange64(PTW32_TO_VLONG64PTR(p),(v)) -# define PTW32_INTERLOCKED_EXCHANGE_ADD_64(p,v) InterlockedExchangeAdd64(PTW32_TO_VLONG64PTR(p),(v)) -# define PTW32_INTERLOCKED_INCREMENT_64(p) InterlockedIncrement64(PTW32_TO_VLONG64PTR(p)) -# define PTW32_INTERLOCKED_DECREMENT_64(p) InterlockedDecrement64(PTW32_TO_VLONG64PTR(p)) +# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_64(p,v,c) InterlockedCompareExchange64 (PTW32_TO_VLONG64PTR(p),(v),(c)) +# define PTW32_INTERLOCKED_EXCHANGE_64(p,v) InterlockedExchange64 (PTW32_TO_VLONG64PTR(p),(v)) +# define PTW32_INTERLOCKED_EXCHANGE_ADD_64(p,v) InterlockedExchangeAdd64 (PTW32_TO_VLONG64PTR(p),(v)) +# define PTW32_INTERLOCKED_INCREMENT_64(p) InterlockedIncrement64 (PTW32_TO_VLONG64PTR(p)) +# define PTW32_INTERLOCKED_DECREMENT_64(p) InterlockedDecrement64 (PTW32_TO_VLONG64PTR(p)) # endif -# if defined(PTW32_CONFIG_MSVC6) && !defined(_WIN64) -# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG(location, value, comparand) \ +# if defined (PTW32_CONFIG_MSVC6) && !defined(_WIN64) +# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG(location, value, comparand) \ ((LONG)InterlockedCompareExchange((PVOID *)(location), (PVOID)(value), (PVOID)(comparand))) # else -# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG InterlockedCompareExchange +# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG InterlockedCompareExchange # endif -# define PTW32_INTERLOCKED_EXCHANGE_LONG(p,v) InterlockedExchange((p),(v)) -# define PTW32_INTERLOCKED_EXCHANGE_ADD_LONG(p,v) InterlockedExchangeAdd((p),(v)) -# define PTW32_INTERLOCKED_INCREMENT_LONG(p) InterlockedIncrement((p)) -# define PTW32_INTERLOCKED_DECREMENT_LONG(p) InterlockedDecrement((p)) -# if defined(PTW32_CONFIG_MSVC6) && !defined(_WIN64) -# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_PTR InterlockedCompareExchange -# define PTW32_INTERLOCKED_EXCHANGE_PTR(location, value) \ +# define PTW32_INTERLOCKED_EXCHANGE_LONG(p,v) InterlockedExchange((p),(v)) +# define PTW32_INTERLOCKED_EXCHANGE_ADD_LONG(p,v) InterlockedExchangeAdd((p),(v)) +# define PTW32_INTERLOCKED_INCREMENT_LONG(p) InterlockedIncrement((p)) +# define PTW32_INTERLOCKED_DECREMENT_LONG(p) InterlockedDecrement((p)) +# if defined (PTW32_CONFIG_MSVC6) && !defined(_WIN64) +# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_PTR InterlockedCompareExchange +# define PTW32_INTERLOCKED_EXCHANGE_PTR(location, value) \ ((PVOID)InterlockedExchange((LPLONG)(location), (LONG)(value))) # else -# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_PTR(p,v,c) InterlockedCompareExchangePointer((p),(v),(c)) -# define PTW32_INTERLOCKED_EXCHANGE_PTR(p,v) InterlockedExchangePointer((p),(v)) +# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_PTR(p,v,c) InterlockedCompareExchangePointer((p),(v),(c)) +# define PTW32_INTERLOCKED_EXCHANGE_PTR(p,v) InterlockedExchangePointer((p),(v)) # endif #endif #if defined(_WIN64) -# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_SIZE(p,v,c) PTW32_INTERLOCKED_COMPARE_EXCHANGE_64(PTW32_TO_VLONG64PTR(p),(v),(c)) -# define PTW32_INTERLOCKED_EXCHANGE_SIZE(p,v) PTW32_INTERLOCKED_EXCHANGE_64(PTW32_TO_VLONG64PTR(p),(v)) -# define PTW32_INTERLOCKED_EXCHANGE_ADD_SIZE(p,v) PTW32_INTERLOCKED_EXCHANGE_ADD_64(PTW32_TO_VLONG64PTR(p),(v)) -# define PTW32_INTERLOCKED_INCREMENT_SIZE(p) PTW32_INTERLOCKED_INCREMENT_64(PTW32_TO_VLONG64PTR(p)) -# define PTW32_INTERLOCKED_DECREMENT_SIZE(p) PTW32_INTERLOCKED_DECREMENT_64(PTW32_TO_VLONG64PTR(p)) +# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_SIZE(p,v,c) PTW32_INTERLOCKED_COMPARE_EXCHANGE_64 (PTW32_TO_VLONG64PTR(p),(v),(c)) +# define PTW32_INTERLOCKED_EXCHANGE_SIZE(p,v) PTW32_INTERLOCKED_EXCHANGE_64 (PTW32_TO_VLONG64PTR(p),(v)) +# define PTW32_INTERLOCKED_EXCHANGE_ADD_SIZE(p,v) PTW32_INTERLOCKED_EXCHANGE_ADD_64 (PTW32_TO_VLONG64PTR(p),(v)) +# define PTW32_INTERLOCKED_INCREMENT_SIZE(p) PTW32_INTERLOCKED_INCREMENT_64 (PTW32_TO_VLONG64PTR(p)) +# define PTW32_INTERLOCKED_DECREMENT_SIZE(p) PTW32_INTERLOCKED_DECREMENT_64 (PTW32_TO_VLONG64PTR(p)) #else -# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_SIZE(p,v,c) PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG((p),(v),(c)) -# define PTW32_INTERLOCKED_EXCHANGE_SIZE(p,v) PTW32_INTERLOCKED_EXCHANGE_LONG((p),(v)) -# define PTW32_INTERLOCKED_EXCHANGE_ADD_SIZE(p,v) PTW32_INTERLOCKED_EXCHANGE_ADD_LONG((p),(v)) -# define PTW32_INTERLOCKED_INCREMENT_SIZE(p) PTW32_INTERLOCKED_INCREMENT_LONG((p)) -# define PTW32_INTERLOCKED_DECREMENT_SIZE(p) PTW32_INTERLOCKED_DECREMENT_LONG((p)) +# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_SIZE(p,v,c) PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG((p),(v),(c)) +# define PTW32_INTERLOCKED_EXCHANGE_SIZE(p,v) PTW32_INTERLOCKED_EXCHANGE_LONG((p),(v)) +# define PTW32_INTERLOCKED_EXCHANGE_ADD_SIZE(p,v) PTW32_INTERLOCKED_EXCHANGE_ADD_LONG((p),(v)) +# define PTW32_INTERLOCKED_INCREMENT_SIZE(p) PTW32_INTERLOCKED_INCREMENT_LONG((p)) +# define PTW32_INTERLOCKED_DECREMENT_SIZE(p) PTW32_INTERLOCKED_DECREMENT_LONG((p)) #endif #if defined(NEED_CREATETHREAD) diff --git a/install-sh b/install-sh new file mode 100644 index 00000000..e9de2384 --- /dev/null +++ b/install-sh @@ -0,0 +1,251 @@ +#!/bin/sh +# +# install - install a program, script, or datafile +# This comes from X11R5 (mit/util/scripts/install.sh). +# +# Copyright 1991 by the Massachusetts Institute of Technology +# +# Permission to use, copy, modify, distribute, and sell this software and its +# documentation for any purpose is hereby granted without fee, provided that +# the above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of M.I.T. not be used in advertising or +# publicity pertaining to distribution of the software without specific, +# written prior permission. M.I.T. makes no representations about the +# suitability of this software for any purpose. It is provided "as is" +# without express or implied warranty. +# +# Calling this script install-sh is preferred over install.sh, to prevent +# `make' implicit rules from creating a file called install from it +# when there is no Makefile. +# +# This script is compatible with the BSD install script, but was written +# from scratch. It can only install one file at a time, a restriction +# shared with many OS's install programs. + + +# set DOITPROG to echo to test this script + +# Don't use :- since 4.3BSD and earlier shells don't like it. +doit="${DOITPROG-}" + + +# put in absolute paths if you don't have them in your path; or use env. vars. + +mvprog="${MVPROG-mv}" +cpprog="${CPPROG-cp}" +chmodprog="${CHMODPROG-chmod}" +chownprog="${CHOWNPROG-chown}" +chgrpprog="${CHGRPPROG-chgrp}" +stripprog="${STRIPPROG-strip}" +rmprog="${RMPROG-rm}" +mkdirprog="${MKDIRPROG-mkdir}" + +transformbasename="" +transform_arg="" +instcmd="$mvprog" +chmodcmd="$chmodprog 0755" +chowncmd="" +chgrpcmd="" +stripcmd="" +rmcmd="$rmprog -f" +mvcmd="$mvprog" +src="" +dst="" +dir_arg="" + +while [ x"$1" != x ]; do + case $1 in + -c) instcmd="$cpprog" + shift + continue;; + + -d) dir_arg=true + shift + continue;; + + -m) chmodcmd="$chmodprog $2" + shift + shift + continue;; + + -o) chowncmd="$chownprog $2" + shift + shift + continue;; + + -g) chgrpcmd="$chgrpprog $2" + shift + shift + continue;; + + -s) stripcmd="$stripprog" + shift + continue;; + + -t=*) transformarg=`echo $1 | sed 's/-t=//'` + shift + continue;; + + -b=*) transformbasename=`echo $1 | sed 's/-b=//'` + shift + continue;; + + *) if [ x"$src" = x ] + then + src=$1 + else + # this colon is to work around a 386BSD /bin/sh bug + : + dst=$1 + fi + shift + continue;; + esac +done + +if [ x"$src" = x ] +then + echo "install: no input file specified" + exit 1 +else + true +fi + +if [ x"$dir_arg" != x ]; then + dst=$src + src="" + + if [ -d $dst ]; then + instcmd=: + chmodcmd="" + else + instcmd=mkdir + fi +else + +# Waiting for this to be detected by the "$instcmd $src $dsttmp" command +# might cause directories to be created, which would be especially bad +# if $src (and thus $dsttmp) contains '*'. + + if [ -f $src -o -d $src ] + then + true + else + echo "install: $src does not exist" + exit 1 + fi + + if [ x"$dst" = x ] + then + echo "install: no destination specified" + exit 1 + else + true + fi + +# If destination is a directory, append the input filename; if your system +# does not like double slashes in filenames, you may need to add some logic + + if [ -d $dst ] + then + dst="$dst"/`basename $src` + else + true + fi +fi + +## this sed command emulates the dirname command +dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` + +# Make sure that the destination directory exists. +# this part is taken from Noah Friedman's mkinstalldirs script + +# Skip lots of stat calls in the usual case. +if [ ! -d "$dstdir" ]; then +defaultIFS=' +' +IFS="${IFS-${defaultIFS}}" + +oIFS="${IFS}" +# Some sh's can't handle IFS=/ for some reason. +IFS='%' +set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` +IFS="${oIFS}" + +pathcomp='' + +while [ $# -ne 0 ] ; do + pathcomp="${pathcomp}${1}" + shift + + if [ ! -d "${pathcomp}" ] ; + then + $mkdirprog "${pathcomp}" + else + true + fi + + pathcomp="${pathcomp}/" +done +fi + +if [ x"$dir_arg" != x ] +then + $doit $instcmd $dst && + + if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && + if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && + if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && + if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi +else + +# If we're going to rename the final executable, determine the name now. + + if [ x"$transformarg" = x ] + then + dstfile=`basename $dst` + else + dstfile=`basename $dst $transformbasename | + sed $transformarg`$transformbasename + fi + +# don't allow the sed command to completely eliminate the filename + + if [ x"$dstfile" = x ] + then + dstfile=`basename $dst` + else + true + fi + +# Make a temp file name in the proper directory. + + dsttmp=$dstdir/#inst.$$# + +# Move or copy the file name to the temp name + + $doit $instcmd $src $dsttmp && + + trap "rm -f ${dsttmp}" 0 && + +# and set any options; do chmod last to preserve setuid bits + +# If any of these fail, we abort the whole thing. If we want to +# ignore errors from any of these, just make sure not to ignore +# errors from the above "$doit $instcmd $src $dsttmp" command. + + if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && + if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && + if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && + if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && + +# Now rename the file to the real destination. + + $doit $rmcmd -f $dstdir/$dstfile && + $doit $mvcmd $dsttmp $dstdir/$dstfile + +fi && + + +exit 0 diff --git a/manual/ChangeLog b/manual/ChangeLog index d225fc32..f9864494 100644 --- a/manual/ChangeLog +++ b/manual/ChangeLog @@ -1,3 +1,9 @@ +2016-12-25 Ross Johnson + + * Change all references to "pthreads-win32" etc. to "pthreads-win32" + * Change all references to the sourceware projects web page to the + SourceForge project web page. + 2015-02-03 Ross Johnson * *.html: Fix HEAD section inconsistencies and remove editor meta tags. diff --git a/manual/PortabilityIssues.html b/manual/PortabilityIssues.html index 03d58068..92c00c1e 100644 --- a/manual/PortabilityIssues.html +++ b/manual/PortabilityIssues.html @@ -1,18 +1,31 @@ - + PORTABILITY ISSUES manual page + + + + + -

POSIX Threads for Windows – REFERENCE - pthreads-win32

+

POSIX Threads for Windows – REFERENCE – +pthreads-win32

Reference Index

-

Table of Contents

-

Name

-

Portability issues

-

Synopsis

+

Table of Contents

+

Name

+

Portability issues

+

Synopsis

Thread priority

-

Description

+

Description

Thread priority

POSIX defines a single contiguous range of numbers that determine a thread's priority. Win32 defines priority @@ -690,9 +703,9 @@

Thread priority

If it wishes, a Win32 application using pthreads-win32 can use the Win32 defined priority macros THREAD_PRIORITY_IDLE through THREAD_PRIORITY_TIME_CRITICAL.

-

Author

+

Author

Ross Johnson for use with pthreads-win32.

-

See also

+

See also




diff --git a/manual/index.html b/manual/index.html index 315df9ed..2be20621 100644 --- a/manual/index.html +++ b/manual/index.html @@ -3,9 +3,10 @@ - + - + + -

POSIX Threads for Windows – REFERENCE - pthreads-win32

+

POSIX Threads for Windows – REFERENCE – +pthreads-win32

Reference Index

Table of Contents

-

Name

-

pthreadCancelableTimedWait, -pthreadCancelableWait – provide cancellation hooks for user Win32 -routines

-

Synopsis

+

Name

+

pthreadCancelableTimedWait, +pthreadCancelableWait – provide cancellation hooks for user +Win32 routines

+

Synopsis

#include <pthread.h>

int pthreadCancelableTimedWait (HANDLE waitHandle, DWORD timeout);

int pthreadCancelableWait (HANDLE waitHandle);

-

Description

+

Description

These two functions provide hooks into the pthread_cancel() mechanism that will allow you to wait on a Windows handle and make it a cancellation point. Both functions block until either the given @@ -33,13 +46,13 @@

Description

pthreadCancelableTimedWait is the timed version that will return with the code ETIMEDOUT if the interval timeout milliseconds elapses before waitHandle is signalled.

-

Cancellation

+

Cancellation

These routines allow routines that block on Win32 HANDLEs to be cancellable via pthread_cancel().

-

Return Value

+

Return Value



-

Errors

+

Errors

The pthreadCancelableTimedWait function returns the following error code on error:

@@ -50,9 +63,9 @@

Errors

The interval timeout milliseconds elapsed before waitHandle was signalled.

-

Author

+

Author

Ross Johnson for use with pthreads-win32.

-

See also

+

See also

pthread_cancel(), pthread_self()


@@ -66,8 +79,8 @@

See also

  • Cancellation

    -
  • Return - Value +

  • Return + Value

  • Errors

    diff --git a/manual/pthread_attr_init.html b/manual/pthread_attr_init.html index 31eb1fc4..c3a3ed65 100644 --- a/manual/pthread_attr_init.html +++ b/manual/pthread_attr_init.html @@ -3,19 +3,23 @@ PTHREAD_ATTR_INIT(3) manual page + + + + -

    POSIX Threads for Windows – REFERENCE - +

    POSIX Threads for Windows – REFERENCE – pthreads-win32

    Reference Index

    Table of Contents

    @@ -37,16 +41,14 @@

    Synopsis

    int pthread_attr_destroy(pthread_attr_t *attr);

    int pthread_attr_setaffinity_np(pthread_attr_t *attr, -size_t cpusetsize, -cpu_set_t -* -cpuset); +size_t cpusetsize, +cpu_set_t * +cpuset);

    int pthread_attr_getaffinity_np(const pthread_attr_t *attr, -size_t cpusetsize, -cpu_set_t -* -cpuset); +size_t cpusetsize, +cpu_set_t * +cpuset);

    int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate); @@ -54,12 +56,12 @@

    Synopsis

    int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate);

    -

    int pthread_attr_setname_np(const -pthread_attr_t *attr, const char * name, -void * arg);

    -

    int pthread_attr_getname_np(const pthread_attr_t -*attr, char * name, -int len);

    +

    int pthread_attr_setname_np(const pthread_attr_t *attr, +const char * name, +void * arg);

    +

    int pthread_attr_getname_np(const pthread_attr_t *attr, +char * name, +int len);

    int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy);

    diff --git a/manual/pthread_attr_setstackaddr.html b/manual/pthread_attr_setstackaddr.html index 446c89c9..5bbaed6a 100644 --- a/manual/pthread_attr_setstackaddr.html +++ b/manual/pthread_attr_setstackaddr.html @@ -3,6 +3,10 @@ PTHREAD_ATTR_SETSTACKADDR(3) manual page + + + + -

    POSIX Threads for Windows – REFERENCE - +

    POSIX Threads for Windows – REFERENCE – pthreads-win32

    Reference Index

    Table of Contents

    diff --git a/manual/pthread_create.html b/manual/pthread_create.html index a1fd7c02..ba7b85d6 100644 --- a/manual/pthread_create.html +++ b/manual/pthread_create.html @@ -3,6 +3,10 @@ PTHREAD_CREATE(3) manual page + + + + + + +

    Table of Contents

    +

    Name

    +

    pthread_equal - compare two thread identifiers +

    +

    Synopsis

    +

    #include <pthread.h> +

    +

    int pthread_equal(pthread_t thread1, +pthread_t thread2); +

    +

    Description

    +

    pthread_equal determines if two thread +identifiers refer to the same thread. +

    +

    Return +Value

    +

    A non-zero value is returned if thread1 and +thread2 refer to the same thread. Otherwise, 0 is returned. +

    +

    Author

    +

    Xavier Leroy <Xavier.Leroy@inria.fr> +

    +

    See +Also

    +

    pthread_self(3) +. +

    +
    +

    Table of Contents

    + + + \ No newline at end of file diff --git a/manual/pthread_exit.html b/manual/pthread_exit.html index 8174460d..715bf610 100644 --- a/manual/pthread_exit.html +++ b/manual/pthread_exit.html @@ -1,56 +1,71 @@ - - -PTHREAD_EXIT(3) manual page - - -Table of Contents

    - -

    -

    Name

    -pthread_exit - terminate the calling thread -

    -

    Synopsis

    -#include <pthread.h> - -

    void pthread_exit(void *retval); -

    -

    Description

    -pthread_exit terminates the -execution of the calling thread. All cleanup handlers that have been set -for the calling thread with pthread_cleanup_push(3) - are executed in reverse -order (the most recently pushed handler is executed first). Finalization -functions for thread-specific data are then called for all keys that have -non- NULL values associated with them in the calling thread (see pthread_key_create(3) -). -Finally, execution of the calling thread is stopped. -

    The retval argument -is the return value of the thread. It can be consulted from another thread -using pthread_join(3) + + + + + PTHREAD_EXIT(3) manual page + + + + + + + +

    Table of Contents

    +

    Name

    +

    pthread_exit - terminate the calling thread +

    +

    Synopsis

    +

    #include <pthread.h> +

    +

    void pthread_exit(void *retval); +

    +

    Description

    +

    pthread_exit terminates the execution of the +calling thread. All cleanup handlers that have been set for the +calling thread with pthread_cleanup_push(3) +are executed in reverse order (the most recently pushed handler is +executed first). Finalization functions for thread-specific data are +then called for all keys that have non- NULL values associated +with them in the calling thread (see pthread_key_create(3) +). Finally, execution of the calling thread is stopped. +

    +

    The retval argument is the return value of the +thread. It can be consulted from another thread using pthread_join(3) . -

    -

    Return Value

    -The pthread_exit function never returns. - -

    -

    Author

    -Xavier Leroy <Xavier.Leroy@inria.fr> -

    -

    See Also

    -pthread_create(3) -, pthread_join(3) -. -

    - -


    -Table of Contents

    -

    - - +

    +

    Return +Value

    +

    The pthread_exit function never returns. +

    +

    Author

    +

    Xavier Leroy <Xavier.Leroy@inria.fr> +

    +

    See +Also

    +

    pthread_create(3) +, pthread_join(3) . +

    +
    +

    Table of Contents

    + + + \ No newline at end of file diff --git a/manual/pthread_setname_np.html b/manual/pthread_setname_np.html index 1f2eff90..e3fce25d 100644 --- a/manual/pthread_setname_np.html +++ b/manual/pthread_setname_np.html @@ -35,8 +35,8 @@

    thr, char * name, int len);

    -

    #if defined(PTW32_COMPATIBILITY_BSD) || -defined(PTW32_COMPATIBILITY_TRU64)
    int +

    #if defined (PTW32_COMPATIBILITY_BSD) || +defined (PTW32_COMPATIBILITY_TRU64)
    int pthread_setname_np(pthread_t thr, const char * name, void * arg);

    @@ -47,7 +47,7 @@

    Description

    pthread_setname_np() sets the descriptive name of the thread. It takes the following arguments.

    -

    #if defined(PTW32_COMPATIBILITY_BSD)

    +

    #if defined (PTW32_COMPATIBILITY_BSD)

    @@ -78,7 +78,7 @@

    Description

    -

    #elif defined(PTW32_COMPATIBILITY_TRU64)

    +

    #elif defined (PTW32_COMPATIBILITY_TRU64)

    diff --git a/manual/pthread_win32_getabstime_np.html b/manual/pthread_win32_getabstime_np.html index 7e4e060f..498184a8 100644 --- a/manual/pthread_win32_getabstime_np.html +++ b/manual/pthread_win32_getabstime_np.html @@ -18,7 +18,7 @@

    POSIX Threads for Windows – REFERENCE - -Pthreads4W

    +pthreads-win32

    Reference Index

    Table of Contents

    Name

    @@ -47,7 +47,7 @@

    Return

    Errors

    None.

    Author

    -

    Ross Johnson for use with Pthreads4W.

    +

    Ross Johnson for use with pthreads-win32.


    Table of Contents

      diff --git a/need_errno.h b/need_errno.h index 96ade072..544016cf 100644 --- a/need_errno.h +++ b/need_errno.h @@ -64,12 +64,12 @@ extern "C" { # define PTW32_STATIC_TLSLIB #endif -#if defined(PTW32_STATIC_LIB) || defined(PTW32_STATIC_TLSLIB) -# define PTW32_DLLPORT -#elif defined(PTW32_BUILD) -# define PTW32_DLLPORT __declspec (dllexport) +#if defined (PTW32_STATIC_LIB) || defined (PTW32_STATIC_TLSLIB) +# define PTW32_DLLPORT +#elif defined (PTW32_BUILD) +# define PTW32_DLLPORT __declspec (dllexport) # else -# define PTW32_DLLPORT __declspec (dllimport) +# define PTW32_DLLPORT __declspec (dllimport) # endif /* declare reference to errno */ @@ -139,8 +139,21 @@ _CRTIMP extern int errno; /* * POSIX 2008 - robust mutexes. */ -#define EOWNERDEAD 43 -#define ENOTRECOVERABLE 44 +#if PTW32_VERSION_MAJOR > 2 +# if !defined(EOWNERDEAD) +# define EOWNERDEAD 1000 +# endif +# if !defined(ENOTRECOVERABLE) +# define ENOTRECOVERABLE 1001 +# endif +#else +# if !defined(EOWNERDEAD) +# define EOWNERDEAD 43 +# endif +# if !defined(ENOTRECOVERABLE) +# define ENOTRECOVERABLE 44 +# endif +#endif /* * Support EDEADLOCK for compatibility with older MS-C versions. diff --git a/pthread.c b/pthread.c index 12823612..13822a88 100644 --- a/pthread.c +++ b/pthread.c @@ -20,17 +20,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/pthread.h b/pthread.h index 0ae2863a..1988a601 100644 --- a/pthread.h +++ b/pthread.h @@ -1,11 +1,3 @@ -/* - * This is a fork of version 2.10.0.0 the pthreads-win32 package. The ABI of this - * fork is different from the original. Changes done: - * 1) The type of the reuse counter in ptw32_handle_t has been changed from - * int to size_t in order to facilitate long-running servers. - * 2) Removed unused elements from pthread_once_t - */ - /* This is an implementation of the threads API of the Single Unix Specification. * * -------------------------------------------------------------------------- @@ -22,17 +14,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., @@ -44,13 +36,6 @@ #if !defined( PTHREAD_H ) #define PTHREAD_H -/* - * See the README file for an explanation of the pthreads-win32 version - * numbering scheme and how the DLL is named etc. - */ -#define PTW32_VERSION 2,10,2,0 -#define PTW32_VERSION_STRING "2, 10, 2, 0\0" - /* There are three implementations of cancel cleanup. * Note that pthread.h is included in both application * compilation units and also internally for the library. @@ -81,70 +66,57 @@ * C++ apps). This is currently consistent with most/all commercial Unix * POSIX threads implementations. */ -#if !defined( __CLEANUP_SEH ) && !defined( __CLEANUP_CXX ) && !defined( __CLEANUP_C ) +#if !defined( PTW32_CLEANUP_SEH ) && !defined( PTW32_CLEANUP_CXX ) && !defined( PTW32_CLEANUP_C ) /* - [i_a] fix for apps using pthreads-Win32: when they do not define __CLEANUP_SEH themselves, - they're screwed as they'll receive the '__CLEANUP_C' macros which do NOT work when - the pthreads library code itself has actually been build with __CLEANUP_SEH, + [i_a] fix for apps using pthreads-Win32: when they do not define PTW32_CLEANUP_SEH themselves, + they're screwed as they'll receive the 'PTW32_CLEANUP_C' macros which do NOT work when + the pthreads library code itself has actually been build with PTW32_CLEANUP_SEH, which is the case when building this stuff in MSVC. Hence this section is made to 'sensibly autodetect' the cleanup mode, when it hasn't been hardwired in the makefiles / project files. - After all, who expects he MUST define one of these __CLEANUP_XXX defines in his own + After all, who expects he MUST define one of these PTW32_CLEANUP_XXX defines in his own code when using pthreads-Win32, for whatever reason. */ #if (defined(_MSC_VER) || defined(PTW32_RC_MSC)) -#define __CLEANUP_SEH +#define PTW32_CLEANUP_SEH #elif defined(__cplusplus) -#define __CLEANUP_CXX +#define PTW32_CLEANUP_CXX #else -#define __CLEANUP_C +# define PTW32_CLEANUP_C #endif #endif -#if defined( __CLEANUP_SEH ) && ( !defined( _MSC_VER ) && !defined(PTW32_RC_MSC)) +#if defined( PTW32_CLEANUP_SEH ) && ( !defined( _MSC_VER ) && !defined (PTW32_RC_MSC)) #error ERROR [__FILE__, line __LINE__]: SEH is not supported for this compiler. #endif +#include <_ptw32.h> + /* * Stop here if we are being included by the resource compiler. */ #if !defined(RC_INVOKED) -#undef PTW32_LEVEL - -#if defined(_POSIX_SOURCE) -#define PTW32_LEVEL 0 /* Early POSIX */ -#endif +#undef PTW32_LEVEL +#undef PTW32_LEVEL_MAX +#define PTW32_LEVEL_MAX 3 -#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309 -#undef PTW32_LEVEL -#define PTW32_LEVEL 1 /* Include 1b, 1c and 1d */ -#endif +#if _POSIX_C_SOURCE >= 200112L /* POSIX.1-2001 and later */ +# define PTW32_LEVEL PTW32_LEVEL_MAX /* include everything */ -#if defined(INCLUDE_NP) -#undef PTW32_LEVEL -#define PTW32_LEVEL 2 /* Include Non-Portable extensions */ -#endif +#elif defined INCLUDE_NP /* earlier than POSIX.1-2001, but... */ +# define PTW32_LEVEL 2 /* include non-portable extensions */ -#define PTW32_LEVEL_MAX 3 +#elif _POSIX_C_SOURCE >= 199309L /* POSIX.1-1993 */ +# define PTW32_LEVEL 1 /* include 1b, 1c, and 1d */ -#if ( defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112 ) || !defined(PTW32_LEVEL) -#undef PTW32_LEVEL -#define PTW32_LEVEL PTW32_LEVEL_MAX /* Include everything */ -#endif +#elif defined _POSIX_SOURCE /* early POSIX */ +# define PTW32_LEVEL 0 /* minimal support */ -#if defined(__MINGW32__) || defined(__MINGW64__) -# define PTW32_CONFIG_MINGW -#endif -#if defined(_MSC_VER) -# if _MSC_VER < 1300 -# define PTW32_CONFIG_MSVC6 -# endif -# if _MSC_VER < 1400 -# define PTW32_CONFIG_MSVC7 -# endif +#else /* unspecified support level */ +# define PTW32_LEVEL PTW32_LEVEL_MAX /* include everything anyway */ #endif /* @@ -215,117 +187,19 @@ * The source code and other information about this library * are available from * - * http://sources.redhat.com/pthreads-win32/ + * http://sources.redhat.com/pthreads-win32 * * ------------------------------------------------------------- */ - -/* Try to avoid including windows.h */ -#if defined(PTW32_CONFIG_MINGW) && defined(__cplusplus) -#define PTW32_INCLUDE_WINDOWS_H -#endif - -#if defined(PTW32_INCLUDE_WINDOWS_H) -#include -#endif - -/* - * Boolean values to make us independent of system includes. - */ -enum { - PTW32_FALSE = 0, - PTW32_TRUE = (! PTW32_FALSE) +enum +{ /* Boolean values to make us independent of system includes. */ + PTW32_FALSE = 0, + PTW32_TRUE = (! PTW32_FALSE) }; -/* - * This is a duplicate of what is in the autoconf config.h, - * which is only used when building the pthread-win32 libraries. - */ - -#if !defined(PTW32_CONFIG_H) -# if defined(WINCE) -# define NEED_ERRNO -# define NEED_SEM -# elif defined(_UWIN) -# define HAVE_MODE_T -# define HAVE_STRUCT_TIMESPEC -# define HAVE_SIGNAL_H -# elif defined(__MINGW64__) -# define HAVE_STRUCT_TIMESPEC -# define HAVE_MODE_T -# elif defined(__MINGW32__) -# define HAVE_MODE_T -# endif -#endif - -#if !defined(NEED_FTIME) #include -#else /* NEED_FTIME */ -/* use native WIN32 time API */ -#endif /* NEED_FTIME */ - -#if defined(HAVE_SIGNAL_H) -#include -#endif - -#include - -#if PTW32_LEVEL >= PTW32_LEVEL_MAX -#if defined(NEED_ERRNO) -#include "need_errno.h" -#else -#include -#endif -#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */ - #include "sched.h" -/* - * Several systems don't define some error numbers. - */ -#if !defined(ENOTSUP) -# define ENOTSUP 48 /* This is the value in Solaris. */ -#endif - -#if !defined(ETIMEDOUT) -# define ETIMEDOUT 10060 /* Same as WSAETIMEDOUT */ -#endif - -#if !defined(ENOSYS) -# define ENOSYS 140 /* Semi-arbitrary value */ -#endif - -#if !defined(EDEADLK) -# if defined(EDEADLOCK) -# define EDEADLK EDEADLOCK -# else -# define EDEADLK 36 /* This is the value in MSVC. */ -# endif -#endif - -/* POSIX 2008 - related to robust mutexes */ -#if !defined(EOWNERDEAD) -# define EOWNERDEAD 43 -#endif -#if !defined(ENOTRECOVERABLE) -# define ENOTRECOVERABLE 44 -#endif - -/* - * To avoid including windows.h we define only those things that we - * actually need from it. - */ -#if !defined(PTW32_INCLUDE_WINDOWS_H) -#if !defined(HANDLE) -# define PTW32__HANDLE_DEF -# define HANDLE void * -#endif -#if !defined(DWORD) -# define PTW32__DWORD_DEF -# define DWORD unsigned long -#endif -#endif - #if defined(_MSC_VER) && _MSC_VER >= 1900 # define HAVE_STRUCT_TIMESPEC # ifndef _TIMESPEC_DEFINED @@ -333,34 +207,6 @@ enum { # endif #endif -#if !defined(HAVE_STRUCT_TIMESPEC) -#define HAVE_STRUCT_TIMESPEC -#if !defined(_TIMESPEC_DEFINED) -#define _TIMESPEC_DEFINED -struct timespec { - time_t tv_sec; - long tv_nsec; -}; -#endif /* _TIMESPEC_DEFINED */ -#endif /* HAVE_STRUCT_TIMESPEC */ - -#if !defined(SIG_BLOCK) -#define SIG_BLOCK 0 -#endif /* SIG_BLOCK */ - -#if !defined(SIG_UNBLOCK) -#define SIG_UNBLOCK 1 -#endif /* SIG_UNBLOCK */ - -#if !defined(SIG_SETMASK) -#define SIG_SETMASK 2 -#endif /* SIG_SETMASK */ - -#if defined(__cplusplus) -extern "C" -{ -#endif /* __cplusplus */ - /* * ------------------------------------------------------------- * @@ -562,29 +408,6 @@ extern "C" #define SEM_VALUE_MAX INT_MAX -#if defined(__GNUC__) && !defined(__declspec) -# error Please upgrade your GNU compiler to one that supports __declspec. -#endif - -#if defined(PTW32_STATIC_LIB) && defined(_MSC_VER) && _MSC_VER >= 1400 && defined(_WINDLL) -# undef PTW32_STATIC_LIB -# define PTW32_STATIC_TLSLIB -#endif - -/* - * When building the library, you should define PTW32_BUILD so that - * the variables/functions are exported correctly. When using the library, - * do NOT define PTW32_BUILD, and then the variables/functions will - * be imported correctly. - */ -#if defined(PTW32_STATIC_LIB) || defined(PTW32_STATIC_TLSLIB) -# define PTW32_DLLPORT -#elif defined(PTW32_BUILD) -# define PTW32_DLLPORT __declspec (dllexport) -# else -# define PTW32_DLLPORT __declspec (dllimport) -# endif - #if defined(_UWIN) && PTW32_LEVEL >= PTW32_LEVEL_MAX # include #else @@ -604,8 +427,8 @@ extern "C" */ typedef struct { - void * p; /* Pointer to actual object */ - size_t x; /* Extra information - reuse count etc */ + void * p; /* Pointer to actual object */ + size_t x; /* Extra information - reuse count etc */ } ptw32_handle_t; typedef ptw32_handle_t pthread_t; @@ -634,52 +457,45 @@ typedef struct pthread_barrierattr_t_ * pthread_barrierattr_t; enum { -/* - * pthread_attr_{get,set}detachstate - */ + /* + * pthread_attr_{get,set}detachstate + */ PTHREAD_CREATE_JOINABLE = 0, /* Default */ PTHREAD_CREATE_DETACHED = 1, - -/* - * pthread_attr_{get,set}inheritsched - */ + /* + * pthread_attr_{get,set}inheritsched + */ PTHREAD_INHERIT_SCHED = 0, PTHREAD_EXPLICIT_SCHED = 1, /* Default */ - -/* - * pthread_{get,set}scope - */ + /* + * pthread_{get,set}scope + */ PTHREAD_SCOPE_PROCESS = 0, PTHREAD_SCOPE_SYSTEM = 1, /* Default */ - -/* - * pthread_setcancelstate paramters - */ + /* + * pthread_setcancelstate paramters + */ PTHREAD_CANCEL_ENABLE = 0, /* Default */ PTHREAD_CANCEL_DISABLE = 1, - -/* - * pthread_setcanceltype parameters - */ + /* + * pthread_setcanceltype parameters + */ PTHREAD_CANCEL_ASYNCHRONOUS = 0, PTHREAD_CANCEL_DEFERRED = 1, /* Default */ - -/* - * pthread_mutexattr_{get,set}pshared - * pthread_condattr_{get,set}pshared - */ + /* + * pthread_mutexattr_{get,set}pshared + * pthread_condattr_{get,set}pshared + */ PTHREAD_PROCESS_PRIVATE = 0, PTHREAD_PROCESS_SHARED = 1, - -/* - * pthread_mutexattr_{get,set}robust - */ + /* + * pthread_mutexattr_{get,set}robust + */ PTHREAD_MUTEX_STALLED = 0, /* Default */ PTHREAD_MUTEX_ROBUST = 1, - -/* - * pthread_barrier_wait - */ + /* + * pthread_barrier_wait + */ PTHREAD_BARRIER_SERIAL_THREAD = -1 }; @@ -700,14 +516,28 @@ enum * ==================== * ==================== */ +#if PTW32_VERSION_MAJOR > 2 + +#define PTHREAD_ONCE_INIT { 0, PTW32_FALSE } + +struct pthread_once_t_ +{ + void * lock; /* MCS lock */ + int done; /* indicates if user function has been executed */ +}; + +#else + #define PTHREAD_ONCE_INIT { PTW32_FALSE, 0 } struct pthread_once_t_ { - int done; /* indicates if user function has been executed */ - void * lock; + int done; /* indicates if user function has been executed */ + void * lock; /* MCS lock */ }; +#endif + /* * ==================== @@ -773,7 +603,7 @@ struct ptw32_cleanup_t struct ptw32_cleanup_t *prev; }; -#if defined(__CLEANUP_SEH) +#if defined(PTW32_CLEANUP_SEH) /* * WIN32 SEH version of cancel cleanup. */ @@ -806,9 +636,9 @@ struct ptw32_cleanup_t } \ } -#else /* __CLEANUP_SEH */ +#else /* PTW32_CLEANUP_SEH */ -#if defined(__CLEANUP_C) +#if defined(PTW32_CLEANUP_C) /* * C implementation of PThreads cancel cleanup @@ -824,9 +654,9 @@ struct ptw32_cleanup_t (void) ptw32_pop_cleanup( _execute ); \ } -#else /* __CLEANUP_C */ +#else /* PTW32_CLEANUP_C */ -#if defined(__CLEANUP_CXX) +#if defined(PTW32_CLEANUP_CXX) /* * C++ version of cancel cleanup. @@ -906,11 +736,12 @@ struct ptw32_cleanup_t #error ERROR [__FILE__, line __LINE__]: Cleanup type undefined. -#endif /* __CLEANUP_CXX */ +#endif /* PTW32_CLEANUP_CXX */ -#endif /* __CLEANUP_C */ +#endif /* PTW32_CLEANUP_C */ + +#endif /* PTW32_CLEANUP_SEH */ -#endif /* __CLEANUP_SEH */ /* * =============== @@ -920,100 +751,102 @@ struct ptw32_cleanup_t * =============== */ +PTW32_BEGIN_C_DECLS + /* * PThread Attribute Functions */ -PTW32_DLLPORT int PTW32_CDECL pthread_attr_init (pthread_attr_t * attr); +PTW32_DLLPORT int PTW32_CDECL pthread_attr_init (pthread_attr_t * attr); -PTW32_DLLPORT int PTW32_CDECL pthread_attr_destroy (pthread_attr_t * attr); +PTW32_DLLPORT int PTW32_CDECL pthread_attr_destroy (pthread_attr_t * attr); -PTW32_DLLPORT int PTW32_CDECL pthread_attr_getaffinity_np (const pthread_attr_t * attr, +PTW32_DLLPORT int PTW32_CDECL pthread_attr_getaffinity_np (const pthread_attr_t * attr, size_t cpusetsize, cpu_set_t * cpuset); -PTW32_DLLPORT int PTW32_CDECL pthread_attr_getdetachstate (const pthread_attr_t * attr, +PTW32_DLLPORT int PTW32_CDECL pthread_attr_getdetachstate (const pthread_attr_t * attr, int *detachstate); -PTW32_DLLPORT int PTW32_CDECL pthread_attr_getstackaddr (const pthread_attr_t * attr, +PTW32_DLLPORT int PTW32_CDECL pthread_attr_getstackaddr (const pthread_attr_t * attr, void **stackaddr); -PTW32_DLLPORT int PTW32_CDECL pthread_attr_getstacksize (const pthread_attr_t * attr, +PTW32_DLLPORT int PTW32_CDECL pthread_attr_getstacksize (const pthread_attr_t * attr, size_t * stacksize); -PTW32_DLLPORT int PTW32_CDECL pthread_attr_setaffinity_np (pthread_attr_t * attr, +PTW32_DLLPORT int PTW32_CDECL pthread_attr_setaffinity_np (pthread_attr_t * attr, size_t cpusetsize, const cpu_set_t * cpuset); -PTW32_DLLPORT int PTW32_CDECL pthread_attr_setdetachstate (pthread_attr_t * attr, +PTW32_DLLPORT int PTW32_CDECL pthread_attr_setdetachstate (pthread_attr_t * attr, int detachstate); -PTW32_DLLPORT int PTW32_CDECL pthread_attr_setstackaddr (pthread_attr_t * attr, +PTW32_DLLPORT int PTW32_CDECL pthread_attr_setstackaddr (pthread_attr_t * attr, void *stackaddr); -PTW32_DLLPORT int PTW32_CDECL pthread_attr_setstacksize (pthread_attr_t * attr, +PTW32_DLLPORT int PTW32_CDECL pthread_attr_setstacksize (pthread_attr_t * attr, size_t stacksize); -PTW32_DLLPORT int PTW32_CDECL pthread_attr_getschedparam (const pthread_attr_t *attr, +PTW32_DLLPORT int PTW32_CDECL pthread_attr_getschedparam (const pthread_attr_t *attr, struct sched_param *param); -PTW32_DLLPORT int PTW32_CDECL pthread_attr_setschedparam (pthread_attr_t *attr, +PTW32_DLLPORT int PTW32_CDECL pthread_attr_setschedparam (pthread_attr_t *attr, const struct sched_param *param); -PTW32_DLLPORT int PTW32_CDECL pthread_attr_setschedpolicy (pthread_attr_t *, +PTW32_DLLPORT int PTW32_CDECL pthread_attr_setschedpolicy (pthread_attr_t *, int); -PTW32_DLLPORT int PTW32_CDECL pthread_attr_getschedpolicy (const pthread_attr_t *, +PTW32_DLLPORT int PTW32_CDECL pthread_attr_getschedpolicy (const pthread_attr_t *, int *); -PTW32_DLLPORT int PTW32_CDECL pthread_attr_setinheritsched(pthread_attr_t * attr, +PTW32_DLLPORT int PTW32_CDECL pthread_attr_setinheritsched(pthread_attr_t * attr, int inheritsched); -PTW32_DLLPORT int PTW32_CDECL pthread_attr_getinheritsched(const pthread_attr_t * attr, +PTW32_DLLPORT int PTW32_CDECL pthread_attr_getinheritsched(const pthread_attr_t * attr, int * inheritsched); -PTW32_DLLPORT int PTW32_CDECL pthread_attr_setscope (pthread_attr_t *, +PTW32_DLLPORT int PTW32_CDECL pthread_attr_setscope (pthread_attr_t *, int); -PTW32_DLLPORT int PTW32_CDECL pthread_attr_getscope (const pthread_attr_t *, +PTW32_DLLPORT int PTW32_CDECL pthread_attr_getscope (const pthread_attr_t *, int *); /* * PThread Functions */ -PTW32_DLLPORT int PTW32_CDECL pthread_create (pthread_t * tid, +PTW32_DLLPORT int PTW32_CDECL pthread_create (pthread_t * tid, const pthread_attr_t * attr, - void *(PTW32_CDECL *start) (void *), + void * (PTW32_CDECL *start) (void *), void *arg); -PTW32_DLLPORT int PTW32_CDECL pthread_detach (pthread_t tid); +PTW32_DLLPORT int PTW32_CDECL pthread_detach (pthread_t tid); -PTW32_DLLPORT int PTW32_CDECL pthread_equal (pthread_t t1, +PTW32_DLLPORT int PTW32_CDECL pthread_equal (pthread_t t1, pthread_t t2); -PTW32_DLLPORT void PTW32_CDECL pthread_exit (void *value_ptr); +PTW32_DLLPORT void PTW32_CDECL pthread_exit (void *value_ptr); -PTW32_DLLPORT int PTW32_CDECL pthread_join (pthread_t thread, +PTW32_DLLPORT int PTW32_CDECL pthread_join (pthread_t thread, void **value_ptr); -PTW32_DLLPORT pthread_t PTW32_CDECL pthread_self (void); +PTW32_DLLPORT pthread_t PTW32_CDECL pthread_self (void); -PTW32_DLLPORT int PTW32_CDECL pthread_cancel (pthread_t thread); +PTW32_DLLPORT int PTW32_CDECL pthread_cancel (pthread_t thread); -PTW32_DLLPORT int PTW32_CDECL pthread_setcancelstate (int state, +PTW32_DLLPORT int PTW32_CDECL pthread_setcancelstate (int state, int *oldstate); -PTW32_DLLPORT int PTW32_CDECL pthread_setcanceltype (int type, +PTW32_DLLPORT int PTW32_CDECL pthread_setcanceltype (int type, int *oldtype); -PTW32_DLLPORT void PTW32_CDECL pthread_testcancel (void); +PTW32_DLLPORT void PTW32_CDECL pthread_testcancel (void); -PTW32_DLLPORT int PTW32_CDECL pthread_once (pthread_once_t * once_control, - void (PTW32_CDECL *init_routine) (void)); +PTW32_DLLPORT int PTW32_CDECL pthread_once (pthread_once_t * once_control, + void (PTW32_CDECL *init_routine) (void)); #if PTW32_LEVEL >= PTW32_LEVEL_MAX -PTW32_DLLPORT ptw32_cleanup_t * PTW32_CDECL ptw32_pop_cleanup (int execute); +PTW32_DLLPORT ptw32_cleanup_t * PTW32_CDECL ptw32_pop_cleanup (int execute); -PTW32_DLLPORT void PTW32_CDECL ptw32_push_cleanup (ptw32_cleanup_t * cleanup, +PTW32_DLLPORT void PTW32_CDECL ptw32_push_cleanup (ptw32_cleanup_t * cleanup, ptw32_cleanup_callback_t routine, void *arg); #endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */ @@ -1021,177 +854,177 @@ PTW32_DLLPORT void PTW32_CDECL ptw32_push_cleanup (ptw32_cleanup_t * cleanup, /* * Thread Specific Data Functions */ -PTW32_DLLPORT int PTW32_CDECL pthread_key_create (pthread_key_t * key, - void (PTW32_CDECL *destructor) (void *)); +PTW32_DLLPORT int PTW32_CDECL pthread_key_create (pthread_key_t * key, + void (PTW32_CDECL *destructor) (void *)); -PTW32_DLLPORT int PTW32_CDECL pthread_key_delete (pthread_key_t key); +PTW32_DLLPORT int PTW32_CDECL pthread_key_delete (pthread_key_t key); -PTW32_DLLPORT int PTW32_CDECL pthread_setspecific (pthread_key_t key, +PTW32_DLLPORT int PTW32_CDECL pthread_setspecific (pthread_key_t key, const void *value); -PTW32_DLLPORT void * PTW32_CDECL pthread_getspecific (pthread_key_t key); +PTW32_DLLPORT void * PTW32_CDECL pthread_getspecific (pthread_key_t key); /* * Mutex Attribute Functions */ -PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_init (pthread_mutexattr_t * attr); +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_init (pthread_mutexattr_t * attr); -PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_destroy (pthread_mutexattr_t * attr); +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_destroy (pthread_mutexattr_t * attr); -PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getpshared (const pthread_mutexattr_t +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getpshared (const pthread_mutexattr_t * attr, int *pshared); -PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setpshared (pthread_mutexattr_t * attr, +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setpshared (pthread_mutexattr_t * attr, int pshared); -PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_settype (pthread_mutexattr_t * attr, int kind); -PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_gettype (const pthread_mutexattr_t * attr, int *kind); +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_settype (pthread_mutexattr_t * attr, int kind); +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_gettype (const pthread_mutexattr_t * attr, int *kind); -PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setrobust( +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setrobust( pthread_mutexattr_t *attr, int robust); -PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getrobust( +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getrobust( const pthread_mutexattr_t * attr, int * robust); /* * Barrier Attribute Functions */ -PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_init (pthread_barrierattr_t * attr); +PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_init (pthread_barrierattr_t * attr); -PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_destroy (pthread_barrierattr_t * attr); +PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_destroy (pthread_barrierattr_t * attr); -PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_getpshared (const pthread_barrierattr_t +PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_getpshared (const pthread_barrierattr_t * attr, int *pshared); -PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_setpshared (pthread_barrierattr_t * attr, +PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_setpshared (pthread_barrierattr_t * attr, int pshared); /* * Mutex Functions */ -PTW32_DLLPORT int PTW32_CDECL pthread_mutex_init (pthread_mutex_t * mutex, +PTW32_DLLPORT int PTW32_CDECL pthread_mutex_init (pthread_mutex_t * mutex, const pthread_mutexattr_t * attr); -PTW32_DLLPORT int PTW32_CDECL pthread_mutex_destroy (pthread_mutex_t * mutex); +PTW32_DLLPORT int PTW32_CDECL pthread_mutex_destroy (pthread_mutex_t * mutex); -PTW32_DLLPORT int PTW32_CDECL pthread_mutex_lock (pthread_mutex_t * mutex); +PTW32_DLLPORT int PTW32_CDECL pthread_mutex_lock (pthread_mutex_t * mutex); -PTW32_DLLPORT int PTW32_CDECL pthread_mutex_timedlock(pthread_mutex_t * mutex, +PTW32_DLLPORT int PTW32_CDECL pthread_mutex_timedlock(pthread_mutex_t * mutex, const struct timespec *abstime); -PTW32_DLLPORT int PTW32_CDECL pthread_mutex_trylock (pthread_mutex_t * mutex); +PTW32_DLLPORT int PTW32_CDECL pthread_mutex_trylock (pthread_mutex_t * mutex); -PTW32_DLLPORT int PTW32_CDECL pthread_mutex_unlock (pthread_mutex_t * mutex); +PTW32_DLLPORT int PTW32_CDECL pthread_mutex_unlock (pthread_mutex_t * mutex); -PTW32_DLLPORT int PTW32_CDECL pthread_mutex_consistent (pthread_mutex_t * mutex); +PTW32_DLLPORT int PTW32_CDECL pthread_mutex_consistent (pthread_mutex_t * mutex); /* * Spinlock Functions */ -PTW32_DLLPORT int PTW32_CDECL pthread_spin_init (pthread_spinlock_t * lock, int pshared); +PTW32_DLLPORT int PTW32_CDECL pthread_spin_init (pthread_spinlock_t * lock, int pshared); -PTW32_DLLPORT int PTW32_CDECL pthread_spin_destroy (pthread_spinlock_t * lock); +PTW32_DLLPORT int PTW32_CDECL pthread_spin_destroy (pthread_spinlock_t * lock); -PTW32_DLLPORT int PTW32_CDECL pthread_spin_lock (pthread_spinlock_t * lock); +PTW32_DLLPORT int PTW32_CDECL pthread_spin_lock (pthread_spinlock_t * lock); -PTW32_DLLPORT int PTW32_CDECL pthread_spin_trylock (pthread_spinlock_t * lock); +PTW32_DLLPORT int PTW32_CDECL pthread_spin_trylock (pthread_spinlock_t * lock); -PTW32_DLLPORT int PTW32_CDECL pthread_spin_unlock (pthread_spinlock_t * lock); +PTW32_DLLPORT int PTW32_CDECL pthread_spin_unlock (pthread_spinlock_t * lock); /* * Barrier Functions */ -PTW32_DLLPORT int PTW32_CDECL pthread_barrier_init (pthread_barrier_t * barrier, +PTW32_DLLPORT int PTW32_CDECL pthread_barrier_init (pthread_barrier_t * barrier, const pthread_barrierattr_t * attr, unsigned int count); -PTW32_DLLPORT int PTW32_CDECL pthread_barrier_destroy (pthread_barrier_t * barrier); +PTW32_DLLPORT int PTW32_CDECL pthread_barrier_destroy (pthread_barrier_t * barrier); -PTW32_DLLPORT int PTW32_CDECL pthread_barrier_wait (pthread_barrier_t * barrier); +PTW32_DLLPORT int PTW32_CDECL pthread_barrier_wait (pthread_barrier_t * barrier); /* * Condition Variable Attribute Functions */ -PTW32_DLLPORT int PTW32_CDECL pthread_condattr_init (pthread_condattr_t * attr); +PTW32_DLLPORT int PTW32_CDECL pthread_condattr_init (pthread_condattr_t * attr); -PTW32_DLLPORT int PTW32_CDECL pthread_condattr_destroy (pthread_condattr_t * attr); +PTW32_DLLPORT int PTW32_CDECL pthread_condattr_destroy (pthread_condattr_t * attr); -PTW32_DLLPORT int PTW32_CDECL pthread_condattr_getpshared (const pthread_condattr_t * attr, +PTW32_DLLPORT int PTW32_CDECL pthread_condattr_getpshared (const pthread_condattr_t * attr, int *pshared); -PTW32_DLLPORT int PTW32_CDECL pthread_condattr_setpshared (pthread_condattr_t * attr, +PTW32_DLLPORT int PTW32_CDECL pthread_condattr_setpshared (pthread_condattr_t * attr, int pshared); /* * Condition Variable Functions */ -PTW32_DLLPORT int PTW32_CDECL pthread_cond_init (pthread_cond_t * cond, +PTW32_DLLPORT int PTW32_CDECL pthread_cond_init (pthread_cond_t * cond, const pthread_condattr_t * attr); -PTW32_DLLPORT int PTW32_CDECL pthread_cond_destroy (pthread_cond_t * cond); +PTW32_DLLPORT int PTW32_CDECL pthread_cond_destroy (pthread_cond_t * cond); -PTW32_DLLPORT int PTW32_CDECL pthread_cond_wait (pthread_cond_t * cond, +PTW32_DLLPORT int PTW32_CDECL pthread_cond_wait (pthread_cond_t * cond, pthread_mutex_t * mutex); -PTW32_DLLPORT int PTW32_CDECL pthread_cond_timedwait (pthread_cond_t * cond, +PTW32_DLLPORT int PTW32_CDECL pthread_cond_timedwait (pthread_cond_t * cond, pthread_mutex_t * mutex, const struct timespec *abstime); -PTW32_DLLPORT int PTW32_CDECL pthread_cond_signal (pthread_cond_t * cond); +PTW32_DLLPORT int PTW32_CDECL pthread_cond_signal (pthread_cond_t * cond); -PTW32_DLLPORT int PTW32_CDECL pthread_cond_broadcast (pthread_cond_t * cond); +PTW32_DLLPORT int PTW32_CDECL pthread_cond_broadcast (pthread_cond_t * cond); /* * Scheduling */ -PTW32_DLLPORT int PTW32_CDECL pthread_setschedparam (pthread_t thread, +PTW32_DLLPORT int PTW32_CDECL pthread_setschedparam (pthread_t thread, int policy, const struct sched_param *param); -PTW32_DLLPORT int PTW32_CDECL pthread_getschedparam (pthread_t thread, +PTW32_DLLPORT int PTW32_CDECL pthread_getschedparam (pthread_t thread, int *policy, struct sched_param *param); -PTW32_DLLPORT int PTW32_CDECL pthread_setconcurrency (int); +PTW32_DLLPORT int PTW32_CDECL pthread_setconcurrency (int); -PTW32_DLLPORT int PTW32_CDECL pthread_getconcurrency (void); +PTW32_DLLPORT int PTW32_CDECL pthread_getconcurrency (void); /* * Read-Write Lock Functions */ -PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_init(pthread_rwlock_t *lock, +PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_init(pthread_rwlock_t *lock, const pthread_rwlockattr_t *attr); -PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_destroy(pthread_rwlock_t *lock); +PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_destroy(pthread_rwlock_t *lock); -PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_tryrdlock(pthread_rwlock_t *); +PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_tryrdlock(pthread_rwlock_t *); -PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_trywrlock(pthread_rwlock_t *); +PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_trywrlock(pthread_rwlock_t *); -PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_rdlock(pthread_rwlock_t *lock); +PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_rdlock(pthread_rwlock_t *lock); -PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_timedrdlock(pthread_rwlock_t *lock, +PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_timedrdlock(pthread_rwlock_t *lock, const struct timespec *abstime); -PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_wrlock(pthread_rwlock_t *lock); +PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_wrlock(pthread_rwlock_t *lock); -PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_timedwrlock(pthread_rwlock_t *lock, +PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_timedwrlock(pthread_rwlock_t *lock, const struct timespec *abstime); -PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_unlock(pthread_rwlock_t *lock); +PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_unlock(pthread_rwlock_t *lock); -PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_init (pthread_rwlockattr_t * attr); +PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_init (pthread_rwlockattr_t * attr); -PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_destroy (pthread_rwlockattr_t * attr); +PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_destroy (pthread_rwlockattr_t * attr); -PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_getpshared (const pthread_rwlockattr_t * attr, +PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_getpshared (const pthread_rwlockattr_t * attr, int *pshared); -PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_setpshared (pthread_rwlockattr_t * attr, +PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_setpshared (pthread_rwlockattr_t * attr, int pshared); #if PTW32_LEVEL >= PTW32_LEVEL_MAX - 1 @@ -1200,7 +1033,7 @@ PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_setpshared (pthread_rwlockattr_ * Signal Functions. Should be defined in but MSVC and MinGW32 * already have signal.h that don't define these. */ -PTW32_DLLPORT int PTW32_CDECL pthread_kill(pthread_t thread, int sig); +PTW32_DLLPORT int PTW32_CDECL pthread_kill(pthread_t thread, int sig); /* * Non-portable functions @@ -1209,37 +1042,37 @@ PTW32_DLLPORT int PTW32_CDECL pthread_kill(pthread_t thread, int sig); /* * Compatibility with Linux. */ -PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setkind_np(pthread_mutexattr_t * attr, +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setkind_np(pthread_mutexattr_t * attr, int kind); -PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getkind_np(pthread_mutexattr_t * attr, +PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getkind_np(pthread_mutexattr_t * attr, int *kind); -PTW32_DLLPORT int PTW32_CDECL pthread_timedjoin_np(pthread_t thread, +PTW32_DLLPORT int PTW32_CDECL pthread_timedjoin_np(pthread_t thread, void **value_ptr, const struct timespec *abstime); -PTW32_DLLPORT int PTW32_CDECL pthread_tryjoin_np(pthread_t thread, +PTW32_DLLPORT int PTW32_CDECL pthread_tryjoin_np(pthread_t thread, void **value_ptr); -PTW32_DLLPORT int PTW32_CDECL pthread_setaffinity_np(pthread_t thread, +PTW32_DLLPORT int PTW32_CDECL pthread_setaffinity_np(pthread_t thread, size_t cpusetsize, const cpu_set_t *cpuset); -PTW32_DLLPORT int PTW32_CDECL pthread_getaffinity_np(pthread_t thread, +PTW32_DLLPORT int PTW32_CDECL pthread_getaffinity_np(pthread_t thread, size_t cpusetsize, cpu_set_t *cpuset); /* * Possibly supported by other POSIX threads implementations */ -PTW32_DLLPORT int PTW32_CDECL pthread_delay_np (struct timespec * interval); -PTW32_DLLPORT int PTW32_CDECL pthread_num_processors_np(void); -PTW32_DLLPORT unsigned __int64 PTW32_CDECL pthread_getunique_np(pthread_t thread); +PTW32_DLLPORT int PTW32_CDECL pthread_delay_np (struct timespec * interval); +PTW32_DLLPORT int PTW32_CDECL pthread_num_processors_np(void); +PTW32_DLLPORT unsigned __int64 PTW32_CDECL pthread_getunique_np(pthread_t thread); /* * Useful if an application wants to statically link * the lib rather than load the DLL at run-time. */ -PTW32_DLLPORT int PTW32_CDECL pthread_win32_process_attach_np(void); -PTW32_DLLPORT int PTW32_CDECL pthread_win32_process_detach_np(void); -PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_attach_np(void); -PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_detach_np(void); +PTW32_DLLPORT int PTW32_CDECL pthread_win32_process_attach_np(void); +PTW32_DLLPORT int PTW32_CDECL pthread_win32_process_detach_np(void); +PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_attach_np(void); +PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_detach_np(void); /* * Returns the first parameter "abstime" modified to represent the current system time. @@ -1268,43 +1101,43 @@ enum ptw32_features * WM_TIMECHANGE message. It can be passed directly to * pthread_create() as a new thread if desired. */ -PTW32_DLLPORT void * PTW32_CDECL pthread_timechange_handler_np(void *); +PTW32_DLLPORT void * PTW32_CDECL pthread_timechange_handler_np(void *); -#endif /*PTW32_LEVEL >= PTW32_LEVEL_MAX - 1 */ +#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX - 1 */ #if PTW32_LEVEL >= PTW32_LEVEL_MAX /* * Returns the Win32 HANDLE for the POSIX thread. */ -PTW32_DLLPORT HANDLE PTW32_CDECL pthread_getw32threadhandle_np(pthread_t thread); +PTW32_DLLPORT void * PTW32_CDECL pthread_getw32threadhandle_np(pthread_t thread); /* * Returns the win32 thread ID for POSIX thread. */ -PTW32_DLLPORT DWORD PTW32_CDECL pthread_getw32threadid_np (pthread_t thread); +PTW32_DLLPORT unsigned long PTW32_CDECL pthread_getw32threadid_np (pthread_t thread); /* * Sets the POSIX thread name. If _MSC_VER is defined the name should be displayed by * the MSVS debugger. */ -#if defined(PTW32_COMPATIBILITY_BSD) || defined(PTW32_COMPATIBILITY_TRU64) +#if defined (PTW32_COMPATIBILITY_BSD) || defined (PTW32_COMPATIBILITY_TRU64) #define PTHREAD_MAX_NAMELEN_NP 16 -PTW32_DLLPORT int PTW32_CDECL pthread_setname_np (pthread_t thr, const char * name, void * arg); -PTW32_DLLPORT int PTW32_CDECL pthread_attr_setname_np (pthread_attr_t * attr, const char * name, void * arg); +PTW32_DLLPORT int PTW32_CDECL pthread_setname_np (pthread_t thr, const char * name, void * arg); +PTW32_DLLPORT int PTW32_CDECL pthread_attr_setname_np (pthread_attr_t * attr, const char * name, void * arg); #else -PTW32_DLLPORT int PTW32_CDECL pthread_setname_np (pthread_t thr, const char * name); -PTW32_DLLPORT int PTW32_CDECL pthread_attr_setname_np (pthread_attr_t * attr, const char * name); +PTW32_DLLPORT int PTW32_CDECL pthread_setname_np (pthread_t thr, const char * name); +PTW32_DLLPORT int PTW32_CDECL pthread_attr_setname_np (pthread_attr_t * attr, const char * name); #endif -PTW32_DLLPORT int PTW32_CDECL pthread_getname_np (pthread_t thr, char * name, int len); -PTW32_DLLPORT int PTW32_CDECL pthread_attr_getname_np (pthread_attr_t * attr, char * name, int len); +PTW32_DLLPORT int PTW32_CDECL pthread_getname_np (pthread_t thr, char * name, int len); +PTW32_DLLPORT int PTW32_CDECL pthread_attr_getname_np (pthread_attr_t * attr, char * name, int len); /* * Protected Methods * * This function blocks until the given WIN32 handle - * is signaled or pthread_cancel had been called. + * is signalled or pthread_cancel had been called. * This function allows the caller to hook into the * PThreads cancel mechanism. It is implemented using * @@ -1315,9 +1148,9 @@ PTW32_DLLPORT int PTW32_CDECL pthread_attr_getname_np (pthread_attr_t * attr, ch * argument to TimedWait is simply passed to * WaitForMultipleObjects. */ -PTW32_DLLPORT int PTW32_CDECL pthreadCancelableWait (HANDLE waitHandle); -PTW32_DLLPORT int PTW32_CDECL pthreadCancelableTimedWait (HANDLE waitHandle, - DWORD timeout); +PTW32_DLLPORT int PTW32_CDECL pthreadCancelableWait (void *waitHandle); +PTW32_DLLPORT int PTW32_CDECL pthreadCancelableTimedWait (void *waitHandle, + unsigned long timeout); #endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */ @@ -1332,53 +1165,9 @@ PTW32_DLLPORT int PTW32_CDECL pthreadCancelableTimedWait (HANDLE waitHandle, # endif #endif -/* - * If pthreads-win32 is compiled as a DLL with MSVC, and - * both it and the application are linked against the static - * C runtime (i.e. with the /MT compiler flag), then the - * application will not see the same C runtime globals as - * the library. These include the errno variable, and the - * termination routine called by terminate(). For details, - * refer to the following links: - * - * http://support.microsoft.com/kb/94248 - * (Section 4: Problems Encountered When Using Multiple CRT Libraries) - * - * http://social.msdn.microsoft.com/forums/en-US/vclanguage/thread/b4500c0d-1b69-40c7-9ef5-08da1025b5bf - * - * When pthreads-win32 is built with PTW32_USES_SEPARATE_CRT - * defined, the following features are enabled: - * - * (1) In addition to setting the errno variable when errors - * occur, the library will also call SetLastError() with the - * same value. The application can then use GetLastError() - * to obtain the value of errno. (This pair of routines are - * in kernel32.dll, and so are not affected by the use of - * multiple CRT libraries.) - * - * (2) When C++ or SEH cleanup is used, the library defines - * a function pthread_win32_set_terminate_np(), which can be - * used to set the termination routine that should be called - * when an unhandled exception occurs in a thread function - * (or otherwise inside the library). - * - * Note: "_DLL" implies the /MD compiler flag. - */ -#if defined(_MSC_VER) && !defined(_DLL) && !defined(PTW32_STATIC_LIB) -# define PTW32_USES_SEPARATE_CRT -#endif - -#if defined(PTW32_USES_SEPARATE_CRT) && (defined(__CLEANUP_CXX) || defined(__CLEANUP_SEH)) +#if defined (PTW32_USES_SEPARATE_CRT) && (defined(PTW32_CLEANUP_CXX) || defined(PTW32_CLEANUP_SEH)) typedef void (*ptw32_terminate_handler)(); -PTW32_DLLPORT ptw32_terminate_handler PTW32_CDECL pthread_win32_set_terminate_np(ptw32_terminate_handler termFunction); -#endif - -/* - * Some compiler environments don't define some things. - */ -#if defined(__BORLANDC__) -# define _ftime ftime -# define _timeb timeb +PTW32_DLLPORT ptw32_terminate_handler PTW32_CDECL pthread_win32_set_terminate_np(ptw32_terminate_handler termFunction); #endif #if defined(__cplusplus) @@ -1398,13 +1187,13 @@ class ptw32_exception_exit : public ptw32_exception {}; /* * Get internal SEH tag */ -PTW32_DLLPORT DWORD PTW32_CDECL ptw32_get_exception_services_code(void); +PTW32_DLLPORT unsigned long PTW32_CDECL ptw32_get_exception_services_code(void); #endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */ -#if !defined(PTW32_BUILD) +#if !defined (PTW32_BUILD) -#if defined(__CLEANUP_SEH) +#if defined(PTW32_CLEANUP_SEH) /* * Redefine the SEH __except keyword to ensure that applications @@ -1414,9 +1203,9 @@ PTW32_DLLPORT DWORD PTW32_CDECL ptw32_get_exception_services_code(void); __except( ( GetExceptionCode() == ptw32_get_exception_services_code() ) \ ? EXCEPTION_CONTINUE_SEARCH : ( E ) ) -#endif /* __CLEANUP_SEH */ +#endif /* PTW32_CLEANUP_SEH */ -#if defined(__CLEANUP_CXX) +#if defined(PTW32_CLEANUP_CXX) /* * Redefine the C++ catch keyword to ensure that applications @@ -1424,21 +1213,21 @@ PTW32_DLLPORT DWORD PTW32_CDECL ptw32_get_exception_services_code(void); */ #if defined(_MSC_VER) /* - * WARNING: Replace any 'catch( ... )' with 'PtW32CatchAll' + * WARNING: Replace any 'catch( ... )' with '__PtW32CatchAll' * if you want Pthread-Win32 cancellation and pthread_exit to work. */ -#if !defined(PtW32NoCatchWarn) +#if !defined(__PtW32NoCatchWarn) -#pragma message("Specify \"/DPtW32NoCatchWarn\" compiler flag to skip this message.") +#pragma message("Specify \"/D__PtW32NoCatchWarn\" compiler flag to skip this message.") #pragma message("------------------------------------------------------------------") #pragma message("When compiling applications with MSVC++ and C++ exception handling:") #pragma message(" Replace any 'catch( ... )' in routines called from POSIX threads") -#pragma message(" with 'PtW32CatchAll' or 'CATCHALL' if you want POSIX thread") +#pragma message(" with '__PtW32CatchAll' or 'CATCHALL' if you want POSIX thread") #pragma message(" cancellation and pthread_exit to work. For example:") #pragma message("") -#pragma message(" #if defined(PtW32CatchAll)") -#pragma message(" PtW32CatchAll") +#pragma message(" #if defined(__PtW32CatchAll)") +#pragma message(" __PtW32CatchAll") #pragma message(" #else") #pragma message(" catch(...)") #pragma message(" #endif") @@ -1449,7 +1238,7 @@ PTW32_DLLPORT DWORD PTW32_CDECL ptw32_get_exception_services_code(void); #endif -#define PtW32CatchAll \ +#define __PtW32CatchAll \ catch( ptw32_exception & ) { throw; } \ catch( ... ) @@ -1461,20 +1250,11 @@ PTW32_DLLPORT DWORD PTW32_CDECL ptw32_get_exception_services_code(void); #endif /* _MSC_VER */ -#endif /* __CLEANUP_CXX */ +#endif /* PTW32_CLEANUP_CXX */ -#endif /* ! PTW32_BUILD */ +#endif /* ! PTW32_BUILD */ -#if defined(__cplusplus) -} /* End of extern "C" */ -#endif /* __cplusplus */ - -#if defined(PTW32__HANDLE_DEF) -# undef HANDLE -#endif -#if defined(PTW32__DWORD_DEF) -# undef DWORD -#endif +PTW32_END_C_DECLS #undef PTW32_LEVEL #undef PTW32_LEVEL_MAX diff --git a/pthread_attr_getaffinity_np.c b/pthread_attr_getaffinity_np.c index 022a3d38..3caaa8ae 100644 --- a/pthread_attr_getaffinity_np.c +++ b/pthread_attr_getaffinity_np.c @@ -18,17 +18,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/pthread_attr_getname_np.c b/pthread_attr_getname_np.c index 1e4b3dcf..9c8e8b2b 100644 --- a/pthread_attr_getname_np.c +++ b/pthread_attr_getname_np.c @@ -15,17 +15,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/pthread_attr_getstackaddr.c b/pthread_attr_getstackaddr.c index bffa66fd..38249114 100644 --- a/pthread_attr_getstackaddr.c +++ b/pthread_attr_getstackaddr.c @@ -18,17 +18,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/pthread_attr_getstacksize.c b/pthread_attr_getstacksize.c index b12ab649..0918de89 100644 --- a/pthread_attr_getstacksize.c +++ b/pthread_attr_getstacksize.c @@ -18,17 +18,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/pthread_attr_init.c b/pthread_attr_init.c index b5ad4a42..ef799a93 100644 --- a/pthread_attr_init.c +++ b/pthread_attr_init.c @@ -18,17 +18,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/pthread_attr_setaffinity_np.c b/pthread_attr_setaffinity_np.c index c15dfc5d..f7166e68 100644 --- a/pthread_attr_setaffinity_np.c +++ b/pthread_attr_setaffinity_np.c @@ -18,17 +18,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/pthread_attr_setname_np.c b/pthread_attr_setname_np.c index 4dc9ac02..2ab34de8 100644 --- a/pthread_attr_setname_np.c +++ b/pthread_attr_setname_np.c @@ -15,17 +15,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/pthread_attr_setstackaddr.c b/pthread_attr_setstackaddr.c index e93ab364..4a682818 100644 --- a/pthread_attr_setstackaddr.c +++ b/pthread_attr_setstackaddr.c @@ -18,17 +18,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/pthread_attr_setstacksize.c b/pthread_attr_setstacksize.c index 259499e4..f10658e5 100644 --- a/pthread_attr_setstacksize.c +++ b/pthread_attr_setstacksize.c @@ -18,17 +18,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/pthread_cancel.c b/pthread_cancel.c index 0a32cc32..2d5e2eba 100644 --- a/pthread_cancel.c +++ b/pthread_cancel.c @@ -109,8 +109,12 @@ pthread_cancel (pthread_t thread) ptw32_thread_t * tp; ptw32_mcs_local_node_t stateLock; + /* + * Validate the thread id. This method works for pthreads-win32 because + * pthread_kill and pthread_t are designed to accommodate it, but the + * method is not portable. + */ result = pthread_kill (thread, 0); - if (0 != result) { return result; diff --git a/pthread_detach.c b/pthread_detach.c index 34544c98..df19c64e 100644 --- a/pthread_detach.c +++ b/pthread_detach.c @@ -108,9 +108,13 @@ pthread_detach (pthread_t thread) result = 0; ptw32_mcs_lock_acquire (&tp->stateLock, &stateLock); - if (tp->state != PThreadStateLast) + if (tp->state < PThreadStateLast) { tp->detachState = PTHREAD_CREATE_DETACHED; + if (tp->state == PThreadStateExiting) + { + destroyIt = PTW32_TRUE; + } } else if (tp->detachState != PTHREAD_CREATE_DETACHED) { diff --git a/pthread_exit.c b/pthread_exit.c index 0a843509..4b91df65 100644 --- a/pthread_exit.c +++ b/pthread_exit.c @@ -95,7 +95,7 @@ pthread_exit (void *value_ptr) * Implicit POSIX handles are cleaned up in ptw32_throw() now. */ -#if ! defined (PTW32_CONFIG_MINGW) || defined (__MSVCRT__) || defined (__DMC__) +#if ! defined (__MINGW32__) || defined (__MSVCRT__) || defined (__DMC__) _endthreadex ((unsigned) (size_t) value_ptr); #else _endthread (); diff --git a/pthread_getname_np.c b/pthread_getname_np.c index dd84b5d8..d5efeb69 100644 --- a/pthread_getname_np.c +++ b/pthread_getname_np.c @@ -15,17 +15,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., @@ -46,9 +46,14 @@ pthread_getname_np(pthread_t thr, char *name, int len) { ptw32_mcs_local_node_t threadLock; ptw32_thread_t * tp; + char * s, * d; int result; - /* Validate the thread id. */ + /* + * Validate the thread id. This method works for pthreads-win32 because + * pthread_kill and pthread_t are designed to accommodate it, but the + * method is not portable. + */ result = pthread_kill (thr, 0); if (0 != result) { @@ -59,13 +64,11 @@ pthread_getname_np(pthread_t thr, char *name, int len) ptw32_mcs_lock_acquire (&tp->threadLock, &threadLock); -#if defined(_MSC_VER) -# pragma warning(suppress:4996) -#endif - strncpy(name, tp->name, len - 1); - name[len - 1] = '\0'; + for (s = tp->name, d = name; *s && d < &name[len - 1]; *d++ = *s++) + {} + *d = '\0'; ptw32_mcs_lock_release (&threadLock); - return 0; + return result; } diff --git a/pthread_getschedparam.c b/pthread_getschedparam.c index dcf3fadb..24d97f28 100644 --- a/pthread_getschedparam.c +++ b/pthread_getschedparam.c @@ -1,6 +1,6 @@ /* * sched_getschedparam.c - * + * * Description: * POSIX thread functions that deal with thread scheduling. * @@ -51,7 +51,11 @@ pthread_getschedparam (pthread_t thread, int *policy, { int result; - /* Validate the thread id. */ + /* + * Validate the thread id. This method works for pthreads-win32 because + * pthread_kill and pthread_t are designed to accommodate it, but the + * method is not portable. + */ result = pthread_kill (thread, 0); if (0 != result) { diff --git a/pthread_key_create.c b/pthread_key_create.c index b318504c..24bb4d36 100644 --- a/pthread_key_create.c +++ b/pthread_key_create.c @@ -51,7 +51,7 @@ #endif int -pthread_key_create (pthread_key_t * key, void (PTW32_CDECL *destructor) (void *)) +pthread_key_create (pthread_key_t * key, void (PTW32_CDECL *destructor) (void *)) /* * ------------------------------------------------------ * DOCPUBLIC diff --git a/pthread_key_delete.c b/pthread_key_delete.c index f6ebf780..f36f7f23 100644 --- a/pthread_key_delete.c +++ b/pthread_key_delete.c @@ -18,17 +18,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/pthread_kill.c b/pthread_kill.c index e80e3a46..5702be27 100644 --- a/pthread_kill.c +++ b/pthread_kill.c @@ -83,23 +83,8 @@ pthread_kill (pthread_t thread, int sig) */ { int result = 0; - ptw32_thread_t * tp; - ptw32_mcs_local_node_t node; - ptw32_mcs_lock_acquire(&ptw32_thread_reuse_lock, &node); - - tp = (ptw32_thread_t *) thread.p; - - if (NULL == tp - || thread.x != tp->ptHandle.x - || NULL == tp->threadH) - { - result = ESRCH; - } - - ptw32_mcs_lock_release(&node); - - if (0 == result && 0 != sig) + if (0 != sig) { /* * Currently only supports direct thread termination via SIGABRT. @@ -148,6 +133,24 @@ pthread_kill (pthread_t thread, int sig) break; } } + else + { + ptw32_mcs_local_node_t node; + ptw32_thread_t * tp; + + ptw32_mcs_lock_acquire(&ptw32_thread_reuse_lock, &node); + + tp = (ptw32_thread_t *) thread.p; + + if (NULL == tp + || thread.x != tp->ptHandle.x + || tp->state < PThreadStateRunning) + { + result = ESRCH; + } + + ptw32_mcs_lock_release(&node); + } return result; diff --git a/pthread_mutex_init.c b/pthread_mutex_init.c index cccc1b55..4fac214c 100644 --- a/pthread_mutex_init.c +++ b/pthread_mutex_init.c @@ -18,17 +18,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., @@ -111,34 +111,42 @@ pthread_mutex_init (pthread_mutex_t * mutex, const pthread_mutexattr_t * attr) mx->robustNode = (ptw32_robust_node_t*) malloc(sizeof(ptw32_robust_node_t)); if (NULL == mx->robustNode) - { - free(mx); - mx = NULL; - return ENOMEM; - } - mx->robustNode->stateInconsistent = PTW32_ROBUST_CONSISTENT; - mx->robustNode->mx = mx; - mx->robustNode->next = NULL; - mx->robustNode->prev = NULL; + { + result = ENOMEM; + } + else + { + mx->robustNode->stateInconsistent = PTW32_ROBUST_CONSISTENT; + mx->robustNode->mx = mx; + mx->robustNode->next = NULL; + mx->robustNode->prev = NULL; + } } } - mx->ownerThread.p = NULL; + if (0 == result) + { + mx->ownerThread.p = NULL; - mx->event = CreateEvent (NULL, PTW32_FALSE, /* manual reset = No */ - PTW32_FALSE, /* initial state = not signaled */ - NULL); /* event name */ + mx->event = CreateEvent (NULL, PTW32_FALSE, /* manual reset = No */ + PTW32_FALSE, /* initial state = not signalled */ + NULL); /* event name */ - if (0 == mx->event) - { - result = ENOSPC; - if (mx->robustNode != NULL) - { - free (mx->robustNode); - } - free (mx); - mx = NULL; - } + if (0 == mx->event) + { + result = ENOSPC; + } + } + } + + if (0 != result) + { + if (NULL != mx->robustNode) + { + free (mx->robustNode); + } + free (mx); + mx = NULL; } *mutex = mx; diff --git a/pthread_mutex_lock.c b/pthread_mutex_lock.c index 1a30932a..847477c1 100644 --- a/pthread_mutex_lock.c +++ b/pthread_mutex_lock.c @@ -50,14 +50,14 @@ int pthread_mutex_lock (pthread_mutex_t * mutex) { - int kind; - pthread_mutex_t mx; - int result = 0; - /* * Let the system deal with invalid pointers. */ - if (*mutex == NULL) + pthread_mutex_t mx = *mutex; + int kind; + int result = 0; + + if (mx == NULL) { return EINVAL; } @@ -68,15 +68,15 @@ pthread_mutex_lock (pthread_mutex_t * mutex) * again inside the guarded section of ptw32_mutex_check_need_init() * to avoid race conditions. */ - if (*mutex >= PTHREAD_ERRORCHECK_MUTEX_INITIALIZER) + if (mx >= PTHREAD_ERRORCHECK_MUTEX_INITIALIZER) { if ((result = ptw32_mutex_check_need_init (mutex)) != 0) { return (result); } + mx = *mutex; } - mx = *mutex; kind = mx->kind; if (kind >= 0) diff --git a/pthread_mutex_timedlock.c b/pthread_mutex_timedlock.c index a55f0103..13372e37 100644 --- a/pthread_mutex_timedlock.c +++ b/pthread_mutex_timedlock.c @@ -115,13 +115,17 @@ int pthread_mutex_timedlock (pthread_mutex_t * mutex, const struct timespec *abstime) { - pthread_mutex_t mx; - int kind; - int result = 0; - /* * Let the system deal with invalid pointers. */ + pthread_mutex_t mx = *mutex; + int kind; + int result = 0; + + if (mx == NULL) + { + return EINVAL; + } /* * We do a quick check to see if we need to do more work @@ -129,15 +133,15 @@ pthread_mutex_timedlock (pthread_mutex_t * mutex, * again inside the guarded section of ptw32_mutex_check_need_init() * to avoid race conditions. */ - if (*mutex >= PTHREAD_ERRORCHECK_MUTEX_INITIALIZER) + if (mx >= PTHREAD_ERRORCHECK_MUTEX_INITIALIZER) { if ((result = ptw32_mutex_check_need_init (mutex)) != 0) { return (result); } + mx = *mutex; } - mx = *mutex; kind = mx->kind; if (kind >= 0) diff --git a/pthread_mutex_trylock.c b/pthread_mutex_trylock.c index d0ea212d..f994faec 100644 --- a/pthread_mutex_trylock.c +++ b/pthread_mutex_trylock.c @@ -48,13 +48,17 @@ int pthread_mutex_trylock (pthread_mutex_t * mutex) { - pthread_mutex_t mx; - int kind; - int result = 0; - /* * Let the system deal with invalid pointers. */ + pthread_mutex_t mx = *mutex; + int kind; + int result = 0; + + if (mx == NULL) + { + return EINVAL; + } /* * We do a quick check to see if we need to do more work @@ -62,15 +66,15 @@ pthread_mutex_trylock (pthread_mutex_t * mutex) * again inside the guarded section of ptw32_mutex_check_need_init() * to avoid race conditions. */ - if (*mutex >= PTHREAD_ERRORCHECK_MUTEX_INITIALIZER) + if (mx >= PTHREAD_ERRORCHECK_MUTEX_INITIALIZER) { if ((result = ptw32_mutex_check_need_init (mutex)) != 0) { return (result); } + mx = *mutex; } - mx = *mutex; kind = mx->kind; if (kind >= 0) diff --git a/pthread_mutex_unlock.c b/pthread_mutex_unlock.c index a316cec2..4ccfb417 100644 --- a/pthread_mutex_unlock.c +++ b/pthread_mutex_unlock.c @@ -48,22 +48,19 @@ int PTW32_CDECL pthread_mutex_unlock (pthread_mutex_t * mutex) { - int result = 0; - int kind; - pthread_mutex_t mx; - /* * Let the system deal with invalid pointers. */ - - mx = *mutex; + pthread_mutex_t mx = *mutex; + int kind; + int result = 0; /* * If the thread calling us holds the mutex then there is no * race condition. If another thread holds the * lock then we shouldn't be in here. */ - if (mx < PTHREAD_ERRORCHECK_MUTEX_INITIALIZER) + if (mx < PTHREAD_ERRORCHECK_MUTEX_INITIALIZER) // Remember, pointers are unsigned. { kind = mx->kind; @@ -179,6 +176,11 @@ pthread_mutex_unlock (pthread_mutex_t * mutex) } else if (mx != PTHREAD_MUTEX_INITIALIZER) { + /* + * If mx is PTHREAD_ERRORCHECK_MUTEX_INITIALIZER or PTHREAD_RECURSIVE_MUTEX_INITIALIZER + * we need to know we are doing something unexpected. For PTHREAD_MUTEX_INITIALIZER + * (normal) mutexes we can just silently ignore it. + */ result = EINVAL; } diff --git a/pthread_self.c b/pthread_self.c index c5b12780..61415053 100644 --- a/pthread_self.c +++ b/pthread_self.c @@ -18,17 +18,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., @@ -67,7 +67,6 @@ pthread_self (void) */ { pthread_t self; - DWORD_PTR vThreadMask, vProcessMask, vSystemMask; pthread_t nil = {NULL, 0}; ptw32_thread_t * sp; @@ -88,6 +87,7 @@ pthread_self (void) else { int fail = PTW32_FALSE; + /* * Need to create an implicit 'self' for the currently * executing thread. @@ -139,6 +139,7 @@ pthread_self (void) * affinity to that of the process to get the old thread affinity, * then reset to the old affinity. */ + DWORD_PTR vThreadMask, vProcessMask, vSystemMask; if (GetProcessAffinityMask(GetCurrentProcess(), &vProcessMask, &vSystemMask)) { vThreadMask = SetThreadAffinityMask(sp->threadH, vProcessMask); @@ -156,10 +157,6 @@ pthread_self (void) #endif - /* - * No need to explicitly serialise access to sched_priority - * because the new handle is not yet public. - */ sp->sched_priority = GetThreadPriority (sp->threadH); pthread_setspecific (ptw32_selfThreadKey, (void *) sp); } @@ -179,6 +176,16 @@ pthread_self (void) */ return nil; } + else + { + /* + * This implicit POSIX thread is running (it called us). + * No other thread can reference us yet because all API calls + * passing a pthread_t should recognise an invalid thread id + * through the reuse counter inequality. + */ + sp->state = PThreadStateRunning; + } } return (self); diff --git a/pthread_setaffinity.c b/pthread_setaffinity.c index cbd1d814..baa11db1 100644 --- a/pthread_setaffinity.c +++ b/pthread_setaffinity.c @@ -18,17 +18,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/pthread_setname_np.c b/pthread_setname_np.c index cd8e4011..25a03399 100644 --- a/pthread_setname_np.c +++ b/pthread_setname_np.c @@ -15,17 +15,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., @@ -90,7 +90,11 @@ pthread_setname_np(pthread_t thr, const char *name, void *arg) DWORD Win32ThreadID; #endif - /* Validate the thread id. */ + /* + * Validate the thread id. This method works for pthreads-win32 because + * pthread_kill and pthread_t are designed to accommodate it, but the + * method is not portable. + */ result = pthread_kill (thr, 0); if (0 != result) { @@ -151,7 +155,11 @@ pthread_setname_np(pthread_t thr, const char *name) DWORD Win32ThreadID; #endif - /* Validate the thread id. */ + /* + * Validate the thread id. This method works for pthreads-win32 because + * pthread_kill and pthread_t are designed to accommodate it, but the + * method is not portable. + */ result = pthread_kill (thr, 0); if (0 != result) { diff --git a/pthread_setschedparam.c b/pthread_setschedparam.c index 5d9e342d..808ef5fc 100644 --- a/pthread_setschedparam.c +++ b/pthread_setschedparam.c @@ -51,7 +51,11 @@ pthread_setschedparam (pthread_t thread, int policy, { int result; - /* Validate the thread id. */ + /* + * Validate the thread id. This method works for pthreads-win32 because + * pthread_kill and pthread_t are designed to accommodate it, but the + * method is not portable. + */ result = pthread_kill (thread, 0); if (0 != result) { diff --git a/pthread_timedjoin_np.c b/pthread_timedjoin_np.c index 8b5057b4..8d6fb7ea 100755 --- a/pthread_timedjoin_np.c +++ b/pthread_timedjoin_np.c @@ -19,17 +19,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/pthread_tryjoin_np.c b/pthread_tryjoin_np.c index eb5791c1..42097efb 100644 --- a/pthread_tryjoin_np.c +++ b/pthread_tryjoin_np.c @@ -19,17 +19,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/pthread_win32_attach_detach_np.c b/pthread_win32_attach_detach_np.c index c58abb05..b9a4823f 100644 --- a/pthread_win32_attach_detach_np.c +++ b/pthread_win32_attach_detach_np.c @@ -18,17 +18,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., @@ -44,6 +44,9 @@ #include "pthread.h" #include "implement.h" #include +#if ! (defined(__GNUC__) || defined (PTW32_CONFIG_MSVC7) || defined(WINCE)) +# include +#endif /* * Handle to quserex.dll @@ -83,7 +86,7 @@ pthread_win32_process_attach_np () #if !defined(WINCE) gsd_res = GetSystemDirectory(QuserExDLLPathBuf, QuserExDLLPathBufSize); -#if defined(__GNUC__) || defined(PTW32_CONFIG_MSVC7) +#if defined(__GNUC__) || defined (PTW32_CONFIG_MSVC7) if(gsd_res && gsd_res < QuserExDLLPathBufSize) { (void) strncat(QuserExDLLPathBuf, diff --git a/ptw32_MCS_lock.c b/ptw32_MCS_lock.c index 5af9d5aa..94e52d29 100644 --- a/ptw32_MCS_lock.c +++ b/ptw32_MCS_lock.c @@ -38,6 +38,7 @@ */ /* + * About MCS locks: * * MCS locks are queue-based locks, where the queue nodes are local to the @@ -90,6 +91,7 @@ * } * return (void *)0; * } + * */ #ifdef HAVE_CONFIG_H @@ -109,11 +111,21 @@ INLINE void ptw32_mcs_flag_set (HANDLE * flag) { - HANDLE e = (HANDLE)(PTW32_INTERLOCKED_SIZE)PTW32_INTERLOCKED_COMPARE_EXCHANGE_SIZE( - (PTW32_INTERLOCKED_SIZEPTR)flag, - (PTW32_INTERLOCKED_SIZE)-1, - (PTW32_INTERLOCKED_SIZE)0); - if ((HANDLE)0 != e) + HANDLE e = (HANDLE) (PTW32_INTERLOCKED_SIZE)PTW32_INTERLOCKED_COMPARE_EXCHANGE_SIZE( + (PTW32_INTERLOCKED_SIZEPTR)flag, + (PTW32_INTERLOCKED_SIZE)-1, + (PTW32_INTERLOCKED_SIZE)0); + /* + * NOTE: when e == -1 and the MSVC debugger is attached to + * the process, we get an exception that halts the + * program noting that the handle value is invalid; + * although innocuous this behavior is cumbersome when + * debugging. Therefore we avoid calling SetEvent() + * for 'known' invalid HANDLE values that can arise + * when the above interlocked-compare-and-exchange + * is executed. + */ + if (((HANDLE)0 != e) && ((HANDLE)-1 != e)) { /* another thread has already stored an event handle in the flag */ SetEvent(e); @@ -180,7 +192,7 @@ ptw32_mcs_lock_acquire (ptw32_mcs_lock_t * lock, ptw32_mcs_local_node_t * node) if (0 != pred) { /* the lock was not free. link behind predecessor. */ - pred->next = node; + PTW32_INTERLOCKED_EXCHANGE_PTR ((PTW32_INTERLOCKED_PVOID_PTR)&pred->next, (PTW32_INTERLOCKED_PVOID)node); ptw32_mcs_flag_set(&pred->nextFlag); ptw32_mcs_flag_wait(&node->readyFlag); } @@ -221,7 +233,12 @@ ptw32_mcs_lock_release (ptw32_mcs_local_node_t * node) /* wait for successor */ ptw32_mcs_flag_wait(&node->nextFlag); next = (ptw32_mcs_local_node_t *) - PTW32_INTERLOCKED_EXCHANGE_ADD_SIZE((PTW32_INTERLOCKED_SIZEPTR)&node->next, (PTW32_INTERLOCKED_SIZE)0); /* MBR fence */ + PTW32_INTERLOCKED_EXCHANGE_ADD_SIZE ((PTW32_INTERLOCKED_SIZEPTR)&node->next, (PTW32_INTERLOCKED_SIZE)0); /* MBR fence */ + } + else + { + /* Even if the next is non-0, the successor may still be trying to set the next flag on us, therefore we must wait. */ + ptw32_mcs_flag_wait(&node->nextFlag); } /* pass the lock */ @@ -278,10 +295,18 @@ ptw32_mcs_node_transfer (ptw32_mcs_local_node_t * new_node, ptw32_mcs_local_node /* * A successor has queued after us, so wait for them to link to us */ - while (old_node->next == 0) + while (0 == old_node->next) { sched_yield(); } + + /* we must wait for the next Node to finish inserting itself. */ + ptw32_mcs_flag_wait(&old_node->nextFlag); + /* + * Copy the nextFlag state also so we don't block on it when releasing + * this lock. + */ new_node->next = old_node->next; + new_node->nextFlag = old_node->nextFlag; } } diff --git a/ptw32_callUserDestroyRoutines.c b/ptw32_callUserDestroyRoutines.c index a99616b2..57533e1d 100644 --- a/ptw32_callUserDestroyRoutines.c +++ b/ptw32_callUserDestroyRoutines.c @@ -45,7 +45,7 @@ #include "pthread.h" #include "implement.h" -#if defined(__CLEANUP_CXX) +#if defined(PTW32_CLEANUP_CXX) # if defined(_MSC_VER) # include # elif defined(__WATCOMC__) diff --git a/ptw32_new.c b/ptw32_new.c index 28120e15..1039c752 100644 --- a/ptw32_new.c +++ b/ptw32_new.c @@ -18,17 +18,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/ptw32_processInitialize.c b/ptw32_processInitialize.c index bd3e1001..ee7a797b 100644 --- a/ptw32_processInitialize.c +++ b/ptw32_processInitialize.c @@ -19,17 +19,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/ptw32_relmillisecs.c b/ptw32_relmillisecs.c index 81e41a6b..041e2863 100644 --- a/ptw32_relmillisecs.c +++ b/ptw32_relmillisecs.c @@ -43,38 +43,30 @@ #include "pthread.h" #include "implement.h" -#if !defined(NEED_FTIME) -#include -#endif +static const int64_t NANOSEC_PER_SEC = 1000000000; +static const int64_t NANOSEC_PER_MILLISEC = 1000000; +static const int64_t MILLISEC_PER_SEC = 1000; -#if defined(PTW32_BUILD_INLINED) -INLINE -#endif /* PTW32_BUILD_INLINED */ +#if defined (PTW32_BUILD_INLINED) +INLINE +#endif /* PTW32_BUILD_INLINED */ DWORD ptw32_relmillisecs (const struct timespec * abstime) { - const int64_t NANOSEC_PER_MILLISEC = 1000000; - const int64_t MILLISEC_PER_SEC = 1000; DWORD milliseconds; - int64_t tmpAbsMilliseconds; - int64_t tmpCurrMilliseconds; -#if defined(NEED_FTIME) + int64_t tmpAbsNanoseconds; + int64_t tmpCurrNanoseconds; + struct timespec currSysTime; FILETIME ft; + +# if defined(WINCE) SYSTEMTIME st; -#else /* ! NEED_FTIME */ -#if ( defined(_MSC_VER) && _MSC_VER >= 1300 ) /* MSVC7+ */ || \ - ( defined(PTW32_CONFIG_MINGW) && __MSVCRT_VERSION__ >= 0x0601 ) - struct __timeb64 currSysTime; -#else - struct _timeb currSysTime; #endif -#endif /* NEED_FTIME */ - - /* - * Calculate timeout as milliseconds from current system time. + /* + * Calculate timeout as milliseconds from current system time. */ /* @@ -84,50 +76,34 @@ ptw32_relmillisecs (const struct timespec * abstime) * * Assume all integers are unsigned, i.e. cannot test if less than 0. */ - tmpAbsMilliseconds = (int64_t)abstime->tv_sec * MILLISEC_PER_SEC; - tmpAbsMilliseconds += ((int64_t)abstime->tv_nsec + (NANOSEC_PER_MILLISEC/2)) / NANOSEC_PER_MILLISEC; + tmpAbsNanoseconds = (int64_t)abstime->tv_nsec + ((int64_t)abstime->tv_sec * NANOSEC_PER_SEC); /* get current system time */ -#if defined(NEED_FTIME) - +# if defined(WINCE) GetSystemTime(&st); SystemTimeToFileTime(&st, &ft); - /* - * GetSystemTimeAsFileTime(&ft); would be faster, - * but it does not exist on WinCE - */ +# else + GetSystemTimeAsFileTime(&ft); +# endif ptw32_filetime_to_timespec(&ft, &currSysTime); - tmpCurrMilliseconds = (int64_t)currSysTime.tv_sec * MILLISEC_PER_SEC; - tmpCurrMilliseconds += ((int64_t)currSysTime.tv_nsec + (NANOSEC_PER_MILLISEC/2)) - / NANOSEC_PER_MILLISEC; - -#else /* ! NEED_FTIME */ - -#if defined(_MSC_VER) && _MSC_VER >= 1400 /* MSVC8+ */ - _ftime64_s(&currSysTime); -#elif ( defined(_MSC_VER) && _MSC_VER >= 1300 ) /* MSVC7+ */ || \ - ( defined(PTW32_CONFIG_MINGW) && __MSVCRT_VERSION__ >= 0x0601 ) - _ftime64(&currSysTime); -#else - _ftime(&currSysTime); -#endif - - tmpCurrMilliseconds = (int64_t) currSysTime.time * MILLISEC_PER_SEC; - tmpCurrMilliseconds += (int64_t) currSysTime.millitm; - -#endif /* NEED_FTIME */ + tmpCurrNanoseconds = (int64_t)currSysTime.tv_nsec + ((int64_t)currSysTime.tv_sec * NANOSEC_PER_SEC); - if (tmpAbsMilliseconds > tmpCurrMilliseconds) + if (tmpAbsNanoseconds > tmpCurrNanoseconds) { - milliseconds = (DWORD) (tmpAbsMilliseconds - tmpCurrMilliseconds); - if (milliseconds == INFINITE) - { - /* Timeouts must be finite */ - milliseconds--; - } + int64_t deltaNanoseconds = tmpAbsNanoseconds - tmpCurrNanoseconds; + + if (deltaNanoseconds >= ((int64_t)INFINITE * NANOSEC_PER_MILLISEC)) + { + /* Timeouts must be finite */ + milliseconds = INFINITE - 1; + } + else + { + milliseconds = (DWORD)(deltaNanoseconds / NANOSEC_PER_MILLISEC); + } } else { @@ -135,5 +111,61 @@ ptw32_relmillisecs (const struct timespec * abstime) milliseconds = 0; } + if (milliseconds == 0 && tmpAbsNanoseconds > tmpCurrNanoseconds) { + /* + * millisecond granularity was too small to represent the wait time. + * return the minimum time in milliseconds. + */ + milliseconds = 1; + } + return milliseconds; } + + +/* + * Return the first parameter "abstime" modified to represent the current system time. + * If "relative" is not NULL it represents an interval to add to "abstime". + */ + +struct timespec * +pthread_win32_getabstime_np (struct timespec * abstime, const struct timespec * relative) +{ + int64_t sec; + int64_t nsec; + + struct timespec currSysTime; + FILETIME ft; + + /* get current system time */ + +# if defined(WINCE) + + SYSTEMTIME st; + GetSystemTime(&st); + SystemTimeToFileTime(&st, &ft); +# else + GetSystemTimeAsFileTime(&ft); +# endif + + ptw32_filetime_to_timespec(&ft, &currSysTime); + + sec = currSysTime.tv_sec; + nsec = currSysTime.tv_nsec; + + if (NULL != relative) + { + nsec += relative->tv_nsec; + if (nsec >= NANOSEC_PER_SEC) + { + sec++; + nsec -= NANOSEC_PER_SEC; + } + sec += relative->tv_sec; + } + + abstime->tv_sec = (time_t) sec; + abstime->tv_nsec = (long) nsec; + + return abstime; +} diff --git a/ptw32_reuse.c b/ptw32_reuse.c index 84c7d2bc..5a2bbd3b 100644 --- a/ptw32_reuse.c +++ b/ptw32_reuse.c @@ -18,17 +18,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., @@ -56,7 +56,7 @@ * * The original pthread_t struct plus all copies of it contain the address of * the thread state struct ptw32_thread_t_ (p), plus a reuse counter (x). Each - * ptw32_thread_t contains the original copy of it's pthread_t. + * ptw32_thread_t contains the original copy of it's pthread_t (ptHandle). * Once malloced, a ptw32_thread_t_ struct is not freed until the process exits. * * The thread reuse stack is a simple LILO stack managed through a singly @@ -66,13 +66,13 @@ * reuse stack after it's ptHandle's reuse counter has been incremented. * * The following can now be said from this: - * - two pthread_t's are identical iff their ptw32_thread_t reference pointers - * are equal and their reuse counters are equal. That is, + * - two pthread_t's refer to the same thread iff their ptw32_thread_t reference + * pointers are equal and their reuse counters are equal. That is, * * equal = (a.p == b.p && a.x == b.x) * * - a pthread_t copy refers to a destroyed thread if the reuse counter in - * the copy is not equal to the reuse counter in the original. + * the copy is not equal to (i.e less than) the reuse counter in the original. * * threadDestroyed = (copy.x != ((ptw32_thread_t *)copy.p)->ptHandle.x) * diff --git a/ptw32_semwait.c b/ptw32_semwait.c index 8e9a5232..b797c08c 100644 --- a/ptw32_semwait.c +++ b/ptw32_semwait.c @@ -18,17 +18,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., @@ -106,7 +106,7 @@ return 0; if (result != 0) { - PTW32_SET_ERRNO(result); + PTW32_SET_ERRNO(result); return -1; } diff --git a/ptw32_threadDestroy.c b/ptw32_threadDestroy.c index 1c00a67f..c0141f64 100644 --- a/ptw32_threadDestroy.c +++ b/ptw32_threadDestroy.c @@ -50,34 +50,36 @@ void ptw32_threadDestroy (pthread_t thread) { ptw32_thread_t * tp = (ptw32_thread_t *) thread.p; - ptw32_thread_t threadCopy; if (tp != NULL) { /* * Copy thread state so that the thread can be atomically NULLed. */ - memcpy (&threadCopy, tp, sizeof (threadCopy)); +#if ! defined(__MINGW32__) || defined (__MSVCRT__) || defined (__DMC__) + HANDLE threadH = tp->threadH; +#endif + HANDLE cancelEvent = tp->cancelEvent; /* * Thread ID structs are never freed. They're NULLed and reused. - * This also sets the thread to PThreadStateInitial (invalid). + * This also sets the thread state to PThreadStateInitial before + * it is finally set to PThreadStateReuse. */ ptw32_threadReusePush (thread); - /* Now work on the copy. */ - if (threadCopy.cancelEvent != NULL) + if (cancelEvent != NULL) { - CloseHandle (threadCopy.cancelEvent); + CloseHandle (cancelEvent); } -#if ! defined(PTW32_CONFIG_MINGW) || defined (__MSVCRT__) || defined (__DMC__) +#if ! defined(__MINGW32__) || defined (__MSVCRT__) || defined (__DMC__) /* * See documentation for endthread vs endthreadex. */ - if (threadCopy.threadH != 0) + if (threadH != 0) { - CloseHandle (threadCopy.threadH); + CloseHandle (threadH); } #endif diff --git a/ptw32_threadStart.c b/ptw32_threadStart.c index cc19885b..b19a88da 100644 --- a/ptw32_threadStart.c +++ b/ptw32_threadStart.c @@ -19,17 +19,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., @@ -46,11 +46,11 @@ #include "implement.h" #include -#if defined(__CLEANUP_C) +#if defined(PTW32_CLEANUP_C) # include #endif -#if defined(__CLEANUP_SEH) +#if defined(PTW32_CLEANUP_SEH) static DWORD ExceptionFilter (EXCEPTION_POINTERS * ep, ULONG_PTR * ei) @@ -87,7 +87,7 @@ ExceptionFilter (EXCEPTION_POINTERS * ep, ULONG_PTR * ei) } } -#elif defined(__CLEANUP_CXX) +#elif defined(PTW32_CLEANUP_CXX) #if defined(_MSC_VER) # include @@ -106,7 +106,7 @@ using # endif #endif -#endif /* __CLEANUP_CXX */ +#endif /* PTW32_CLEANUP_CXX */ /* * MSVC6 does not optimize ptw32_threadStart() safely @@ -118,7 +118,7 @@ using # pragma optimize("g", off) #endif -#if ! defined (PTW32_CONFIG_MINGW) || (defined (__MSVCRT__) && ! defined (__DMC__)) +#if ! defined (__MINGW32__) || (defined (__MSVCRT__) && ! defined (__DMC__)) unsigned __stdcall #else @@ -132,12 +132,12 @@ ptw32_threadStart (void *vthreadParms) void * (PTW32_CDECL *start) (void *); void * arg; -#if defined(__CLEANUP_SEH) +#if defined(PTW32_CLEANUP_SEH) ULONG_PTR ei[] = { 0, 0, 0 }; #endif -#if defined(__CLEANUP_C) +#if defined(PTW32_CLEANUP_C) int setjmp_rc; #endif @@ -151,7 +151,7 @@ ptw32_threadStart (void *vthreadParms) free (threadParms); -#if ! defined (PTW32_CONFIG_MINGW) || defined (__MSVCRT__) || defined (__DMC__) +#if ! defined (__MINGW32__) || defined (__MSVCRT__) || defined (__DMC__) #else /* * _beginthread does not return the thread id and is running @@ -170,7 +170,7 @@ ptw32_threadStart (void *vthreadParms) sp->state = PThreadStateRunning; ptw32_mcs_lock_release (&stateLock); -#if defined(__CLEANUP_SEH) +#if defined(PTW32_CLEANUP_SEH) __try { @@ -219,9 +219,9 @@ ptw32_threadStart (void *vthreadParms) //(void)pthread_win32_thread_detach_np(); } -#else /* __CLEANUP_SEH */ +#else /* PTW32_CLEANUP_SEH */ -#if defined(__CLEANUP_C) +#if defined(PTW32_CLEANUP_C) setjmp_rc = setjmp (sp->start_mark); @@ -249,9 +249,9 @@ ptw32_threadStart (void *vthreadParms) } } -#else /* __CLEANUP_C */ +#else /* PTW32_CLEANUP_C */ -#if defined(__CLEANUP_CXX) +#if defined(PTW32_CLEANUP_CXX) try { @@ -286,11 +286,11 @@ ptw32_threadStart (void *vthreadParms) #error ERROR [__FILE__, line __LINE__]: Cleanup type undefined. -#endif /* __CLEANUP_CXX */ -#endif /* __CLEANUP_C */ -#endif /* __CLEANUP_SEH */ +#endif /* PTW32_CLEANUP_CXX */ +#endif /* PTW32_CLEANUP_C */ +#endif /* PTW32_CLEANUP_SEH */ -#if defined(PTW32_STATIC_LIB) +#if defined (PTW32_STATIC_LIB) /* * We need to cleanup the pthread now if we have * been statically linked, in which case the cleanup @@ -308,7 +308,7 @@ ptw32_threadStart (void *vthreadParms) (void) pthread_win32_thread_detach_np (); #endif -#if ! defined (PTW32_CONFIG_MINGW) || defined (__MSVCRT__) || defined (__DMC__) +#if ! defined (__MINGW32__) || defined (__MSVCRT__) || defined (__DMC__) _endthreadex ((unsigned)(size_t) status); #else _endthread (); @@ -318,7 +318,7 @@ ptw32_threadStart (void *vthreadParms) * Never reached. */ -#if ! defined (PTW32_CONFIG_MINGW) || defined (__MSVCRT__) || defined (__DMC__) +#if ! defined (__MINGW32__) || defined (__MSVCRT__) || defined (__DMC__) return (unsigned)(size_t) status; #endif @@ -331,7 +331,7 @@ ptw32_threadStart (void *vthreadParms) # pragma optimize("", on) #endif -#if defined (PTW32_USES_SEPARATE_CRT) && defined (__cplusplus) +#if defined (PTW32_USES_SEPARATE_CRT) && (defined(PTW32_CLEANUP_CXX) || defined(PTW32_CLEANUP_SEH)) ptw32_terminate_handler pthread_win32_set_terminate_np(ptw32_terminate_handler termFunction) { diff --git a/ptw32_throw.c b/ptw32_throw.c index 0f5f5ce8..1703b09d 100644 --- a/ptw32_throw.c +++ b/ptw32_throw.c @@ -45,31 +45,20 @@ #include "pthread.h" #include "implement.h" -#if defined(__CLEANUP_C) +#if defined(PTW32_CLEANUP_C) # include #endif /* * ptw32_throw * - * All canceled and explicitly exited POSIX threads go through + * All cancelled and explicitly exited POSIX threads go through * here. This routine knows how to exit both POSIX initiated threads and * 'implicit' POSIX threads for each of the possible language modes (C, * C++, and SEH). */ -#if defined(_MSC_VER) -/* - * Ignore the warning: - * "C++ exception specification ignored except to indicate that - * the function is not __declspec(nothrow)." - */ -#pragma warning(disable:4290) -#endif void ptw32_throw (DWORD exception) -#if defined(__CLEANUP_CXX) - throw(ptw32_exception_cancel,ptw32_exception_exit) -#endif { /* * Don't use pthread_self() to avoid creating an implicit POSIX thread handle @@ -77,7 +66,7 @@ ptw32_throw (DWORD exception) */ ptw32_thread_t * sp = (ptw32_thread_t *) pthread_getspecific (ptw32_selfThreadKey); -#if defined(__CLEANUP_SEH) +#if defined(PTW32_CLEANUP_SEH) ULONG_PTR exceptionInformation[3]; #endif if( sp ) @@ -97,7 +86,7 @@ ptw32_throw (DWORD exception) * explicit thread exit here after cleaning up POSIX * residue (i.e. cleanup handlers, POSIX thread handle etc). */ -#if ! defined (PTW32_CONFIG_MINGW) || defined (__MSVCRT__) || defined (__DMC__) +#if ! defined (__MINGW32__) || defined (__MSVCRT__) || defined (__DMC__) unsigned int exitCode = 0; switch (exception) @@ -120,7 +109,7 @@ ptw32_throw (DWORD exception) #endif -#if ! defined (PTW32_CONFIG_MINGW) || defined (__MSVCRT__) || defined (__DMC__) +#if ! defined (__MINGW32__) || defined (__MSVCRT__) || defined (__DMC__) _endthreadex (exitCode); #else _endthread (); @@ -128,7 +117,7 @@ ptw32_throw (DWORD exception) } -#if defined(__CLEANUP_SEH) +#if defined(PTW32_CLEANUP_SEH) exceptionInformation[0] = (ULONG_PTR) (exception); @@ -137,16 +126,16 @@ ptw32_throw (DWORD exception) RaiseException (EXCEPTION_PTW32_SERVICES, 0, 3, (ULONG_PTR *) exceptionInformation); -#else /* __CLEANUP_SEH */ +#else /* PTW32_CLEANUP_SEH */ -#if defined(__CLEANUP_C) +#if defined(PTW32_CLEANUP_C) ptw32_pop_cleanup_all (1); longjmp (sp->start_mark, exception); -#else /* __CLEANUP_C */ +#else /* PTW32_CLEANUP_C */ -#if defined(__CLEANUP_CXX) +#if defined(PTW32_CLEANUP_CXX) switch (exception) { @@ -162,11 +151,11 @@ ptw32_throw (DWORD exception) #error ERROR [__FILE__, line __LINE__]: Cleanup type undefined. -#endif /* __CLEANUP_CXX */ +#endif /* PTW32_CLEANUP_CXX */ -#endif /* __CLEANUP_C */ +#endif /* PTW32_CLEANUP_C */ -#endif /* __CLEANUP_SEH */ +#endif /* PTW32_CLEANUP_SEH */ /* Never reached */ } @@ -184,7 +173,7 @@ ptw32_pop_cleanup_all (int execute) DWORD ptw32_get_exception_services_code (void) { -#if defined(__CLEANUP_SEH) +#if defined(PTW32_CLEANUP_SEH) return EXCEPTION_PTW32_SERVICES; diff --git a/ptw32_timespec.c b/ptw32_timespec.c index d53206d3..3bd3b507 100644 --- a/ptw32_timespec.c +++ b/ptw32_timespec.c @@ -45,14 +45,11 @@ #include "pthread.h" #include "implement.h" - -#if defined(NEED_FTIME) - /* * time between jan 1, 1601 and jan 1, 1970 in units of 100 nanoseconds */ -#define PTW32_TIMESPEC_TO_FILETIME_OFFSET \ - ( ((int64_t) 27111902 << 32) + (int64_t) 3577643008 ) +#define PTW32_TIMESPEC_TO_FILETIME_OFFSET \ + ( ((uint64_t) 27111902UL << 32) + (uint64_t) 3577643008UL ) INLINE void ptw32_timespec_to_filetime (const struct timespec *ts, FILETIME * ft) @@ -65,8 +62,8 @@ ptw32_timespec_to_filetime (const struct timespec *ts, FILETIME * ft) * ------------------------------------------------------------------- */ { - *(int64_t *) ft = ts->tv_sec * 10000000 - + (ts->tv_nsec + 50) / 100 + PTW32_TIMESPEC_TO_FILETIME_OFFSET; + *(uint64_t *) ft = ts->tv_sec * 10000000UL + + (ts->tv_nsec + 50) / 100 + PTW32_TIMESPEC_TO_FILETIME_OFFSET; } INLINE void @@ -81,10 +78,8 @@ ptw32_filetime_to_timespec (const FILETIME * ft, struct timespec *ts) */ { ts->tv_sec = - (int) ((*(int64_t *) ft - PTW32_TIMESPEC_TO_FILETIME_OFFSET) / 10000000); + (int) ((*(uint64_t *) ft - PTW32_TIMESPEC_TO_FILETIME_OFFSET) / 10000000UL); ts->tv_nsec = - (int) ((*(int64_t *) ft - PTW32_TIMESPEC_TO_FILETIME_OFFSET - - ((int64_t) ts->tv_sec * (int64_t) 10000000)) * 100); + (int) ((*(uint64_t *) ft - PTW32_TIMESPEC_TO_FILETIME_OFFSET - + ((uint64_t) ts->tv_sec * (uint64_t) 10000000UL)) * 100); } - -#endif /* NEED_FTIME */ diff --git a/sched.h b/sched.h index 1779e11c..bad3353e 100644 --- a/sched.h +++ b/sched.h @@ -21,17 +21,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., @@ -42,144 +42,83 @@ #pragma once #if !defined(_SCHED_H) #define _SCHED_H +#define __SCHED_H_SOURCED__ -#if defined(_MSC_VER) -# if _MSC_VER < 1300 -# define PTW32_CONFIG_MSVC6 -# endif -# if _MSC_VER < 1400 -# define PTW32_CONFIG_MSVC7 -# endif -#endif - -#undef PTW32_SCHED_LEVEL - -#if defined(_POSIX_SOURCE) -#define PTW32_SCHED_LEVEL 0 -/* Early POSIX */ -#endif - -#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309 -#undef PTW32_SCHED_LEVEL -#define PTW32_SCHED_LEVEL 1 -/* Include 1b, 1c and 1d */ -#endif - -#if defined(INCLUDE_NP) -#undef PTW32_SCHED_LEVEL -#define PTW32_SCHED_LEVEL 2 -/* Include Non-Portable extensions */ -#endif +#include <_ptw32.h> -#define PTW32_SCHED_LEVEL_MAX 3 +/* We need a typedef for pid_t, (and POSIX requires to + * define it, as it is defined in , but it does NOT + * sanction exposure of everything from ); there is + * no pid_t in Windows anyway, (except that MinGW does define it + * in their ), so just provide a suitable typedef, + * but note that we must do so cautiously, to avoid a typedef + * conflict if MinGW's is also #included: + */ +#if ! defined __MINGW32__ || ! defined __have_typedef_pid_t -#if ( defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112 ) || !defined(PTW32_SCHED_LEVEL) -#undef PTW32_SCHED_LEVEL -#define PTW32_SCHED_LEVEL PTW32_SCHED_LEVEL_MAX -/* Include everything */ +# if defined __MINGW64__ + typedef __int64 pid_t; +# else + typedef int pid_t; #endif - -#if defined(__GNUC__) && !defined(__declspec) -# error Please upgrade your GNU compiler to one that supports __declspec. +#if __GNUC__ < 4 +/* GCC v4.0 and later, (as used by MinGW), allows us to repeat a + * typedef, provided every duplicate is consistent; only set this + * multiple definition guard when we cannot be certain that it is + * permissable to repeat typedefs. + */ +#define __have_typedef_pid_t 1 #endif - -#if defined(PTW32_STATIC_LIB) && defined(_MSC_VER) && _MSC_VER >= 1400 && defined(_WINDLL) -# undef PTW32_STATIC_LIB -# define PTW32_STATIC_TLSLIB #endif -/* - * When building the library, you should define PTW32_BUILD so that - * the variables/functions are exported correctly. When using the library, - * do NOT define PTW32_BUILD, and then the variables/functions will - * be imported correctly. +/* POSIX.1-1993 says that WILL expose all of */ -#if defined(PTW32_STATIC_LIB) || defined(PTW32_STATIC_TLSLIB) -# define PTW32_DLLPORT -#elif defined(PTW32_BUILD) -# define PTW32_DLLPORT __declspec (dllexport) -# else -# define PTW32_DLLPORT __declspec (dllimport) -# endif - -/* - * The Open Watcom C/C++ compiler uses a non-standard calling convention - * that passes function args in registers unless __cdecl is explicitly specified - * in exposed function prototypes. - * - * We force all calls to cdecl even though this could slow Watcom code down - * slightly. If you know that the Watcom compiler will be used to build both - * the DLL and application, then you can probably define this as a null string. - * Remember that sched.h (this file) is used for both the DLL and application builds. +#undef __SCHED_H_SOURCED__ +#if _POSIX_C_SOURCE >= 200112L +/* POSIX.1-2001 and later revises this to say only that it MAY do so; + * only struct timespec, and associated time_t are actually required, + * so prefer to be selective; (MinGW.org's offers an option + * for selective #inclusion, when __SCHED_H_SOURCED__ is defined): */ -#if !defined(PTW32_CDECL) -# define PTW32_CDECL __cdecl +#define __SCHED_H_SOURCED__ +#define __need_struct_timespec +#define __need_time_t #endif - -/* - * This is a duplicate of what is in the autoconf config.h, - * which is only used when building the pthread-win32 libraries. +#include + +#if defined __MINGW64__ || _MSC_VER >= 1900 +/* These are known to define struct timespec, when has been + * #included, but may not, (probably don't), follow the convention of + * defining __struct_timespec_defined, as adopted by MinGW.org; for + * these cases, we unconditionally assume that struct timespec has + * been defined, otherwise, if MinGW.org's criterion has not been + * satisfied... */ - -#if !defined(PTW32_CONFIG_H) -# if defined(WINCE) -# define NEED_ERRNO -# define NEED_SEM -# endif -# if defined(__MINGW64__) -# define HAVE_STRUCT_TIMESPEC -# define HAVE_MODE_T -# elif defined(_UWIN) || defined(__MINGW32__) -# define HAVE_MODE_T +#elif ! defined __struct_timespec_defined +# ifndef _TIMESPEC_DEFINED +# define _TIMESPEC_DEFINED +struct timespec +{ /* ...we fall back on this explicit definition. + */ + time_t tv_sec; + int tv_nsec; +}; # endif #endif -/* - * - */ - -#include - -#if PTW32_SCHED_LEVEL >= PTW32_SCHED_LEVEL_MAX -#if defined(NEED_ERRNO) -#include "need_errno.h" -#else -#include -#endif -#endif /* PTW32_SCHED_LEVEL >= PTW32_SCHED_LEVEL_MAX */ - -#if (defined(__MINGW64__) || defined(__MINGW32__)) || defined(_UWIN) -# if PTW32_SCHED_LEVEL >= PTW32_SCHED_LEVEL_MAX -/* For pid_t */ -# include -/* Required by Unix 98 */ -# include -# else - typedef int pid_t; -# endif -#else - /* [i_a] fix for using pthread_win32 with civetweb code, which #define's its own pid_t akin to typedef HANDLE pid_t; */ - #undef pid_t -# if defined(_MSC_VER) - // typedef void *pid_t; - typedef unsigned long pid_t; -# else - typedef int pid_t; -# endif -#endif - /* * Microsoft VC++6.0 lacks these *_PTR types */ -#if defined(_MSC_VER) && _MSC_VER < 1300 && !defined(PTW32_HAVE_DWORD_PTR) +#if defined(_MSC_VER) && _MSC_VER < 1300 && !defined (PTW32_HAVE_DWORD_PTR) typedef unsigned long ULONG_PTR; typedef ULONG_PTR DWORD_PTR; #endif /* Thread scheduling policies */ -enum { +enum +{ SCHED_OTHER = 0, SCHED_FIFO, SCHED_RR, @@ -187,18 +126,21 @@ enum { SCHED_MAX = SCHED_RR }; -struct sched_param { - int sched_priority; +struct sched_param +{ + int sched_priority; }; /* * CPU affinity * * cpu_set_t: - * Considered opaque but cannot be an opaque pointer - * due to the need for compatibility with GNU systems - * and sched_setaffinity() et.al. which include the - * cpusetsize parameter "normally set to sizeof(cpu_set_t)". + * Considered opaque but cannot be an opaque pointer due to the need for + * compatibility with GNU systems and sched_setaffinity() et.al., which + * include the cpusetsize parameter "normally set to sizeof(cpu_set_t)". + * + * FIXME: These are GNU, and NOT specified by POSIX; maybe consider + * occluding them within a _GNU_SOURCE (or similar) feature test. */ #define CPU_SETSIZE (sizeof(size_t)*8) @@ -217,78 +159,86 @@ struct sched_param { #define CPU_OR(destsetptr, srcset1ptr, srcset2ptr) (_sched_affinitycpuor((destsetptr),(srcset1ptr),(srcset2ptr))) -#define CPU_XOR(destsetptr, srcset1ptr, srcset2ptr) (_sched_affinitycpuxor((destsetptr),(srcset1ptr),(srcset2ptr))) +#define CPU_XOR(destsetptr, srcset1ptr, srcset2ptr) \ + (_sched_affinitycpuxor((destsetptr),(srcset1ptr),(srcset2ptr))) #define CPU_EQUAL(set1ptr, set2ptr) (_sched_affinitycpuequal((set1ptr),(set2ptr))) typedef union -{ - char cpuset[CPU_SETSIZE/8]; - size_t _align; +{ + char cpuset[CPU_SETSIZE/8]; + size_t _align; } cpu_set_t; -#if defined(__cplusplus) -extern "C" -{ -#endif /* __cplusplus */ - -PTW32_DLLPORT int PTW32_CDECL sched_yield (void); +PTW32_BEGIN_C_DECLS -PTW32_DLLPORT int PTW32_CDECL sched_get_priority_min (int policy); +PTW32_DLLPORT int PTW32_CDECL sched_yield (void); -PTW32_DLLPORT int PTW32_CDECL sched_get_priority_max (int policy); +PTW32_DLLPORT int PTW32_CDECL sched_get_priority_min (int policy); -PTW32_DLLPORT int PTW32_CDECL sched_setscheduler (pid_t pid, int policy); +PTW32_DLLPORT int PTW32_CDECL sched_get_priority_max (int policy); -PTW32_DLLPORT int PTW32_CDECL sched_getscheduler (pid_t pid); +/* FIXME: this declaration of sched_setscheduler() is NOT as prescribed + * by POSIX; it lacks const struct sched_param * as third argument. + */ +PTW32_DLLPORT int PTW32_CDECL sched_setscheduler (pid_t pid, int policy); -/* Compatibility with Linux - not standard */ +/* FIXME: In addition to the above five functions, POSIX also requires: + * + * int sched_getparam (pid_t, struct sched_param *); + * int sched_setparam (pid_t, const struct sched_param *); + * + * both of which are conspicuous by their absence here! + */ -PTW32_DLLPORT int PTW32_CDECL sched_setaffinity (pid_t pid, size_t cpusetsize, cpu_set_t *mask); +/* Compatibility with Linux - not standard in POSIX + * FIXME: consider occluding within a _GNU_SOURCE (or similar) feature test. + */ +PTW32_DLLPORT int PTW32_CDECL sched_setaffinity (pid_t pid, size_t cpusetsize, cpu_set_t *mask); -PTW32_DLLPORT int PTW32_CDECL sched_getaffinity (pid_t pid, size_t cpusetsize, cpu_set_t *mask); +PTW32_DLLPORT int PTW32_CDECL sched_getaffinity (pid_t pid, size_t cpusetsize, cpu_set_t *mask); /* * Support routines and macros for cpu_set_t */ -PTW32_DLLPORT int PTW32_CDECL _sched_affinitycpucount (const cpu_set_t *set); +PTW32_DLLPORT int PTW32_CDECL _sched_affinitycpucount (const cpu_set_t *set); -PTW32_DLLPORT void PTW32_CDECL _sched_affinitycpuzero (cpu_set_t *pset); +PTW32_DLLPORT void PTW32_CDECL _sched_affinitycpuzero (cpu_set_t *pset); -PTW32_DLLPORT void PTW32_CDECL _sched_affinitycpuset (int cpu, cpu_set_t *pset); +PTW32_DLLPORT void PTW32_CDECL _sched_affinitycpuset (int cpu, cpu_set_t *pset); -PTW32_DLLPORT void PTW32_CDECL _sched_affinitycpuclr (int cpu, cpu_set_t *pset); +PTW32_DLLPORT void PTW32_CDECL _sched_affinitycpuclr (int cpu, cpu_set_t *pset); -PTW32_DLLPORT int PTW32_CDECL _sched_affinitycpuisset (int cpu, const cpu_set_t *pset); +PTW32_DLLPORT int PTW32_CDECL _sched_affinitycpuisset (int cpu, const cpu_set_t *pset); -PTW32_DLLPORT void PTW32_CDECL _sched_affinitycpuand(cpu_set_t *pdestset, const cpu_set_t *psrcset1, const cpu_set_t *psrcset2); +PTW32_DLLPORT void PTW32_CDECL _sched_affinitycpuand(cpu_set_t *pdestset, const cpu_set_t *psrcset1, const cpu_set_t *psrcset2); -PTW32_DLLPORT void PTW32_CDECL _sched_affinitycpuor(cpu_set_t *pdestset, const cpu_set_t *psrcset1, const cpu_set_t *psrcset2); +PTW32_DLLPORT void PTW32_CDECL _sched_affinitycpuor(cpu_set_t *pdestset, const cpu_set_t *psrcset1, const cpu_set_t *psrcset2); -PTW32_DLLPORT void PTW32_CDECL _sched_affinitycpuxor(cpu_set_t *pdestset, const cpu_set_t *psrcset1, const cpu_set_t *psrcset2); +PTW32_DLLPORT void PTW32_CDECL _sched_affinitycpuxor(cpu_set_t *pdestset, const cpu_set_t *psrcset1, const cpu_set_t *psrcset2); -PTW32_DLLPORT int PTW32_CDECL _sched_affinitycpuequal (const cpu_set_t *pset1, const cpu_set_t *pset2); +PTW32_DLLPORT int PTW32_CDECL _sched_affinitycpuequal (const cpu_set_t *pset1, const cpu_set_t *pset2); -/* - * Note that this macro returns ENOTSUP rather than - * ENOSYS as might be expected. However, returning ENOSYS - * should mean that sched_get_priority_{min,max} are - * not implemented as well as sched_rr_get_interval. - * This is not the case, since we just don't support - * round-robin scheduling. Therefore I have chosen to - * return the same value as sched_setscheduler when - * SCHED_RR is passed to it. +/* Note that this macro returns ENOTSUP rather than ENOSYS, as + * might be expected. However, returning ENOSYS should mean that + * sched_get_priority_{min,max} are not implemented as well as + * sched_rr_get_interval. This is not the case, since we just + * don't support round-robin scheduling. Therefore I have chosen + * to return the same value as sched_setscheduler when SCHED_RR + * is passed to it. + * + * FIXME: POSIX requires this to be defined as a function; this + * macro implementation is permitted IN ADDITION to the function, + * but the macro alone is not POSIX compliant! Worse still, it + * imposes a requirement on the caller, to ensure that both the + * declaration of errno, and the definition of ENOTSUP, are in + * scope at point of call, (which it may wish to do anyway, but + * POSIX imposes no such constraint)! */ #define sched_rr_get_interval(_pid, _interval) \ ( errno = ENOTSUP, (int) -1 ) +PTW32_END_C_DECLS -#if defined(__cplusplus) -} /* End of extern "C" */ -#endif /* __cplusplus */ - -#undef PTW32_SCHED_LEVEL -#undef PTW32_SCHED_LEVEL_MAX - -#endif /* !_SCHED_H */ - +#undef __SCHED_H_SOURCED__ +#endif /* !_SCHED_H */ diff --git a/sched_setaffinity.c b/sched_setaffinity.c index 0736ee12..b851712b 100644 --- a/sched_setaffinity.c +++ b/sched_setaffinity.c @@ -18,17 +18,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/sem_destroy.c b/sem_destroy.c index 528f2844..99d0b350 100644 --- a/sem_destroy.c +++ b/sem_destroy.c @@ -25,17 +25,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/sem_getvalue.c b/sem_getvalue.c index 263b2da8..5778114c 100644 --- a/sem_getvalue.c +++ b/sem_getvalue.c @@ -25,17 +25,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/sem_init.c b/sem_init.c index 1ef78e64..d80568df 100644 --- a/sem_init.c +++ b/sem_init.c @@ -23,17 +23,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/sem_open.c b/sem_open.c index 17c64233..b6c2f956 100644 --- a/sem_open.c +++ b/sem_open.c @@ -57,9 +57,14 @@ #pragma warning( disable : 4100 ) #endif -int -sem_open (const char *name, int oflag, mode_t mode, unsigned int value) +sem_t +*sem_open (const char *name, int oflag, ...) { + /* Note: this is a POSIX.1b-1993 conforming stub; POSIX.1-2001 removed + * the requirement to provide this stub, and also removed the validity + * of ENOSYS as a resultant errno state; nevertheless, it makes sense + * to retain the POSIX.1b-1993 conforming behaviour here. + */ PTW32_SET_ERRNO(ENOSYS); - return -1; + return SEM_FAILED; } /* sem_open */ diff --git a/sem_post.c b/sem_post.c index 082820a3..eed9568e 100644 --- a/sem_post.c +++ b/sem_post.c @@ -25,17 +25,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/sem_post_multiple.c b/sem_post_multiple.c index 1f6b375f..10959714 100644 --- a/sem_post_multiple.c +++ b/sem_post_multiple.c @@ -25,17 +25,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/sem_timedwait.c b/sem_timedwait.c index 1bcc4ca6..899d2437 100644 --- a/sem_timedwait.c +++ b/sem_timedwait.c @@ -25,17 +25,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., @@ -183,7 +183,7 @@ sem_timedwait (sem_t * sem, const struct timespec *abstime) cleanup_args.sem = s; cleanup_args.resultPtr = &result; -#if defined(PTW32_CONFIG_MSVC7) +#if defined (PTW32_CONFIG_MSVC7) #pragma inline_depth(0) #endif /* Must wait */ @@ -193,7 +193,7 @@ sem_timedwait (sem_t * sem, const struct timespec *abstime) #endif result = pthreadCancelableTimedWait (s->sem, milliseconds); pthread_cleanup_pop(result); -#if defined(PTW32_CONFIG_MSVC7) +#if defined (PTW32_CONFIG_MSVC7) #pragma inline_depth() #endif diff --git a/sem_trywait.c b/sem_trywait.c index 6f4a3a4d..3f3ed625 100644 --- a/sem_trywait.c +++ b/sem_trywait.c @@ -25,17 +25,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/sem_wait.c b/sem_wait.c index 04fafd76..d4a587c0 100644 --- a/sem_wait.c +++ b/sem_wait.c @@ -25,17 +25,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., @@ -53,7 +53,7 @@ #include "implement.h" -static void PTW32_CDECL +static void PTW32_CDECL ptw32_sem_wait_cleanup(void * sem) { sem_t s = (sem_t) sem; @@ -129,7 +129,7 @@ sem_wait (sem_t * sem) if (v < 0) { -#if defined(PTW32_CONFIG_MSVC7) +#if defined (PTW32_CONFIG_MSVC7) #pragma inline_depth(0) #endif /* Must wait */ @@ -137,7 +137,7 @@ sem_wait (sem_t * sem) result = pthreadCancelableWait (s->sem); /* Cleanup if we're canceled or on any other error */ pthread_cleanup_pop(result); -#if defined(PTW32_CONFIG_MSVC7) +#if defined (PTW32_CONFIG_MSVC7) #pragma inline_depth() #endif } @@ -159,7 +159,7 @@ sem_wait (sem_t * sem) if (result != 0) { - PTW32_SET_ERRNO(result); + PTW32_SET_ERRNO(result); return -1; } diff --git a/semaphore.h b/semaphore.h index 22fce961..3916d986 100644 --- a/semaphore.h +++ b/semaphore.h @@ -21,17 +21,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., @@ -43,138 +43,80 @@ #if !defined( SEMAPHORE_H ) #define SEMAPHORE_H -#undef PTW32_SEMAPHORE_LEVEL - -#if defined(_POSIX_SOURCE) -#define PTW32_SEMAPHORE_LEVEL 0 -/* Early POSIX */ -#endif - -#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309 -#undef PTW32_SEMAPHORE_LEVEL -#define PTW32_SEMAPHORE_LEVEL 1 -/* Include 1b, 1c and 1d */ -#endif - -#if defined(INCLUDE_NP) -#undef PTW32_SEMAPHORE_LEVEL -#define PTW32_SEMAPHORE_LEVEL 2 -/* Include Non-Portable extensions */ -#endif - -#define PTW32_SEMAPHORE_LEVEL_MAX 3 - -#if !defined(PTW32_SEMAPHORE_LEVEL) -#define PTW32_SEMAPHORE_LEVEL PTW32_SEMAPHORE_LEVEL_MAX -/* Include everything */ -#endif - -#if defined(__GNUC__) && ! defined (__declspec) -# error Please upgrade your GNU compiler to one that supports __declspec. -#endif - -#if defined(PTW32_STATIC_LIB) && defined(_MSC_VER) && _MSC_VER >= 1400 && defined(_WINDLL) -# undef PTW32_STATIC_LIB -# define PTW32_STATIC_TLSLIB -#endif - -/* - * When building the library, you should define PTW32_BUILD so that - * the variables/functions are exported correctly. When using the library, - * do NOT define PTW32_BUILD, and then the variables/functions will - * be imported correctly. +/* FIXME: POSIX.1 says that _POSIX_SEMAPHORES should be defined + * in , not here; for later POSIX.1 versions, its value + * should match the corresponding _POSIX_VERSION number, but in + * the case of POSIX.1b-1993, the value is unspecified. + * + * Notwithstanding the above, since POSIX semaphores, (and indeed + * having any to #include), are not a standard feature + * on MS-Windows, it is convenient to retain this definition here; + * we may consider adding a hook, to make it selectively available + * for inclusion by , in those cases (e.g. MinGW) where + * is provided. */ -#if defined(PTW32_STATIC_LIB) || defined(PTW32_STATIC_TLSLIB) -# define PTW32_DLLPORT -#elif defined(PTW32_BUILD) -# define PTW32_DLLPORT __declspec (dllexport) -# else -# define PTW32_DLLPORT __declspec (dllimport) -# endif - -#if !defined(PTW32_CDECL) -# define PTW32_CDECL __cdecl -#endif +#define _POSIX_SEMAPHORES -/* - * This is a duplicate of what is in the autoconf config.h, - * which is only used when building the pthread-win32 libraries. +/* Internal macros, common to the public interfaces for various + * pthreads-win32 components, are defined in <_ptw32.h>; we must + * include them here. */ +#include <_ptw32.h> -#if !defined(PTW32_CONFIG_H) -# if defined(WINCE) -# define NEED_ERRNO -# define NEED_SEM -# endif -# if defined(__MINGW64__) -# define HAVE_STRUCT_TIMESPEC -# define HAVE_MODE_T -# elif defined(_UWIN) || defined(__MINGW32__) -# define HAVE_MODE_T -# endif -#endif - -/* - * +/* The sem_timedwait() function was added in POSIX.1-2001; it + * requires struct timespec to be defined, at least as a partial + * (a.k.a. incomplete) data type. Forward declare it as such, + * then include selectively, to acquire a complete + * definition, (if available). */ +struct timespec; +#define __need_struct_timespec +#include -#if PTW32_SEMAPHORE_LEVEL >= PTW32_SEMAPHORE_LEVEL_MAX -#if defined(NEED_ERRNO) -#include "need_errno.h" -#else -#include -#endif -#endif /* PTW32_SEMAPHORE_LEVEL >= PTW32_SEMAPHORE_LEVEL_MAX */ - -#define _POSIX_SEMAPHORES - -#if defined(__cplusplus) -extern "C" -{ -#endif /* __cplusplus */ - -#if !defined(HAVE_MODE_T) -typedef unsigned int mode_t; -#endif +/* The data type used to represent our semaphore implementation, + * as required by POSIX.1; FIXME: consider renaming the underlying + * structure tag, to avoid possible pollution of user namespace. + */ +typedef struct sem_t_ * sem_t; +/* POSIX.1b (and later) mandates SEM_FAILED as the value to be + * returned on failure of sem_open(); (our implementation is a + * stub, which will always return this). + */ +#define SEM_FAILED (sem_t *)(-1) -typedef struct sem_t_ * sem_t; +PTW32_BEGIN_C_DECLS -PTW32_DLLPORT int PTW32_CDECL sem_init (sem_t * sem, +/* Function prototypes: some are implemented as stubs, which + * always fail; (FIXME: identify them). + */ +PTW32_DLLPORT int PTW32_CDECL sem_init (sem_t * sem, int pshared, unsigned int value); -PTW32_DLLPORT int PTW32_CDECL sem_destroy (sem_t * sem); +PTW32_DLLPORT int PTW32_CDECL sem_destroy (sem_t * sem); -PTW32_DLLPORT int PTW32_CDECL sem_trywait (sem_t * sem); +PTW32_DLLPORT int PTW32_CDECL sem_trywait (sem_t * sem); -PTW32_DLLPORT int PTW32_CDECL sem_wait (sem_t * sem); +PTW32_DLLPORT int PTW32_CDECL sem_wait (sem_t * sem); -PTW32_DLLPORT int PTW32_CDECL sem_timedwait (sem_t * sem, +PTW32_DLLPORT int PTW32_CDECL sem_timedwait (sem_t * sem, const struct timespec * abstime); -PTW32_DLLPORT int PTW32_CDECL sem_post (sem_t * sem); +PTW32_DLLPORT int PTW32_CDECL sem_post (sem_t * sem); -PTW32_DLLPORT int PTW32_CDECL sem_post_multiple (sem_t * sem, +PTW32_DLLPORT int PTW32_CDECL sem_post_multiple (sem_t * sem, int count); -PTW32_DLLPORT int PTW32_CDECL sem_open (const char * name, - int oflag, - mode_t mode, - unsigned int value); +PTW32_DLLPORT sem_t * PTW32_CDECL sem_open (const char *, int, ...); -PTW32_DLLPORT int PTW32_CDECL sem_close (sem_t * sem); +PTW32_DLLPORT int PTW32_CDECL sem_close (sem_t * sem); -PTW32_DLLPORT int PTW32_CDECL sem_unlink (const char * name); +PTW32_DLLPORT int PTW32_CDECL sem_unlink (const char * name); -PTW32_DLLPORT int PTW32_CDECL sem_getvalue (sem_t * sem, +PTW32_DLLPORT int PTW32_CDECL sem_getvalue (sem_t * sem, int * sval); -#if defined(__cplusplus) -} /* End of extern "C" */ -#endif /* __cplusplus */ - -#undef PTW32_SEMAPHORE_LEVEL -#undef PTW32_SEMAPHORE_LEVEL_MAX +PTW32_END_C_DECLS #endif /* !SEMAPHORE_H */ diff --git a/tests/Bmakefile b/tests/Bmakefile index 7f8b5bfc..42a3c83a 100644 --- a/tests/Bmakefile +++ b/tests/Bmakefile @@ -13,7 +13,7 @@ # in the file CONTRIBUTORS included with the source # code distribution. The list can also be seen at the # following World Wide Web location: -# http://sources.redhat.com/pthreads-win32/contributors.html +# http://sources.redhat.com/pthreads-win32contributors.html # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -31,7 +31,7 @@ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA # -DLL_VER = 2 +PTW32_VER = 3 CP = copy RM = erase @@ -50,15 +50,15 @@ OPTIM = -O2 XXLIBS = cw32mti.lib ws2_32.lib # C++ Exceptions -BCEFLAGS = -P -DPtW32NoCatchWarn -D__CLEANUP_CXX -BCELIB = pthreadBCE$(DLL_VER).lib -BCEDLL = pthreadBCE$(DLL_VER).dll +BCEFLAGS = -P -D__PtW32NoCatchWarn -DPTW32_CLEANUP_CXX +BCELIB = pthreadBCE$(PTW32_VER).lib +BCEDLL = pthreadBCE$(PTW32_VER).dll # C cleanup code -BCFLAGS = -D__CLEANUP_C -BCLIB = pthreadBC$(DLL_VER).lib -BCDLL = pthreadBC$(DLL_VER).dll +BCFLAGS = -DPTW32_CLEANUP_C +BCLIB = pthreadBC$(PTW32_VER).lib +BCDLL = pthreadBC$(PTW32_VER).dll # C++ Exceptions in application - using VC version of pthreads dll -BCXFLAGS = -D__CLEANUP_C +BCXFLAGS = -DPTW32_CLEANUP_C # Defaults CPLIB = $(BCLIB) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 00000000..3ce0ec88 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,80 @@ + +include (CTest) + +include_directories(..) + +set(XXLIBS ws2_32.lib) + +set(VCEFLAGS "${VCEFLAGS} -D__PtW32NoCatchWarn") + +macro(add_testcase test type def) + + set(lib_test test-${test}${type}${PTW32_VER}) + set(dll_test test-dll-${test}${type}${PTW32_VER}) + + set(lib_lib libpthread${type}${PTW32_VER}) + set(dll_lib pthread${type}${PTW32_VER}) + + set(c_dep "") + if(${test} MATCHES "benchtest") + set(c_dep "benchlib.c") + endif() + + set(extra "") + if(${test} MATCHES "openmp1") + if(MSVC) + set(extra "/openmp -D_OPENMP") + endif() + endif() + + add_executable(${lib_test} ${test}.c ${c_dep}) + target_link_libraries(${lib_test} ${lib_lib} ${XXLIBS}) + target_compile_definitions(${lib_test} PUBLIC "/nologo -D_CONSOLE -D_MBCS -D${def} ${extra}") + add_dependencies(${lib_test} ${lib_lib}) + + add_executable(${dll_test} ${test}.c ${c_dep}) + target_link_libraries(${dll_test} ${dll_lib} ${XXLIBS}) + target_compile_definitions(${dll_test} PUBLIC "/nologo -D_CONSOLE -D_MBCS -D${def} ${extra}") + add_dependencies(${dll_test} ${dll_lib}) + + if(${CMAKE_GENERATOR} MATCHES "Visual Studio") + install(FILES ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/tests/${lib_test}.exe DESTINATION ${TESTDEST}) + install(FILES ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/tests/${dll_test}.exe DESTINATION ${TESTDEST}) + else() + install(FILES ${CMAKE_BINARY_DIR}/tests/${lib_test}.exe DESTINATION ${TESTDEST}) + install(FILES ${CMAKE_BINARY_DIR}/tests/${dll_test}.exe DESTINATION ${TESTDEST}) + endif() + + if(${type} MATCHES "VCE") + set_target_properties(${lib_test} PROPERTIES COMPILE_FLAGS ${VCEFLAGS}) + set_target_properties(${dll_test} PROPERTIES COMPILE_FLAGS ${VCEFLAGS}) + endif() + + add_test(NAME ${lib_test} COMMAND ${lib_test}) + add_test(NAME ${dll_test} COMMAND ${dll_test}) + +endmacro() + + +file(GLOB TESTS *.c) + +foreach(t ${TESTS}) + + get_filename_component(test ${t} NAME) + string(REPLACE ".c" "" test "${test}") + + # exclusions + if(${test} STREQUAL "benchlib") + list(REMOVE_ITEM TESTS ${t}) + continue() + elseif(${test} STREQUAL "context2") # SEGFAULT + continue() + elseif(${test} STREQUAL "tryentercs2") # SEGFAULT + continue() + endif() + + add_testcase(${test} VCE PTW32_CLEANUP_CXX ) + add_testcase(${test} VSE PTW32_CLEANUP_SEH ) + add_testcase(${test} VC PTW32_CLEANUP_C ) + +endforeach(t) diff --git a/tests/ChangeLog b/tests/ChangeLog index 80f732c8..00658950 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,127 @@ +2018-08-19 Ross Johnson + + * threestage.c: Delete. + * rwlock7.c: Delete. + * rwlock8.c: Delete. + * rwlock7_1.c: Delete. + * rwlock8_1.c: Delete. + +2018-08-10 Ross Johnson + + * Makefile (clean): remove *.idb files. + +2018-08-07 Ross Johnson + + * GNUmakefile.in (DLL_VER): rename as PTW32_VER. + * Makefile (DLL_VER): Likewise. + * Bmakefile (DLL_VER): Likewise; does anyone use this anymore? + * Makefile: Variable renaming: e.g. VCLIB to VCIMP for DLL import + library pthreadVC2.lib and VCLIB now holds static library name + libpthreadVC2.lib, and similar for the other cleanup method versions. + * equal0.c: New test. If this test fails, the library's process init + routines have likely not been invoked or failed. + * common.mk: Add new test. + * runorder.mk: Likewise. + +2018-07-22 Mark Pizzolato + + * Makefile: Change the various static test runs to actually + compile with /MT or /MTd, i.e. No mixed /MT and /MD. Static + builds no longer create a separate pthreads*.lib static library + because errno does not work across that linkage. + * sequence1.c: Use more reasonable number of threads to avoid + resource limits. + +2016-12-25 Ross Johnson + + * Change all license notices to the Apache License 2.0 + +2016-12-21 Ross Johnson + + * mutex6.c: fix random failures by using a polling loop to replace + a single Sleep(). + * mutex6n.c: Likewise. + * mutex6s.c: Likewise. + * mutex7.c: Likewise. + * mutex7n.c: Likewise. + * mutex8.c: Likewise + * mutex8n.c: Likewise. + * semaphore5.c: don't fail on expected sem_destroy EBUSY. + +2016-12-20 Ross Johnson + + * all (PTW32_*): rename to PTW32_*. + (ptw32_*): rename to ptw32_*. + (PtW32*): rename to __PtW32*. + * GNUmakefile: removed; must now configure from GNUmakefile.in. + +2016-12-18 Ross Johnson + + * test.c (PTW32_TEST_SNEAK_PEEK): #define this to prevent some + tests from failing (specifically "make GCX-small-static") with + undefined ptw32_autostatic_anchor. Checked in ../implement.h. + * GNUMakfile.in: Rename testsuite log to test-specific name and + do not remove. + * GNUMakfile.in: Add realclean target + +2016-04-30 Ross Johnson + + * semaphore4t.c: No longer need to include ptw32_timespec.c and the + defines that tried to make it work (but failed). There is now an + exported routine that this test uses that can also be used by + applications. It's a general routine that keeps all the platform + conditional stuff inside the library. + * Makefile: Remove _ptw32.h copied from parent directory. + +2016-03-31 Ross Johnson + + * Makefile (_ptw32.h): Copy header to tests directory required to + build tests, and apps. + +2016-03-31 Ross Johnson + + * test.h: source errno.h + +2016-03-31 Keith Marshall + + * test.h: Patch for MinGW32 autoconf. + * GNUmakefile.in: New for autoconf. + +2016-03-28 Ross Johnson + + * condvar2.c: Use platform-aware pthread_win32_getabstime_np. + * condvar2_1.c: Likewise. + * condvar3.c: Likewise. + * condvar3_1.c: Likewise. + * condvar3_2.c: Likewise. + * condvar3_3.c: Likewise. + * condvar4.c: Likewise. + * condvar5.c: Likewise. + * condvar6.c: Likewise. + * condvar7.c: Likewise. + * condvar8.c: Likewise. + * condvar9.c: Likewise. + * join4.c: Likewise. + * mutex8.c: Likewise. + * mutex8e.c: Likewise. + * mutex8n.c: Likewise. + * mutex8r.c: Likewise. + * reinit1.c: Likewise. + * rwlock2_t.c: Likewise. + * rwlock3_t.c: Likewise. + * rwlock4_t.c: Likewise. + * rwlock5_t.c: Likewise. + * rwlock6_t.c: Likewise. + * rwlock6_t2.c: Likewise. + * semaphore4t.c: Likewise. + * stress1.c: Likewise. + * reinit1.c: Remove unused variable declarations. + +2015-11-01 Mark Smith + + * semaphore4t.c: Enhanced and additional testing of sub-millisecond + timeouts. + 2014-07-22 Scott Libert * semaphore3.c: Wait for threads to complete before exiting main(). @@ -857,7 +981,7 @@ * rwlock6.c: Fix casts. - * exception1.c (PtW32CatchAll): Had the wrong name; + * exception1.c (__PtW32CatchAll): Had the wrong name; fix casts. * cancel3.c: Remove unused waitLock variable. @@ -929,9 +1053,9 @@ 2000-08-05 Ross Johnson - * cancel2.c: Use PtW32CatchAll macro if defined. + * cancel2.c: Use __PtW32CatchAll macro if defined. - * exception1.c: Use PtW32CatchAll macro if defined. + * exception1.c: Use __PtW32CatchAll macro if defined. 2000-08-02 Ross Johnson diff --git a/tests/GNUmakefile.in b/tests/GNUmakefile.in new file mode 100644 index 00000000..c6a63610 --- /dev/null +++ b/tests/GNUmakefile.in @@ -0,0 +1,272 @@ +# Makefile for the pthreads test suite. +# If all of the .pass files can be created, the test suite has passed. +# +# -------------------------------------------------------------------------- +# +# pthreads-win32 / pthreads4w - POSIX Threads for Windows +# Copyright 1998 John E. Bossom +# Copyright(C) 1999-2021 pthreads-win32 / pthreads4w contributors +# +# Homepage: http://sources.redhat.com/pthreads-win32 +# +# The current list of contributors is contained +# in the file CONTRIBUTORS included with the source +# code distribution. The list can also be seen at the +# following World Wide Web location: +# +# https://sourceforge.net/p/pthreads4w/wiki/Contributors/ +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library in the file COPYING.LIB; +# if not, write to the Free Software Foundation, Inc., +# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA +# +# -------------------------------------------------------------------------- +# +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ + +LOGFILE = testsuite.log + +builddir = @builddir@ +top_builddir = @top_builddir@ + +PTW32_VER = 3$(EXTRAVERSION) + +CP = cp -f +MV = mv -f +RM = rm -f +CAT = cat +GREP = grep +WC = wc +TEE = tee +MKDIR = mkdir +ECHO = echo +TOUCH = $(ECHO) Passed > +TESTFILE = test -f +TESTDIR = test -d +AND = && + +# For cross compiling use e.g. +# # make CROSS=i386-mingw32msvc- clean GC +#CROSS = + +# For cross testing use e.g. +# # make RUN=wine CROSS=i386-mingw32msvc- clean GC +RUN = + +AR = $(CROSS)@AR@ +DLLTOOL = $(CROSS)@DLLTOOL@ +CC = $(CROSS)@CC@ +CXX = $(CROSS)@CXX@ +RANLIB = $(CROSS)@RANLIB@ + +# +# Mingw +# +XLIBS = +XXCFLAGS= +XXLIBS = +OPT = -O3 +DOPT = -g -O0 +CFLAGS = ${OPT} $(ARCH) -UNDEBUG -Wall -Wno-missing-braces $(XXCFLAGS) +LFLAGS = $(ARCH) $(XXLFLAGS) +# +# Uncomment this next to link the GCC/C++ runtime libraries statically +# (Be sure to read about these options and their associated caveats +# at http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html) +# +# NOTE 1: Doing this appears to break GCE:pthread_cleanup_*(), which +# relies on C++ class destructors being called when leaving scope. +# +# NOTE 2: If you do this DO NOT distribute your pthreads DLLs with +# the official filenaming, i.e. pthreadVC2.dll, etc. Instead, change PTW32_VER +# above to "2slgcc" for example, to build "pthreadGC2slgcc.dll", etc. +# +#LFLAGS += -static-libgcc -static-libstdc++ + +BUILD_DIR = .. +INCLUDES = -I ${top_srcdir} + +TEST = GC + +# Default lib version +GCX = GC$(PTW32_VER) + +# Files we need to run the tests +# - paths are relative to pthreads build dir. +HDR = pthread.h semaphore.h sched.h +LIB = libpthread$(GCX).a +DLL = pthread$(GCX).dll +# The next path is relative to $BUILD_DIR +QAPC = # ../QueueUserAPCEx/User/quserex.dll + +include ${srcdir}/common.mk + +.INTERMEDIATE: $(ALL_KNOWN_TESTS:%=%.exe) $(BENCHTESTS:%=%.exe) +.SECONDARY: $(ALL_KNOWN_TESTS:%=%.exe) $(ALL_KNOWN_TESTS:%=%.pass) $(BENCHTESTS:%=%.exe) $(BENCHTESTS:%=%.bench) +.PRECIOUS: $(ALL_KNOWN_TESTS:%=%.exe) $(ALL_KNOWN_TESTS:%=%.pass) $(BENCHTESTS:%=%.exe) $(BENCHTESTS:%=%.bench) + +ASM = $(ALL_KNOWN_TESTS:%=%.s) +TESTS = $(ALL_KNOWN_TESTS) +BENCHRESULTS = $(BENCHTESTS:%=%.bench) + +# +# To build and run "foo.exe" and "bar.exe" only use, e.g.: +# make clean GC NO_DEPS=1 TESTS="foo bar" +# +# To build and run "foo.exe" and "bar.exe" and run all prerequisite tests +# use, e.g.: +# make clean GC TESTS="foo bar" +# +# Set TESTS to one or more tests. +# +ifndef NO_DEPS +include ${srcdir}/runorder.mk +endif + +help: + @ $(ECHO) "Run one of the following command lines:" + @ $(ECHO) "$(MAKE) clean GC (to test using GC dll with C (no EH) applications)" + @ $(ECHO) "$(MAKE) clean GCX (to test using GC dll with C++ (EH) applications)" + @ $(ECHO) "$(MAKE) clean GCE (to test using GCE dll with C++ (EH) applications)" + @ $(ECHO) "$(MAKE) clean GC-bench (to benchtest using GNU C dll with C cleanup code)" + @ $(ECHO) "$(MAKE) clean GC-debug (to test using GC dll with C (no EH) applications)" + @ $(ECHO) "$(MAKE) clean GC-static (to test using GC static lib with C (no EH) applications)" + @ $(ECHO) "$(MAKE) clean GC-static-debug (to test using GC static lib with C (no EH) applications)" + @ $(ECHO) "$(MAKE) clean GCE-static (to test using GC static lib with C (no EH) applications)" + @ $(ECHO) "$(MAKE) clean GCE-static-debug (to test using GC static lib with C (no EH) applications)" + @ $(ECHO) "$(MAKE) clean GCE-debug (to test using GCE dll with C++ (EH) applications)" + @ $(ECHO) "$(MAKE) clean GCX-static (to test using GC static lib with C++ applications)" + @ $(ECHO) "$(MAKE) clean GCX-static-debug (to test using GC static lib with C++ applications)" + @ $(ECHO) "$(MAKE) clean GCX-debug (to test using GCE dll with C++ (EH) applications)" + @ $(ECHO) "$(MAKE) clean GC TESTS="foo bar" (to build individual tests \"foo.c and bar.c\" with C and run using GC dll)" + +GC: + @ $(MAKE) --no-builtin-rules TEST=$@ GCX="GC$(PTW32_VER)" CC=$(CC) XXCFLAGS="-DPTW32_CLEANUP_C" allpassed + +GC-asm: + @ $(MAKE) --no-builtin-rules TEST=$@ GCX="GC$(PTW32_VER)" CC=$(CC) XXCFLAGS="-DPTW32_CLEANUP_C" all-asm + +GC-bench: + @ $(MAKE) --no-builtin-rules TEST=$@ GCX="GC$(PTW32_VER)" CC=$(CC) XXCFLAGS="-DPTW32_CLEANUP_C" XXLIBS="benchlib.o" all-bench + +GC-bench-debug: + @ $(MAKE) --no-builtin-rules TEST=$@ GCX="GC$(PTW32_VER)d" CC=$(CC) XXCFLAGS="-DPTW32_CLEANUP_C" XXLIBS="benchlib.o" OPT="${DOPT}" all-bench + +GC-debug: + @ $(MAKE) --no-builtin-rules TEST=$@ GCX="GC$(PTW32_VER)d" CC=$(CC) XXCFLAGS="-DPTW32_CLEANUP_C" OPT="${DOPT}" allpassed + +GC-static GC-small-static: + @ $(MAKE) --no-builtin-rules TEST=$@ GCX="GC$(PTW32_VER)" CC=$(CC) XXCFLAGS="-DPTW32_CLEANUP_C -DPTW32_STATIC_LIB -Wl,-Bstatic" DLL="" allpassed + +GC-static-debug GC-small-static-debug: + @ $(MAKE) --no-builtin-rules TEST=$@ GCX="GC$(PTW32_VER)d" CC=$(CC) XXCFLAGS="-DPTW32_CLEANUP_C -DPTW32_STATIC_LIB -Wl,-Bstatic" OPT="$(DOPT)" DLL="" allpassed + +GCE: + @ $(MAKE) --no-builtin-rules TEST=$@ GCX="GCE$(PTW32_VER)" CC=$(CXX) XXCFLAGS="-mthreads -DPTW32_CLEANUP_CXX" allpassed + +GCE-debug: + @ $(MAKE) --no-builtin-rules TEST=$@ GCX="GCE$(PTW32_VER)d" CC=$(CXX) XXCFLAGS="-DPTW32_CLEANUP_CXX" OPT="${DOPT}" allpassed + +GCE-static GCE-small-static: + @ $(MAKE) --no-builtin-rules TEST=$@ GCX="GCE$(PTW32_VER)" CC=$(CXX) XXCFLAGS="-DPTW32_CLEANUP_CXX -DPTW32_STATIC_LIB -Wl,-Bstatic" DLL="" allpassed + +GCE-static-debug GCE-small-static-debug: + @ $(MAKE) --no-builtin-rules TEST=$@ GCX="GCE$(PTW32_VER)d" CC=$(CXX) XXCFLAGS="-DPTW32_CLEANUP_CXX -DPTW32_STATIC_LIB -Wl,-Bstatic" OPT="$(DOPT)" DLL="" allpassed + +GCX: + @ $(MAKE) --no-builtin-rules TEST=$@ GCX="GC$(PTW32_VER)" CC=$(CXX) XXCFLAGS="-mthreads -DPTW32_CLEANUP_C" allpassed + +GCX-debug: + @ $(MAKE) --no-builtin-rules TEST=$@ GCX="GC$(PTW32_VER)d" CC=$(CXX) XXCFLAGS="-DPTW32_CLEANUP_C" OPT="${DOPT}" allpassed + +GCX-static GCX-small-static: + @ $(MAKE) --no-builtin-rules TEST=$@ GCX="GC$(PTW32_VER)" CC=$(CXX) XXCFLAGS="-DPTW32_CLEANUP_C -DPTW32_STATIC_LIB -Wl,-Bstatic" DLL="" allpassed + +GCX-static-debug GCX-small-static-debug: + @ $(MAKE) --no-builtin-rules TEST=$@ GCX="GC$(PTW32_VER)d" CC=$(CXX) XXCFLAGS="-DPTW32_CLEANUP_C -DPTW32_STATIC_LIB -Wl,-Bstatic" OPT="$(DOPT)" DLL="" allpassed + +all-asm: $(ASM) + @ $(ECHO) "ALL TESTS COMPILED TO ASSEMBLER CODE" + +allpassed: $(HDR) $(LIB) $(DLL) $(QAPC) $(TESTS:%=%.pass) + @ $(ECHO) "ALL TESTS COMPLETED. Check the logfile: $(LOGFILE)" + @ $(ECHO) "FAILURES: $$( $(GREP) FAILED $(LOGFILE) | $(WC) -l ) " + @ - ! $(GREP) FAILED $(LOGFILE) + @ $(MV) $(LOGFILE) ../$(TEST)-$(LOGFILE) + +all-bench: $(HDR) $(LIB) $(DLL) $(QAPC) $(XXLIBS) $(BENCHRESULTS) + @ $(ECHO) "ALL BENCH TESTS COMPLETED. Check the logfile: $(LOGFILE)" + @ $(ECHO) "FAILURES: $$( $(GREP) FAILED $(LOGFILE) | $(WC) -l ) " + @ - ! $(GREP) FAILED $(LOGFILE) + @ $(MV) $(LOGFILE) ../$(TEST)-$(LOGFILE) + +cancel9.exe: XLIBS = -lws2_32 + +%.pass: %.exe + @ $(ECHO) Running $(TEST) test \"$*\" | tee -a $(LOGFILE) + @ (PATH=${top_builddir}:$$PATH $(RUN) ./$* \ + && { $(ECHO) Passed; $(TOUCH) $@; } || { $(ECHO) FAILED: $* ; $(ECHO) ; } ) \ + 2>&1 | tee -a $(LOGFILE) + +%.bench: %.exe + @ $(ECHO) Running $(TEST) test \"$*\" | tee -a $(LOGFILE) + @ (PATH=${top_builddir}:$$PATH $(RUN) ./$* \ + && { $(ECHO) Done; $(TOUCH) $@; } || { $(ECHO) FAILED ; $(ECHO) ; } ) \ + 2>&1 | tee -a $(LOGFILE) + +%.exe: %.c + $(CC) $(CFLAGS) $(INCLUDES) $(LFLAGS) -o $@ $< -L.. -lpthread$(GCX) $(XLIBS) $(XXLIBS) + +%.pre: %.c $(HDR) + $(CC) -E $(CFLAGS) -o $@ $< $(INCLUDES) + +%.s: %.c $(HDR) + @ $(ECHO) Compiling $@ + $(CC) -S $(CFLAGS) -o $@ $< $(INCLUDES) + +$(HDR) $(LIB) $(DLL) $(QAPC): $(LOGFILE) +# @ $(ECHO) Copying $(BUILD_DIR)/$@ +# @ $(TESTFILE) $(BUILD_DIR)/$@ $(AND) $(CP) $(BUILD_DIR)/$@ . + +.PHONY: $(LOGFILE) +$(LOGFILE):; > $@ + +benchlib.o: benchlib.c + @ $(ECHO) Compiling $@ + $(CC) -c $(CFLAGS) $< $(INCLUDES) + +clean: + - $(RM) *.dll + - $(RM) *.lib + - $(RM) _ptw32.h + - $(RM) pthread.h + - $(RM) semaphore.h + - $(RM) sched.h + - $(RM) *.a + - $(RM) *.e + - $(RM) *.i + - $(RM) *.o + - $(RM) *.s + - $(RM) *.so + - $(RM) *.obj + - $(RM) *.pdb + - $(RM) *.exe + - $(RM) *.manifest + - $(RM) *.pass + - $(RM) *.bench + +realclean: clean + - $(RM) *.log diff --git a/tests/Makefile b/tests/Makefile index 767c672d..863ee751 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -31,7 +31,9 @@ # -------------------------------------------------------------------------- # -DLL_VER = 2$(EXTRAVERSION) +PTW32_VER = 3$(EXTRAVERSION) + +CC = cl /errorReport:none /nologo CP = copy RM = erase @@ -44,43 +46,54 @@ TOUCH = $(ECHO) touched > # The next path is relative to $BUILD_DIR QAPC = # ..\QueueUserAPCEx\User\quserex.dll -CPHDR = pthread.h semaphore.h sched.h +CPHDR = _ptw32.h pthread.h semaphore.h sched.h OPTIM = /O2 /Ob0 XXLIBS = ws2_32.lib # C++ Exceptions -VCEFLAGS = /EHs /TP /DPtW32NoCatchWarn /D__CLEANUP_CXX -VCELIB = pthreadVCE$(DLL_VER).lib -VCEDLL = pthreadVCE$(DLL_VER).dll -VCELIBD = pthreadVCE$(DLL_VER)d.lib -VCEDLLD = pthreadVCE$(DLL_VER)d.dll +VCEFLAGS = /EHs /TP /D__PtW32NoCatchWarn /DPTW32_CLEANUP_CXX +VCELIB = libpthreadVCE$(PTW32_VER).lib +VCEIMP = pthreadVCE$(PTW32_VER).lib +VCEDLL = pthreadVCE$(PTW32_VER).dll +VCELIBD = libpthreadVCE$(PTW32_VER)d.lib +VCEIMPD = pthreadVCE$(PTW32_VER)d.lib +VCEDLLD = pthreadVCE$(PTW32_VER)d.dll # Structured Exceptions -VSEFLAGS = /D__CLEANUP_SEH -VSELIB = pthreadVSE$(DLL_VER).lib -VSEDLL = pthreadVSE$(DLL_VER).dll -VSELIBD = pthreadVSE$(DLL_VER)d.lib -VSEDLLD = pthreadVSE$(DLL_VER)d.dll +VSEFLAGS = /DPTW32_CLEANUP_SEH +VSELIB = libpthreadVSE$(PTW32_VER).lib +VSEIMP = pthreadVSE$(PTW32_VER).lib +VSEDLL = pthreadVSE$(PTW32_VER).dll +VSELIBD = libpthreadVSE$(PTW32_VER)d.lib +VSEIMPD = pthreadVSE$(PTW32_VER)d.lib +VSEDLLD = pthreadVSE$(PTW32_VER)d.dll # C cleanup code -VCFLAGS = /D__CLEANUP_C -VCLIB = pthreadVC$(DLL_VER).lib -VCDLL = pthreadVC$(DLL_VER).dll -VCLIBD = pthreadVC$(DLL_VER)d.lib -VCDLLD = pthreadVC$(DLL_VER)d.dll +VCFLAGS = /DPTW32_CLEANUP_C +VCLIB = libpthreadVC$(PTW32_VER).lib +VCIMP = pthreadVC$(PTW32_VER).lib +VCDLL = pthreadVC$(PTW32_VER).dll +VCLIBD = libpthreadVC$(PTW32_VER)d.lib +VCIMPD = pthreadVC$(PTW32_VER)d.lib +VCDLLD = pthreadVC$(PTW32_VER)d.dll # C++ Exceptions in application - using VC version of pthreads dll -VCXFLAGS = /EHs /TP /D__CLEANUP_C +VCXFLAGS = /EHs /TP /DPTW32_CLEANUP_C # Defaults CPLIB = $(VCLIB) CPDLL = $(VCDLL) -CFLAGS= $(OPTIM) /W3 /MD /nologo /Z7 -LFLAGS= /INCREMENTAL:NO -INCLUDES=-I. -BUILD_DIR=.. +CFLAGS = $(OPTIM) /W3 +CFLAGS_DEBUG = $(OPTIM) /W3 /Z7 +LFLAGS = /INCREMENTAL:NO +INCLUDES = -I. +BUILD_DIR = .. EHFLAGS = +EHFLAGS_DLL = /MD +EHFLAGS_DLL_DEBUG = /MDd +EHFLAGS_STATIC = /MT +EHFLAGS_STATIC_DEBUG = /MTd # If a test case returns a non-zero exit code to the shell, make will # stop. @@ -133,86 +146,88 @@ help: @ $(ECHO) nmake clean VSE-small-static-debug VC: - @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCLIB)" CPDLL="$(VCDLL)" EHFLAGS="$(VCFLAGS)" allpassed + @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCIMP)" CPDLL="$(VCDLL)" EHFLAGS="$(VCFLAGS) $(EHFLAGS_DLL)" allpassed VCE: - @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCELIB)" CPDLL="$(VCEDLL)" EHFLAGS="$(VCEFLAGS)" allpassed + @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCEIMP)" CPDLL="$(VCEDLL)" EHFLAGS="$(VCEFLAGS) $(EHFLAGS_DLL)" allpassed VSE: - @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VSELIB)" CPDLL="$(VSEDLL)" EHFLAGS="$(VSEFLAGS)" allpassed + @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VSEIMP)" CPDLL="$(VSEDLL)" EHFLAGS="$(VSEFLAGS) $(EHFLAGS_DLL)" allpassed VCX: - @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCLIB)" CPDLL="$(VCDLL)" EHFLAGS="$(VCXFLAGS)" allpassed + @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCIMP)" CPDLL="$(VCDLL)" EHFLAGS="$(VCXFLAGS) $(EHFLAGS_DLL)" allpassed VC-bench: - @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCLIB)" CPDLL="$(VCDLL)" EHFLAGS="$(VCFLAGS)" $(BENCHTESTS) + @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCIMP)" CPDLL="$(VCDLL)" EHFLAGS="$(VCFLAGS) $(EHFLAGS_DLL)" $(BENCHTESTS) VCE-bench: - @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCELIB)" CPDLL="$(VCEDLL)" EHFLAGS="$(VCEFLAGS)" $(BENCHTESTS) + @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCEIMP)" CPDLL="$(VCEDLL)" EHFLAGS="$(VCEFLAGS) $(EHFLAGS_DLL)" $(BENCHTESTS) VSE-bench: - @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VSELIB)" CPDLL="$(VSEDLL)" EHFLAGS="$(VSEFLAGS)" $(BENCHTESTS) + @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VSEIMP)" CPDLL="$(VSEDLL)" EHFLAGS="$(VSEFLAGS) $(EHFLAGS_DLL)" $(BENCHTESTS) VCX-bench: - @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCLIB)" CPDLL="$(VCDLL)" EHFLAGS="$(VCXFLAGS)" $(BENCHTESTS) + @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCIMP)" CPDLL="$(VCDLL)" EHFLAGS="$(VCXFLAGS) $(EHFLAGS_DLL)" $(BENCHTESTS) VC-static VC-small-static: - @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCLIB)" CPDLL="" EHFLAGS="$(VCFLAGS) /DPTW32_STATIC_LIB" allpassed + @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCLIB)" CPDLL="" EHFLAGS="$(VCFLAGS) $(EHFLAGS_STATIC)" allpassed VCE-static VCE-small-static: - @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCELIB)" CPDLL="" EHFLAGS="$(VCEFLAGS) /DPTW32_STATIC_LIB" allpassed + @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCELIB)" CPDLL="" EHFLAGS="$(VCEFLAGS) $(EHFLAGS_STATIC)" allpassed VSE-static VSE-small-static: - @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VSELIB)" CPDLL="" EHFLAGS="$(VSEFLAGS) /DPTW32_STATIC_LIB" allpassed + @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VSELIB)" CPDLL="" EHFLAGS="$(VSEFLAGS) $(EHFLAGS_STATIC)" allpassed VCX-static VCX-small-static: - @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCLIB)" CPDLL="" EHFLAGS="$(VCXFLAGS) /DPTW32_STATIC_LIB" allpassed + @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCLIBD)" CPDLL="" EHFLAGS="$(VCXFLAGS) $(EHFLAGS_STATIC)" allpassed VC-static-bench: - @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCLIB)" CPDLL="" EHFLAGS="$(VCFLAGS) /DPTW32_STATIC_LIB" $(BENCHTESTS) + @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCLIB)" CPDLL="" EHFLAGS="$(VCFLAGS) $(EHFLAGS_STATIC)" $(BENCHTESTS) VCE-static-bench: - @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCELIB)" CPDLL="" EHFLAGS="$(VCEFLAGS) /DPTW32_STATIC_LIB" $(BENCHTESTS) + @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCELIB)" CPDLL="" EHFLAGS="$(VCEFLAGS) $(EHFLAGS_STATIC)" $(BENCHTESTS) VSE-static-bench: - @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VSELIB)" CPDLL="" EHFLAGS="$(VSEFLAGS) /DPTW32_STATIC_LIB" $(BENCHTESTS) + @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VSELIB)" CPDLL="" EHFLAGS="$(VSEFLAGS) $(EHFLAGS_STATIC)" $(BENCHTESTS) VCX-static-bench: - @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCLIB)" CPDLL="" EHFLAGS="$(VCXFLAGS) /DPTW32_STATIC_LIB" $(BENCHTESTS) + @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCLIBD)" CPDLL="" EHFLAGS="$(VCXFLAGS) $(EHFLAGS_STATIC)" $(BENCHTESTS) VC-debug: - @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCLIBD)" CPDLL="$(VCDLLD)" EHFLAGS="$(VCFLAGS)" allpassed + @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCIMPD)" CPDLL="$(VCDLLD)" EHFLAGS="$(VCFLAGS) $(EHFLAGS_DLL_DEBUG)" allpassed VC-static-debug VC-small-static-debug: - @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCLIBD)" CPDLL="" EHFLAGS="$(VCFLAGS) /DPTW32_STATIC_LIB" allpassed + @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCLIBD)" CPDLL="" EHFLAGS="$(VCFLAGS) $(EHFLAGS_STATIC_DEBUG)" allpassed VCE-debug: - @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCELIBD)" CPDLL="$(VCEDLLD)" EHFLAGS="$(VCEFLAGS)" allpassed + @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCEIMPD)" CPDLL="$(VCEDLLD)" EHFLAGS="$(VCEFLAGS) $(EHFLAGS_DLL_DEBUG)" allpassed VCE-static-debug VCE-small-static-debug: - @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCELIBD)" CPDLL="" EHFLAGS="$(VCEFLAGS) /DPTW32_STATIC_LIB" allpassed + @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCELIBD)" CPDLL="" EHFLAGS="$(VCEFLAGS) $(EHFLAGS_STATIC_DEBUG)" allpassed VSE-debug: - @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VSELIBD)" CPDLL="$(VSEDLLD)" EHFLAGS="$(VSEFLAGS)" allpassed + @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VSEIMPD)" CPDLL="$(VSEDLLD)" EHFLAGS="$(VSEFLAGS) $(EHFLAGS_DLL_DEBUG)" allpassed VSE-static-debug VSE-small-static-debug: - @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VSELIBD)" CPDLL="" EHFLAGS="$(VSEFLAGS) /DPTW32_STATIC_LIB" allpassed + @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VSELIBD)" CPDLL="" EHFLAGS="$(VSEFLAGS) $(EHFLAGS_STATIC_DEBUG)" allpassed VCX-debug: - @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCLIBD)" CPDLL="$(VCDLLD)" EHFLAGS="$(VCXFLAGS)" allpassed + @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCIMPD)" CPDLL="$(VCDLLD)" EHFLAGS="$(VCXFLAGS) $(EHFLAGS_DLL_DEBUG)" allpassed VCX-static-debug VCX-small-static-debug: - @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCLIBD)" CPDLL="" EHFLAGS="$(VCXFLAGS) /DPTW32_STATIC_LIB" allpassed + @ $(MAKE) /E /nologo TEST="$@" CPLIB="$(VCLIBD)" CPDLL="" EHFLAGS="$(VCXFLAGS) $(EHFLAGS_STATIC_DEBUG)" allpassed clean: if exist *.dll $(RM) *.dll if exist *.lib $(RM) *.lib + if exist _ptw32.h $(RM) _ptw32.h if exist pthread.h $(RM) pthread.h if exist semaphore.h $(RM) semaphore.h if exist sched.h $(RM) sched.h if exist *.e $(RM) *.e if exist *.i $(RM) *.i if exist *.obj $(RM) *.obj + if exist *.idb $(RM) *.idb if exist *.pdb $(RM) *.pdb if exist *.o $(RM) *.o if exist *.asm $(RM) *.asm @@ -220,10 +235,12 @@ clean: if exist *.manifest $(RM) *.manifest if exist *.pass $(RM) *.pass if exist *.bench $(RM) *.bench + +realclean: clean if exist *.log $(RM) *.log .c.pass: - $(CC) $(EHFLAGS) $(CFLAGS) $(INCLUDES) $*.c /Fe$*.exe /link $(LFLAGS) $(CPLIB) $(XXLIBS) + $(CC) $(CFLAGS) $(INCLUDES) $(EHFLAGS) $*.c /Fe$*.exe /link $(LFLAGS) $(CPLIB) $(XXLIBS) @ $(ECHO) ... Running $(TEST) test: $*.exe @ .\$*.exe @ $(ECHO) ...... Passed diff --git a/tests/README b/tests/README index a1b5646b..65d46cc2 100644 --- a/tests/README +++ b/tests/README @@ -33,12 +33,15 @@ Tests written in this test suite should behave in the following manner: * If a test succeeds, leave main() with a result of 0. - * No diagnostic output should appear when the test is succeeding. - Diagnostic output may be emitted if something in the test - fails, to help determine the cause of the test failure. + * No diagnostic output should appear when the test is succeeding + unless it is particularly useful to visualise test behaviour. + Diagnostic output should be emitted if something in the test + fails, to help determine the cause of the test failure. Use assert() + for all API calls if possible. Notes: ------ Many test cases use knowledge of implementation internals which are supposed -to be opaque to portable applications. +to be opaque to portable applications. These should not be used as examples +of methods that can be conformantly applied to application code. diff --git a/tests/Wmakefile b/tests/Wmakefile index 95794557..fb12de10 100644 --- a/tests/Wmakefile +++ b/tests/Wmakefile @@ -13,7 +13,7 @@ # in the file CONTRIBUTORS included with the source # code distribution. The list can also be seen at the # following World Wide Web location: -# http://sources.redhat.com/pthreads-win32/contributors.html +# http://sources.redhat.com/pthreads-win32contributors.html # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -54,15 +54,15 @@ OPTIM = -od XXLIBS = # C++ Exceptions -WCEFLAGS = -xs -dPtW32NoCatchWarn -d__CLEANUP_CXX +WCEFLAGS = -xs -d__PtW32NoCatchWarn -dPTW32_CLEANUP_CXX WCELIB = pthreadWCE$(DLL_VER).lib WCEDLL = pthreadWCE$(DLL_VER).dll # C cleanup code -WCFLAGS = -d__CLEANUP_C +WCFLAGS = -dPTW32_CLEANUP_C WCLIB = pthreadWC$(DLL_VER).lib WCDLL = pthreadWC$(DLL_VER).dll # C++ Exceptions in application - using WC version of pthreads dll -WCXFLAGS = -xs -d__CLEANUP_C +WCXFLAGS = -xs -dPTW32_CLEANUP_C CFLAGS= -w4 -e25 -d_REENTRANT -zq -bm $(OPTIM) -5r -bt=nt -mf -d2 diff --git a/tests/affinity1.c b/tests/affinity1.c index def9d952..2997073f 100644 --- a/tests/affinity1.c +++ b/tests/affinity1.c @@ -16,17 +16,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/tests/affinity2.c b/tests/affinity2.c index 834de288..a2a2aa42 100644 --- a/tests/affinity2.c +++ b/tests/affinity2.c @@ -16,17 +16,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., @@ -77,7 +77,7 @@ test_affinity2(void) if (result != 0) { int err = -#if defined(PTW32_USES_SEPARATE_CRT) +#if defined (PTW32_USES_SEPARATE_CRT) GetLastError(); #else errno; diff --git a/tests/affinity3.c b/tests/affinity3.c index a90e2b44..ab7247c7 100644 --- a/tests/affinity3.c +++ b/tests/affinity3.c @@ -16,17 +16,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/tests/affinity4.c b/tests/affinity4.c index 1a378231..f291a15e 100644 --- a/tests/affinity4.c +++ b/tests/affinity4.c @@ -16,17 +16,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/tests/affinity5.c b/tests/affinity5.c index 202d4b77..647558f4 100644 --- a/tests/affinity5.c +++ b/tests/affinity5.c @@ -16,17 +16,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/tests/affinity6.c b/tests/affinity6.c index 91d2ce35..b4ce7150 100644 --- a/tests/affinity6.c +++ b/tests/affinity6.c @@ -16,17 +16,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/tests/benchtest5.c b/tests/benchtest5.c index 53974765..a5fc2c15 100644 --- a/tests/benchtest5.c +++ b/tests/benchtest5.c @@ -69,10 +69,10 @@ int zero = 0; * when doing the overhead timing with an empty loop. */ #define TESTSTART \ - { int i, j = 0, k = 0; PTW32_FTIME(&currSysTimeStart); for (i = 0; i < ITERATIONS; i++) { j++; + { int i, j = 0, k = 0; PTW32_FTIME(&currSysTimeStart); for (i = 0; i < ITERATIONS; i++) { j++; #define TESTSTOP \ - }; PTW32_FTIME(&currSysTimeStop); if (j + k == i) j++; } + }; PTW32_FTIME(&currSysTimeStop); if (j + k == i) j++; } void diff --git a/tests/cancel1.c b/tests/cancel1.c index fd2557b1..2abb940c 100644 --- a/tests/cancel1.c +++ b/tests/cancel1.c @@ -16,17 +16,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/tests/cancel2.c b/tests/cancel2.c index f41af3f4..ead4b39f 100644 --- a/tests/cancel2.c +++ b/tests/cancel2.c @@ -124,8 +124,8 @@ mythread(void * arg) #if !defined(__cplusplus) __except(EXCEPTION_EXECUTE_HANDLER) #else -#if defined(PtW32CatchAll) - PtW32CatchAll +#if defined(__PtW32CatchAll) + __PtW32CatchAll #else catch(...) #endif diff --git a/tests/cancel3.c b/tests/cancel3.c index d0e59594..f71fe5f8 100644 --- a/tests/cancel3.c +++ b/tests/cancel3.c @@ -132,6 +132,9 @@ test_cancel3(void) int i; pthread_t t[NUMTHREADS + 1]; + DWORD dwMode = SetErrorMode(SEM_NOGPFAULTERRORBOX); + SetErrorMode(dwMode | SEM_NOGPFAULTERRORBOX); + assert ((t[0] = pthread_self ()).p != NULL); for (i = 1; i <= NUMTHREADS; i++) diff --git a/tests/cancel5.c b/tests/cancel5.c index b0a54514..47592d06 100644 --- a/tests/cancel5.c +++ b/tests/cancel5.c @@ -132,6 +132,9 @@ test_cancel5(void) int i; pthread_t t[NUMTHREADS + 1]; + DWORD dwMode = SetErrorMode(SEM_NOGPFAULTERRORBOX); + SetErrorMode(dwMode | SEM_NOGPFAULTERRORBOX); + for (i = 1; i <= NUMTHREADS; i++) { threadbag[i].started = 0; diff --git a/tests/cancel6a.c b/tests/cancel6a.c index 066a8f8c..ca4ca1ba 100644 --- a/tests/cancel6a.c +++ b/tests/cancel6a.c @@ -2,25 +2,33 @@ * File: cancel6a.c * * - * pthreads-win32 - POSIX Threads Library for Win32 - * Copyright (C) 1998 Ben Elliston and Ross Johnson - * Copyright (C) 1999,2000,2001 Ross Johnson - * - * Contact Email: rpj@ise.canberra.edu.au - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999-2021 pthreads-win32 / pthreads4w contributors + * + * Homepage1: http://sourceware.org/pthreads-win32/ + * Homepage2: http://sourceforge.net/projects/pthreads4w/ + * + * The current list of contributors is contained + * in the file CONTRIBUTORS included with the source + * code distribution. The list can also be seen at the + * following World Wide Web location: + * http://sources.redhat.com/pthreads-win32/contributors.html + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library in the file COPYING.LIB; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * -------------------------------------------------------------------------- * @@ -120,6 +128,9 @@ test_cancel6a(void) int i; pthread_t t[NUMTHREADS + 1]; + DWORD dwMode = SetErrorMode(SEM_NOGPFAULTERRORBOX); + SetErrorMode(dwMode | SEM_NOGPFAULTERRORBOX); + assert((t[0] = pthread_self()).p != NULL); for (i = 1; i <= NUMTHREADS; i++) diff --git a/tests/cancel6d.c b/tests/cancel6d.c index 54f1e0e9..428cd9e7 100644 --- a/tests/cancel6d.c +++ b/tests/cancel6d.c @@ -2,25 +2,33 @@ * File: cancel6d.c * * - * pthreads-win32 - POSIX Threads Library for Win32 - * Copyright (C) 1998 Ben Elliston and Ross Johnson - * Copyright (C) 1999,2000,2001 Ross Johnson - * - * Contact Email: rpj@ise.canberra.edu.au - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999-2021 pthreads-win32 / pthreads4w contributors + * + * Homepage1: http://sourceware.org/pthreads-win32/ + * Homepage2: http://sourceforge.net/projects/pthreads4w/ + * + * The current list of contributors is contained + * in the file CONTRIBUTORS included with the source + * code distribution. The list can also be seen at the + * following World Wide Web location: + * http://sources.redhat.com/pthreads-win32/contributors.html + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library in the file COPYING.LIB; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * -------------------------------------------------------------------------- * diff --git a/tests/cancel9.c b/tests/cancel9.c index c924cad8..f3158fe4 100644 --- a/tests/cancel9.c +++ b/tests/cancel9.c @@ -16,17 +16,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., @@ -168,7 +168,7 @@ test_cancel9(void) pthread_t t; void *result; - if (pthread_win32_test_features_np (PTW32_ALERTABLE_ASYNC_CANCEL)) + if (pthread_win32_test_features_np (PTW32_ALERTABLE_ASYNC_CANCEL)) { printf ("Cancel sleeping thread.\n"); assert (pthread_create (&t, NULL, test_sleep, NULL) == 0); diff --git a/tests/cleanup1.c b/tests/cleanup1.c index 1b9bf4f4..866094b9 100644 --- a/tests/cleanup1.c +++ b/tests/cleanup1.c @@ -16,17 +16,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., @@ -158,6 +158,9 @@ test_cleanup1(void) int i; pthread_t t[NUMTHREADS + 1]; + DWORD dwMode = SetErrorMode(SEM_NOGPFAULTERRORBOX); + SetErrorMode(dwMode | SEM_NOGPFAULTERRORBOX); + memset(&pop_count, 0, sizeof(sharedInt_t)); InitializeCriticalSection(&pop_count.cs); diff --git a/tests/common.mk b/tests/common.mk index eec90583..f3ce9fd7 100644 --- a/tests/common.mk +++ b/tests/common.mk @@ -18,7 +18,9 @@ ALL_KNOWN_TESTS = \ create1 create2 create3 \ delay1 delay2 \ detach1 \ + equal0 \ equal1 \ + errno0 \ errno1 \ exception1 exception2 exception3_0 exception3 \ exit1 exit2 exit3 exit4 exit5 exit6 \ @@ -39,7 +41,7 @@ ALL_KNOWN_TESTS = \ robust1 robust2 robust3 robust4 robust5 \ rwlock1 rwlock2 rwlock3 rwlock4 \ rwlock2_t rwlock3_t rwlock4_t rwlock5_t rwlock6_t rwlock6_t2 \ - rwlock5 rwlock6 rwlock7 rwlock8 \ + rwlock5 rwlock6 \ self1 self2 \ semaphore1 semaphore2 semaphore3 \ semaphore4 semaphore4t semaphore5 \ diff --git a/tests/condvar2.c b/tests/condvar2.c index 553d6bb8..9969c955 100644 --- a/tests/condvar2.c +++ b/tests/condvar2.c @@ -82,6 +82,8 @@ static pthread_cond_t cv; static pthread_mutex_t mutex; +/* Cheating here - sneaking a peek at library internals */ +#include "../config.h" #include "../implement.h" #ifndef MONOLITHIC_PTHREAD_TESTS @@ -92,9 +94,7 @@ int test_condvar2(void) #endif { - struct timespec abstime = { 0, 0 }; - PTW32_STRUCT_TIMEB currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; + struct timespec abstime = { 0, 0 }, reltime = { 1, 0 }; assert(pthread_cond_init(&cv, NULL) == 0); @@ -102,13 +102,7 @@ test_condvar2(void) assert(pthread_mutex_lock(&mutex) == 0); - /* get current system time */ - PTW32_FTIME(&currSysTime); - - abstime.tv_sec = (long)currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - - abstime.tv_sec += 1; + (void) pthread_win32_getabstime_np(&abstime, &reltime); assert(pthread_cond_timedwait(&cv, &mutex, &abstime) == ETIMEDOUT); diff --git a/tests/condvar2_1.c b/tests/condvar2_1.c index 1fdbe449..2d0c5f08 100644 --- a/tests/condvar2_1.c +++ b/tests/condvar2_1.c @@ -81,7 +81,7 @@ static pthread_cond_t cv; static pthread_mutex_t mutex; -static struct timespec abstime = { 0, 0 }; +static struct timespec abstime = { 0, 0 }, reltime = { 5, 0 }; enum { NUMTHREADS = 30 @@ -99,6 +99,8 @@ mythread(void * arg) return arg; } +/* Cheating here - sneaking a peek at library internals */ +#include "../config.h" #include "../implement.h" #ifndef MONOLITHIC_PTHREAD_TESTS @@ -111,20 +113,12 @@ test_condvar2_1(void) { int i; pthread_t t[NUMTHREADS + 1]; - PTW32_STRUCT_TIMEB currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; assert(pthread_cond_init(&cv, NULL) == 0); assert(pthread_mutex_init(&mutex, NULL) == 0); - /* get current system time */ - PTW32_FTIME(&currSysTime); - - abstime.tv_sec = (long)currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - - abstime.tv_sec += 5; + pthread_win32_getabstime_np(&abstime, &reltime); assert(pthread_mutex_lock(&mutex) == 0); diff --git a/tests/condvar3.c b/tests/condvar3.c index fe5620cb..0e01b09b 100644 --- a/tests/condvar3.c +++ b/tests/condvar3.c @@ -117,9 +117,7 @@ test_condvar3(void) #endif { pthread_t t[NUMTHREADS]; - struct timespec abstime = { 0, 0 }; - PTW32_STRUCT_TIMEB currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; + struct timespec abstime, reltime = { 5, 0 }; assert((t[0] = pthread_self()).p != NULL); @@ -129,15 +127,9 @@ test_condvar3(void) assert(pthread_mutex_lock(&mutex) == 0); - /* get current system time */ - PTW32_FTIME(&currSysTime); - - abstime.tv_sec = (long)currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - assert(pthread_create(&t[1], NULL, mythread, (void *) 1) == 0); - abstime.tv_sec += 5; + (void) pthread_win32_getabstime_np(&abstime, &reltime); while (! (shared > 0)) assert(pthread_cond_timedwait(&cv, &mutex, &abstime) == 0); diff --git a/tests/condvar3_1.c b/tests/condvar3_1.c index 540c14f9..e23b85d3 100644 --- a/tests/condvar3_1.c +++ b/tests/condvar3_1.c @@ -85,7 +85,7 @@ static pthread_cond_t cv; static pthread_cond_t cv1; static pthread_mutex_t mutex; static pthread_mutex_t mutex1; -static struct timespec abstime = { 0, 0 }; +static struct timespec abstime = { 0, 0 }, reltime = { 5, 0 }; static int timedout = 0; static int signaled = 0; static int awoken = 0; @@ -120,6 +120,8 @@ mythread(void * arg) return arg; } +/* Cheating here - sneaking a peek at library internals */ +#include "../config.h" #include "../implement.h" #ifndef MONOLITHIC_PTHREAD_TESTS @@ -132,8 +134,6 @@ test_condvar3_1(void) { int i; pthread_t t[NUMTHREADS + 1]; - PTW32_STRUCT_TIMEB currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; assert(pthread_cond_init(&cv, NULL) == 0); assert(pthread_cond_init(&cv1, NULL) == 0); @@ -141,13 +141,7 @@ test_condvar3_1(void) assert(pthread_mutex_init(&mutex, NULL) == 0); assert(pthread_mutex_init(&mutex1, NULL) == 0); - /* get current system time */ - PTW32_FTIME(&currSysTime); - - abstime.tv_sec = (long)currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - - abstime.tv_sec += 5; + (void) pthread_win32_getabstime_np(&abstime, &reltime); assert(pthread_mutex_lock(&mutex1) == 0); diff --git a/tests/condvar3_2.c b/tests/condvar3_2.c index 8a2e1a24..f11cd474 100644 --- a/tests/condvar3_2.c +++ b/tests/condvar3_2.c @@ -83,8 +83,8 @@ static pthread_cond_t cv; static pthread_mutex_t mutex; -static struct timespec abstime = { 0, 0 }; -static struct timespec abstime2 = { 0, 0 }; +static struct timespec abstime, abstime2; +static struct timespec reltime = { 5, 0 }; static int timedout = 0; static int awoken = 0; @@ -117,10 +117,11 @@ mythread(void * arg) InterlockedIncrement((LPLONG)&awoken); } - return arg; } +/* Cheating here - sneaking a peek at library internals */ +#include "../config.h" #include "../implement.h" #ifndef MONOLITHIC_PTHREAD_TESTS @@ -133,18 +134,14 @@ test_condvar3_2(void) { int i; pthread_t t[NUMTHREADS + 1]; - PTW32_STRUCT_TIMEB currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; assert(pthread_cond_init(&cv, NULL) == 0); assert(pthread_mutex_init(&mutex, NULL) == 0); - /* get current system time */ - PTW32_FTIME(&currSysTime); - - abstime.tv_sec = abstime2.tv_sec = (long)currSysTime.time + 5; - abstime.tv_nsec = abstime2.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; + (void) pthread_win32_getabstime_np(&abstime, &reltime); + abstime2.tv_sec = abstime.tv_sec; + abstime2.tv_nsec = abstime.tv_nsec; assert(pthread_mutex_lock(&mutex) == 0); diff --git a/tests/condvar3_3.c b/tests/condvar3_3.c index b7c1cac6..8dbd7d2d 100644 --- a/tests/condvar3_3.c +++ b/tests/condvar3_3.c @@ -83,6 +83,8 @@ pthread_cond_t cnd; pthread_mutex_t mtx; +static const long NANOSEC_PER_SEC = 1000000000L; + #ifndef MONOLITHIC_PTHREAD_TESTS int main() @@ -92,20 +94,12 @@ test_condvar3_3(void) #endif { int rc; - - struct timespec abstime = { 0, 0 }; - PTW32_STRUCT_TIMEB currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; + struct timespec abstime, reltime = { 0, NANOSEC_PER_SEC/2 }; assert(pthread_cond_init(&cnd, 0) == 0); assert(pthread_mutex_init(&mtx, 0) == 0); - /* get current system time */ - PTW32_FTIME(&currSysTime); - - abstime.tv_sec = (long)currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - abstime.tv_sec += 1; + (void) pthread_win32_getabstime_np(&abstime, &reltime); /* Here pthread_cond_timedwait should time out after one second. */ @@ -115,21 +109,15 @@ test_condvar3_3(void) assert(pthread_mutex_unlock(&mtx) == 0); - /* Here, the condition variable is signaled, but there are no + /* Here, the condition variable is signalled, but there are no threads waiting on it. The signal should be lost and the next pthread_cond_timedwait should time out too. */ -// assert(pthread_mutex_lock(&mtx) == 0); - assert((rc = pthread_cond_signal(&cnd)) == 0); -// assert(pthread_mutex_unlock(&mtx) == 0); - assert(pthread_mutex_lock(&mtx) == 0); - abstime.tv_sec = (long)currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - abstime.tv_sec += 1; + (void) pthread_win32_getabstime_np(&abstime, &reltime); assert((rc = pthread_cond_timedwait(&cnd, &mtx, &abstime)) == ETIMEDOUT); diff --git a/tests/condvar4.c b/tests/condvar4.c index 6cea043e..18db2945 100644 --- a/tests/condvar4.c +++ b/tests/condvar4.c @@ -117,9 +117,7 @@ test_condvar4(void) #endif { pthread_t t[NUMTHREADS]; - struct timespec abstime = { 0, 0 }; - PTW32_STRUCT_TIMEB currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; + struct timespec abstime, reltime = { 5, 0 }; cvthing.shared = 0; @@ -133,13 +131,7 @@ test_condvar4(void) assert(cvthing.lock != PTHREAD_MUTEX_INITIALIZER); - /* get current system time */ - PTW32_FTIME(&currSysTime); - - abstime.tv_sec = (long)currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - - abstime.tv_sec += 5; + (void) pthread_win32_getabstime_np(&abstime, &reltime); assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == ETIMEDOUT); @@ -147,12 +139,7 @@ test_condvar4(void) assert(pthread_create(&t[1], NULL, mythread, (void *) 1) == 0); - PTW32_FTIME(&currSysTime); - - abstime.tv_sec = (long)currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - - abstime.tv_sec += 5; + (void) pthread_win32_getabstime_np(&abstime, &reltime); while (! (cvthing.shared > 0)) assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == 0); diff --git a/tests/condvar5.c b/tests/condvar5.c index bd642fd2..e9fb9f20 100644 --- a/tests/condvar5.c +++ b/tests/condvar5.c @@ -116,9 +116,7 @@ test_condvar5(void) #endif { pthread_t t[NUMTHREADS]; - struct timespec abstime = { 0, 0 }; - PTW32_STRUCT_TIMEB currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; + struct timespec abstime, reltime = { 5, 0 }; cvthing.shared = 0; @@ -132,13 +130,7 @@ test_condvar5(void) assert(cvthing.lock != PTHREAD_MUTEX_INITIALIZER); - /* get current system time */ - PTW32_FTIME(&currSysTime); - - abstime.tv_sec = (long)currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - - abstime.tv_sec += 5; + (void) pthread_win32_getabstime_np(&abstime, &reltime); assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == ETIMEDOUT); @@ -146,12 +138,7 @@ test_condvar5(void) assert(pthread_create(&t[1], NULL, mythread, (void *) 1) == 0); - PTW32_FTIME(&currSysTime); - - abstime.tv_sec = (long)currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - - abstime.tv_sec += 5; + (void) pthread_win32_getabstime_np(&abstime, &reltime); while (! (cvthing.shared > 0)) assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == 0); diff --git a/tests/condvar6.c b/tests/condvar6.c index f287eaab..d8878b3c 100644 --- a/tests/condvar6.c +++ b/tests/condvar6.c @@ -107,7 +107,7 @@ static cvthing_t cvthing = { static pthread_mutex_t start_flag = PTHREAD_MUTEX_INITIALIZER; -static struct timespec abstime = { 0, 0 }; +static struct timespec abstime, reltime = { 5, 0 }; static int awoken; @@ -150,9 +150,6 @@ test_condvar6(void) int i; pthread_t t[NUMTHREADS + 1]; - PTW32_STRUCT_TIMEB currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; - cvthing.shared = 0; assert((t[0] = pthread_self()).p != NULL); @@ -163,12 +160,7 @@ test_condvar6(void) assert(pthread_mutex_lock(&start_flag) == 0); - PTW32_FTIME(&currSysTime); - - abstime.tv_sec = (long)currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - - abstime.tv_sec += 5; + (void) pthread_win32_getabstime_np(&abstime, &reltime); assert((t[0] = pthread_self()).p != NULL); diff --git a/tests/condvar7.c b/tests/condvar7.c index 505042f6..bc48905e 100644 --- a/tests/condvar7.c +++ b/tests/condvar7.c @@ -107,7 +107,7 @@ static cvthing_t cvthing = { static pthread_mutex_t start_flag = PTHREAD_MUTEX_INITIALIZER; -static struct timespec abstime = { 0, 0 }; +static struct timespec abstime, reltime = { 10, 0 }; static int awoken; @@ -167,9 +167,6 @@ test_condvar7(void) int i; pthread_t t[NUMTHREADS + 1]; - PTW32_STRUCT_TIMEB currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; - cvthing.shared = 0; assert((t[0] = pthread_self()).p != NULL); @@ -180,12 +177,7 @@ test_condvar7(void) assert(pthread_mutex_lock(&start_flag) == 0); - PTW32_FTIME(&currSysTime); - - abstime.tv_sec = (time_t)currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - - abstime.tv_sec += 10; + (void) pthread_win32_getabstime_np(&abstime, &reltime); assert((t[0] = pthread_self()).p != NULL); diff --git a/tests/condvar8.c b/tests/condvar8.c index fb8009c8..70805106 100644 --- a/tests/condvar8.c +++ b/tests/condvar8.c @@ -107,7 +107,7 @@ static cvthing_t cvthing = { static pthread_mutex_t start_flag = PTHREAD_MUTEX_INITIALIZER; -static struct timespec abstime = { 0, 0 }; +static struct timespec abstime, reltime = { 10, 0 }; static int awoken; @@ -168,21 +168,13 @@ test_condvar8(void) int first, last; pthread_t t[NUMTHREADS + 1]; - PTW32_STRUCT_TIMEB currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; - assert((t[0] = pthread_self()).p != NULL); assert(cvthing.notbusy == PTHREAD_COND_INITIALIZER); assert(cvthing.lock == PTHREAD_MUTEX_INITIALIZER); - PTW32_FTIME(&currSysTime); - - abstime.tv_sec = (long)currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - - abstime.tv_sec += 10; + (void) pthread_win32_getabstime_np(&abstime, &reltime); assert((t[0] = pthread_self()).p != NULL); diff --git a/tests/condvar9.c b/tests/condvar9.c index b214fc0b..cb2b8714 100644 --- a/tests/condvar9.c +++ b/tests/condvar9.c @@ -109,7 +109,7 @@ static cvthing_t cvthing = { static pthread_mutex_t start_flag = PTHREAD_MUTEX_INITIALIZER; -static struct timespec abstime = { 0, 0 }; +static struct timespec abstime, reltime = { 5, 0 }; static int awoken; @@ -176,21 +176,13 @@ test_condvar9(void) int canceledThreads = 0; pthread_t t[NUMTHREADS + 1]; - PTW32_STRUCT_TIMEB currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; - assert((t[0] = pthread_self()).p != NULL); assert(cvthing.notbusy == PTHREAD_COND_INITIALIZER); assert(cvthing.lock == PTHREAD_MUTEX_INITIALIZER); - PTW32_FTIME(&currSysTime); - - abstime.tv_sec = (long)currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - - abstime.tv_sec += 5; + (void) pthread_win32_getabstime_np(&abstime, &reltime); assert((t[0] = pthread_self()).p != NULL); diff --git a/tests/context1.c b/tests/context1.c index 5d8ab473..47bb74ef 100644 --- a/tests/context1.c +++ b/tests/context1.c @@ -75,6 +75,8 @@ #define _WIN32_WINNT 0x400 #include "test.h" +/* Cheating here - sneaking a peek at library internals */ +#include "../config.h" #include "../implement.h" #include "../context.h" @@ -110,6 +112,9 @@ test_context1(void) pthread_t t; HANDLE hThread; + DWORD dwMode = SetErrorMode(SEM_NOGPFAULTERRORBOX); + SetErrorMode(dwMode | SEM_NOGPFAULTERRORBOX); + assert(pthread_create(&t, NULL, func, NULL) == 0); hThread = ((ptw32_thread_t *)t.p)->threadH; @@ -128,7 +133,7 @@ test_context1(void) context.ContextFlags = CONTEXT_CONTROL; GetThreadContext(hThread, &context); - PTW32_PROGCTR (context) = (DWORD_PTR) anotherEnding; + PTW32_PROGCTR (context) = (DWORD_PTR) anotherEnding; SetThreadContext(hThread, &context); ResumeThread(hThread); } diff --git a/tests/context2.c b/tests/context2.c index 621930ce..f86f8770 100644 --- a/tests/context2.c +++ b/tests/context2.c @@ -8,24 +8,25 @@ * Copyright(C) 1998 John E. Bossom * Copyright(C) 1999-2021 pthreads-win32 / pthreads4w contributors * - * Contact Email: rpj@callisto.canberra.edu.au + * Homepage1: http://sourceware.org/pthreads-win32/ + * Homepage2: http://sourceforge.net/projects/pthreads4w/ * * The current list of contributors is contained * in the file CONTRIBUTORS included with the source * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., @@ -74,6 +75,8 @@ #define _WIN32_WINNT 0x400 #include "test.h" +/* Cheating here - sneaking a peek at library internals */ +#include "../config.h" #include "../implement.h" #include "../context.h" diff --git a/tests/equal0.c b/tests/equal0.c new file mode 100644 index 00000000..ebbef414 --- /dev/null +++ b/tests/equal0.c @@ -0,0 +1,56 @@ +/* + * Test for pthread_equal. + * + * + * -------------------------------------------------------------------------- + * + * pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999-2021 pthreads-win32 / pthreads4w contributors + * + * Homepage1: http://sourceware.org/pthreads-win32/ + * Homepage2: http://sourceforge.net/projects/pthreads4w/ + * + * The current list of contributors is contained + * in the file CONTRIBUTORS included with the source + * code distribution. The list can also be seen at the + * following World Wide Web location: + * http://sources.redhat.com/pthreads-win32/contributors.html + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library in the file COPYING.LIB; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * -------------------------------------------------------------------------- + * + * Depends on functions: pthread_self(). + */ + +#include "test.h" + +#ifndef MONOLITHIC_PTHREAD_TESTS +int +main() +#else +int +test_equal0(void) +#endif +{ + pthread_t t1 = pthread_self(); + + assert(pthread_equal(t1, pthread_self()) != 0); + + /* Success. */ + return 0; +} diff --git a/tests/errno0.c b/tests/errno0.c new file mode 100644 index 00000000..52e0f857 --- /dev/null +++ b/tests/errno0.c @@ -0,0 +1,105 @@ +/* + * File: errno0.c + * + * + * -------------------------------------------------------------------------- + * + * pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999-2021 pthreads-win32 / pthreads4w contributors + * + * Homepage1: http://sourceware.org/pthreads-win32/ + * Homepage2: http://sourceforge.net/projects/pthreads4w/ + * + * The current list of contributors is contained + * in the file CONTRIBUTORS included with the source + * code distribution. The list can also be seen at the + * following World Wide Web location: + * http://sources.redhat.com/pthreads-win32/contributors.html + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library in the file COPYING.LIB; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * -------------------------------------------------------------------------- + * + * Test Synopsis: Test transmissibility of errno between library and exe + * - + * + * Test Method (Validation or Falsification): + * - Validation + * + * Requirements Tested: + * - + * + * Features Tested: + * - + * + * Cases Tested: + * - + * + * Description: + * - + * + * Environment: + * - + * + * Input: + * - None. + * + * Output: + * - File name, Line number, and failed expression on failure. + * - No output on success. + * + * Assumptions: + * - + * + * Pass Criteria: + * - Process returns zero exit status. + * + * Fail Criteria: + * - Process returns non-zero exit status. + */ + +#include "test.h" + +#ifndef MONOLITHIC_PTHREAD_TESTS +int +main() +#else +int +test_errno0(void) +#endif +{ + int err = 0; + errno = 0; + + assert(errno == 0); + assert(0 != sem_destroy(NULL)); + + err = +#if defined(PTW32_USES_SEPARATE_CRT) + GetLastError(); +#else + errno; +#endif + + assert(err != 0); + assert(err == EINVAL); + + /* + * Success. + */ + return 0; +} diff --git a/tests/exception1.c b/tests/exception1.c index 658511be..2d6c289c 100644 --- a/tests/exception1.c +++ b/tests/exception1.c @@ -16,17 +16,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., @@ -133,8 +133,8 @@ exceptionedThread(void * arg) */ throw dummy; } -#if defined(PtW32CatchAll) - PtW32CatchAll +#if defined(__PtW32CatchAll) + __PtW32CatchAll #else catch (...) #endif @@ -184,8 +184,8 @@ canceledThread(void * arg) for (count = 0; count < 100; count++) Sleep(100); } -#if defined(PtW32CatchAll) - PtW32CatchAll +#if defined(__PtW32CatchAll) + __PtW32CatchAll #else catch (...) #endif @@ -212,6 +212,9 @@ test_exception1(void) pthread_t et[NUMTHREADS]; pthread_t ct[NUMTHREADS]; + DWORD dwMode = SetErrorMode(SEM_NOGPFAULTERRORBOX); + SetErrorMode(dwMode | SEM_NOGPFAULTERRORBOX); + assert((mt = pthread_self()).p != NULL); for (i = 0; i < NUMTHREADS; i++) diff --git a/tests/exception2.c b/tests/exception2.c index 0333d4d6..50ba5ff1 100644 --- a/tests/exception2.c +++ b/tests/exception2.c @@ -127,6 +127,9 @@ test_exception2(int argc, char **argv) pthread_t mt; pthread_t et[NUMTHREADS]; + DWORD dwMode = SetErrorMode(SEM_NOGPFAULTERRORBOX); + SetErrorMode(dwMode | SEM_NOGPFAULTERRORBOX); + if (argc >= 2 && (!strcmp(argv[1], "-?") || !strcmp(argv[1], "-h"))) { int result; diff --git a/tests/exception3.c b/tests/exception3.c index 9ac59a05..4505abe9 100644 --- a/tests/exception3.c +++ b/tests/exception3.c @@ -115,7 +115,7 @@ terminateFunction () fclose(fp); } #endif - assert(pthread_mutex_unlock(&caughtLock) == 0); + assert_e(pthread_mutex_unlock(&caughtLock), ==, 0); /* * Notes from the MSVC++ manual: @@ -129,6 +129,14 @@ terminateFunction () * exception-using version of pthreads-win32 library * is being used (i.e. either pthreadVCE or pthreadVSE). */ + /* + * Allow time for all threads to reach here before exit, otherwise + * threads will be terminated while holding the lock and cause + * the next unlock to return EPERM (we're using ERRORCHECK mutexes). + * Perhaps this would be a good test for robust mutexes. + */ + Sleep(20); + exit(0); } @@ -144,7 +152,8 @@ exceptionedThread(void * arg) { int dummy = 0x1; -#if defined(PTW32_USES_SEPARATE_CRT) && (defined(__CLEANUP_CXX) || defined(__CLEANUP_SEH)) +#if defined (PTW32_USES_SEPARATE_CRT) && (defined(PTW32_CLEANUP_CXX) || defined(PTW32_CLEANUP_SEH)) + printf("PTW32_USES_SEPARATE_CRT is defined\n"); pthread_win32_set_terminate_np(&terminateFunction); set_terminate(&wrongTerminateFunction); #else @@ -169,6 +178,9 @@ test_exception3(void) pthread_t et[NUMTHREADS]; pthread_mutexattr_t ma; + DWORD dwMode = SetErrorMode(SEM_NOGPFAULTERRORBOX); + SetErrorMode(dwMode | SEM_NOGPFAULTERRORBOX); + assert((mt = pthread_self()).p != NULL); printf("See the notes inside of exception3.c re term_funcs.\n"); @@ -188,7 +200,7 @@ test_exception3(void) assert(caught == NUMTHREADS); /* - * Fail. Should never be reached. + * Should never be reached. */ return 1; } diff --git a/tests/exception3_0.c b/tests/exception3_0.c index 9f6bf9d1..b83ce34e 100755 --- a/tests/exception3_0.c +++ b/tests/exception3_0.c @@ -16,17 +16,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., @@ -156,6 +156,9 @@ test_exception3_0(void) int i; DWORD et[NUMTHREADS]; + DWORD dwMode = SetErrorMode(SEM_NOGPFAULTERRORBOX); + SetErrorMode(dwMode | SEM_NOGPFAULTERRORBOX); + InitializeCriticalSection(&caughtLock); for (i = 0; i < NUMTHREADS; i++) diff --git a/tests/exit2.c b/tests/exit2.c index e2ffdb88..b3ea604b 100644 --- a/tests/exit2.c +++ b/tests/exit2.c @@ -44,12 +44,17 @@ static void * func(void * arg) { - pthread_exit(arg); + int failed = (int) arg; - /* Never reached. */ - assert(0); + pthread_exit(arg); - return NULL; + /* Never reached. */ + /* + * Trick gcc compiler into not issuing a warning here + */ + assert(failed - (int)arg); + + return NULL; } #ifndef MONOLITHIC_PTHREAD_TESTS diff --git a/tests/exit3.c b/tests/exit3.c index fdb4f10e..e2a4861c 100644 --- a/tests/exit3.c +++ b/tests/exit3.c @@ -42,10 +42,15 @@ static void * func(void * arg) { + int failed = (int) arg; + pthread_exit(arg); /* Never reached. */ - assert(0); + /* + * assert(0) in a way to prevent warning or optimising away. + */ + assert(failed - (int) arg); return NULL; } diff --git a/tests/exit5.c b/tests/exit5.c index cc3b02fd..223c5fd1 100644 --- a/tests/exit5.c +++ b/tests/exit5.c @@ -16,17 +16,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., @@ -97,7 +97,7 @@ struct bag_t_ { static bag_t threadbag[NUMTHREADS + 1]; static -#if ! defined (PTW32_CONFIG_MINGW) || defined (__MSVCRT__) +#if ! defined (__MINGW32__) || defined (__MSVCRT__) unsigned __stdcall #else void @@ -139,7 +139,7 @@ test_exit5(void) { threadbag[i].started = 0; threadbag[i].threadnum = i; -#if ! defined (PTW32_CONFIG_MINGW) || defined (__MSVCRT__) +#if ! defined (__MINGW32__) || defined (__MSVCRT__) h[i] = (HANDLE) _beginthreadex(NULL, 0, Win32thread, (void *) &threadbag[i], 0, &thrAddr); #else h[i] = (HANDLE) _beginthread(Win32thread, 0, (void *) &threadbag[i]); @@ -179,7 +179,7 @@ test_exit5(void) int fail = 0; int result = 0; -#if ! defined (PTW32_CONFIG_MINGW) || defined (__MSVCRT__) +#if ! defined (__MINGW32__) || defined (__MSVCRT__) assert(GetExitCodeThread(h[i], (LPDWORD) &result) == TRUE); #else /* diff --git a/tests/exit6.c b/tests/exit6.c index 67782099..f5833d58 100644 --- a/tests/exit6.c +++ b/tests/exit6.c @@ -1,8 +1,42 @@ /* - * exit6.c + * + * File: exit6.c * * Created on: 14/05/2013 * Author: ross + * + * -------------------------------------------------------------------------- + * + * pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999-2021 pthreads-win32 / pthreads4w contributors + * + * Homepage1: http://sourceware.org/pthreads-win32/ + * Homepage2: http://sourceforge.net/projects/pthreads4w/ + * + * The current list of contributors is contained + * in the file CONTRIBUTORS included with the source + * code distribution. The list can also be seen at the + * following World Wide Web location: + * http://sources.redhat.com/pthreads-win32/contributors.html + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library in the file COPYING.LIB; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * -------------------------------------------------------------------------- + * */ #include "test.h" diff --git a/tests/join4.c b/tests/join4.c index 32f5351f..1ed87bce 100755 --- a/tests/join4.c +++ b/tests/join4.c @@ -16,17 +16,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., @@ -55,10 +55,8 @@ int #endif { pthread_t id; - struct timespec abstime; + struct timespec abstime, reltime = { 1, 0 }; void* result = (void*)-1; - PTW32_STRUCT_TIMEB currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; assert(pthread_create(&id, NULL, func, (void *)(size_t)999) == 0); @@ -67,13 +65,9 @@ int */ Sleep(100); - PTW32_FTIME(&currSysTime); - - abstime.tv_sec = (long)currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; + (void) pthread_win32_getabstime_np(&abstime, &reltime); /* Test for pthread_timedjoin_np timeout */ - abstime.tv_sec += 1; assert(pthread_timedjoin_np(id, &result, &abstime) == ETIMEDOUT); assert((int)(size_t)result == -1); diff --git a/tests/mutex6.c b/tests/mutex6.c index 750b7551..798282b6 100644 --- a/tests/mutex6.c +++ b/tests/mutex6.c @@ -78,7 +78,10 @@ test_mutex6(void) assert(pthread_create(&t, NULL, locker, NULL) == 0); - Sleep(1000); + while (lockCount < 1) + { + Sleep(1); + } assert(lockCount == 1); @@ -88,7 +91,10 @@ test_mutex6(void) */ assert(pthread_mutex_unlock(&mutex) == 0); - Sleep (1000); + while (lockCount < 2) + { + Sleep(1); + } assert(lockCount == 2); diff --git a/tests/mutex6n.c b/tests/mutex6n.c index f47db49a..84c99345 100644 --- a/tests/mutex6n.c +++ b/tests/mutex6n.c @@ -97,13 +97,19 @@ test_mutex6n(void) assert(pthread_create(&t, NULL, locker, NULL) == 0); - Sleep(100); + while (lockCount < 1) + { + Sleep(1); + } assert(lockCount == 1); assert(pthread_mutex_unlock(&mutex) == (IS_ROBUST ? EPERM : 0)); - Sleep(100); + while (lockCount < (IS_ROBUST?1:2)) + { + Sleep(1); + } assert(lockCount == (IS_ROBUST ? 1 : 2)); diff --git a/tests/mutex6s.c b/tests/mutex6s.c index 45f0f621..7c4ae8c3 100644 --- a/tests/mutex6s.c +++ b/tests/mutex6s.c @@ -78,7 +78,10 @@ test_mutex6s(void) assert(pthread_create(&t, NULL, locker, NULL) == 0); - Sleep(1000); + while (lockCount < 1) + { + Sleep(1); + } assert(lockCount == 1); @@ -88,7 +91,10 @@ test_mutex6s(void) */ assert(pthread_mutex_unlock(&mutex) == 0); - Sleep (1000); + while (lockCount < 2) + { + Sleep(1); + } assert(lockCount == 2); diff --git a/tests/mutex7.c b/tests/mutex7.c index 6f40a800..a459bbac 100644 --- a/tests/mutex7.c +++ b/tests/mutex7.c @@ -77,7 +77,10 @@ test_mutex7(void) assert(pthread_create(&t, NULL, locker, NULL) == 0); - Sleep(1000); + while (lockCount < 2) + { + Sleep(1); + } assert(lockCount == 2); diff --git a/tests/mutex7n.c b/tests/mutex7n.c index 94e41a86..9853234e 100644 --- a/tests/mutex7n.c +++ b/tests/mutex7n.c @@ -91,7 +91,10 @@ test_mutex7n(void) assert(pthread_create(&t, NULL, locker, NULL) == 0); - Sleep(100); + while (lockCount < 2) + { + Sleep(1); + } assert(lockCount == 2); diff --git a/tests/mutex8.c b/tests/mutex8.c index 1e7b5f5d..740418e2 100644 --- a/tests/mutex8.c +++ b/tests/mutex8.c @@ -2,25 +2,33 @@ * mutex8.c * * - * pthreads-win32 - POSIX Threads Library for Win32 - * Copyright (C) 1998 Ben Elliston and Ross Johnson - * Copyright (C) 1999,2000,2001 Ross Johnson + * pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999-2021 pthreads-win32 / pthreads4w contributors * - * Contact Email: rpj@ise.canberra.edu.au + * Homepage1: http://sourceware.org/pthreads-win32/ + * Homepage2: http://sourceforge.net/projects/pthreads4w/ * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * The current list of contributors is contained + * in the file CONTRIBUTORS included with the source + * code distribution. The list can also be seen at the + * following World Wide Web location: + * http://sources.redhat.com/pthreads-win32/contributors.html + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library in the file COPYING.LIB; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * -------------------------------------------------------------------------- * @@ -42,16 +50,9 @@ static pthread_mutex_t mutex; static void * locker(void * arg) { - struct timespec abstime = { 0, 0 }; - PTW32_STRUCT_TIMEB currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; - - PTW32_FTIME(&currSysTime); - - abstime.tv_sec = (long)currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; + struct timespec abstime, reltime = { 1, 0 }; - abstime.tv_sec += 1; + (void) pthread_win32_getabstime_np(&abstime, &reltime); assert(pthread_mutex_timedlock(&mutex, &abstime) == ETIMEDOUT); @@ -76,7 +77,10 @@ test_mutex8(void) assert(pthread_create(&t, NULL, locker, NULL) == 0); - Sleep(2000); + while (lockCount < 1) + { + Sleep(1); + } assert(lockCount == 1); diff --git a/tests/mutex8e.c b/tests/mutex8e.c index 31cf52e7..42d943be 100644 --- a/tests/mutex8e.c +++ b/tests/mutex8e.c @@ -2,25 +2,33 @@ * mutex8e.c * * - * pthreads-win32 - POSIX Threads Library for Win32 - * Copyright (C) 1998 Ben Elliston and Ross Johnson - * Copyright (C) 1999,2000,2001 Ross Johnson + * pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999-2021 pthreads-win32 / pthreads4w contributors * - * Contact Email: rpj@ise.canberra.edu.au + * Homepage1: http://sourceware.org/pthreads-win32/ + * Homepage2: http://sourceforge.net/projects/pthreads4w/ * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * The current list of contributors is contained + * in the file CONTRIBUTORS included with the source + * code distribution. The list can also be seen at the + * following World Wide Web location: + * http://sources.redhat.com/pthreads-win32/contributors.html + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library in the file COPYING.LIB; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * -------------------------------------------------------------------------- * @@ -50,16 +58,9 @@ static pthread_mutexattr_t mxAttr; static void * locker(void * arg) { - struct timespec abstime = { 0, 0 }; - PTW32_STRUCT_TIMEB currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; - - PTW32_FTIME(&currSysTime); - - abstime.tv_sec = (long)currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; + struct timespec abstime, reltime = { 1, 0 }; - abstime.tv_sec += 1; + (void) pthread_win32_getabstime_np(&abstime, &reltime); assert(pthread_mutex_timedlock(&mutex, &abstime) == ETIMEDOUT); diff --git a/tests/mutex8n.c b/tests/mutex8n.c index 1230d2f4..75d7f5c8 100644 --- a/tests/mutex8n.c +++ b/tests/mutex8n.c @@ -2,25 +2,33 @@ * mutex8n.c * * - * pthreads-win32 - POSIX Threads Library for Win32 - * Copyright (C) 1998 Ben Elliston and Ross Johnson - * Copyright (C) 1999,2000,2001 Ross Johnson + * pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999-2021 pthreads-win32 / pthreads4w contributors * - * Contact Email: rpj@ise.canberra.edu.au + * Homepage1: http://sourceware.org/pthreads-win32/ + * Homepage2: http://sourceforge.net/projects/pthreads4w/ * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * The current list of contributors is contained + * in the file CONTRIBUTORS included with the source + * code distribution. The list can also be seen at the + * following World Wide Web location: + * http://sources.redhat.com/pthreads-win32/contributors.html + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library in the file COPYING.LIB; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * -------------------------------------------------------------------------- * @@ -50,16 +58,9 @@ static pthread_mutexattr_t mxAttr; static void * locker(void * arg) { - struct timespec abstime = { 0, 0 }; - PTW32_STRUCT_TIMEB currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; - - PTW32_FTIME(&currSysTime); - - abstime.tv_sec = (long)currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; + struct timespec abstime, reltime = { 1, 0 }; - abstime.tv_sec += 1; + (void) pthread_win32_getabstime_np(&abstime, &reltime); assert(pthread_mutex_timedlock(&mutex, &abstime) == ETIMEDOUT); @@ -94,7 +95,10 @@ test_mutex8n(void) assert(pthread_create(&t, NULL, locker, NULL) == 0); - Sleep(2000); + while (lockCount < 1) + { + Sleep(1); + } assert(lockCount == 1); diff --git a/tests/mutex8r.c b/tests/mutex8r.c index 87f3fbd6..99efc162 100644 --- a/tests/mutex8r.c +++ b/tests/mutex8r.c @@ -2,25 +2,33 @@ * mutex8r.c * * - * pthreads-win32 - POSIX Threads Library for Win32 - * Copyright (C) 1998 Ben Elliston and Ross Johnson - * Copyright (C) 1999,2000,2001 Ross Johnson + * pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999-2021 pthreads-win32 / pthreads4w contributors * - * Contact Email: rpj@ise.canberra.edu.au + * Homepage1: http://sourceware.org/pthreads-win32/ + * Homepage2: http://sourceforge.net/projects/pthreads4w/ * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * The current list of contributors is contained + * in the file CONTRIBUTORS included with the source + * code distribution. The list can also be seen at the + * following World Wide Web location: + * http://sources.redhat.com/pthreads-win32/contributors.html + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library in the file COPYING.LIB; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * -------------------------------------------------------------------------- * @@ -50,16 +58,9 @@ static pthread_mutexattr_t mxAttr; static void * locker(void * arg) { - struct timespec abstime = { 0, 0 }; - PTW32_STRUCT_TIMEB currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; - - PTW32_FTIME(&currSysTime); - - abstime.tv_sec = (long)currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; + struct timespec abstime, reltime = { 1, 0 }; - abstime.tv_sec += 1; + (void) pthread_win32_getabstime_np(&abstime, &reltime); assert(pthread_mutex_timedlock(&mutex, &abstime) == ETIMEDOUT); diff --git a/tests/name_np1.c b/tests/name_np1.c index 74403288..9fbea1ee 100644 --- a/tests/name_np1.c +++ b/tests/name_np1.c @@ -16,17 +16,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., @@ -58,7 +58,7 @@ static int washere = 0; static pthread_barrier_t sync; -#if defined(PTW32_COMPATIBILITY_BSD) +#if defined (PTW32_COMPATIBILITY_BSD) static int seqno = 0; #endif @@ -89,10 +89,10 @@ test_namenp1(void) assert(pthread_barrier_init(&sync, NULL, 2) == 0); assert(pthread_create(&t, NULL, func, NULL) == 0); -#if defined(PTW32_COMPATIBILITY_BSD) +#if defined (PTW32_COMPATIBILITY_BSD) seqno++; assert(pthread_setname_np(t, "MyThread%d", (void *)&seqno) == 0); -#elif defined(PTW32_COMPATIBILITY_TRU64) +#elif defined (PTW32_COMPATIBILITY_TRU64) assert(pthread_setname_np(t, "MyThread1", NULL) == 0); #else assert(pthread_setname_np(t, "MyThread1") == 0); diff --git a/tests/name_np2.c b/tests/name_np2.c index 5936853c..0b2a35cb 100644 --- a/tests/name_np2.c +++ b/tests/name_np2.c @@ -16,17 +16,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., @@ -60,7 +60,7 @@ static int washere = 0; static pthread_attr_t attr; static pthread_barrier_t sync; -#if defined(PTW32_COMPATIBILITY_BSD) +#if defined (PTW32_COMPATIBILITY_BSD) static int seqno = 0; #endif @@ -89,10 +89,10 @@ test_namenp2(void) pthread_t t; assert(pthread_attr_init(&attr) == 0); -#if defined(PTW32_COMPATIBILITY_BSD) +#if defined (PTW32_COMPATIBILITY_BSD) seqno++; assert(pthread_attr_setname_np(&attr, "MyThread%d", (void *)&seqno) == 0); -#elif defined(PTW32_COMPATIBILITY_TRU64) +#elif defined (PTW32_COMPATIBILITY_TRU64) assert(pthread_attr_setname_np(&attr, "MyThread1", NULL) == 0); #else assert(pthread_attr_setname_np(&attr, "MyThread1") == 0); diff --git a/tests/once3.c b/tests/once3.c index 4fc945d6..da55bcbf 100644 --- a/tests/once3.c +++ b/tests/once3.c @@ -111,7 +111,7 @@ test_once3(void) pthread_t t[NUM_THREADS][NUM_ONCE]; int i, j; -#if defined(PTW32_CONFIG_MSVC6) && defined(__CLEANUP_CXX) +#if defined (PTW32_CONFIG_MSVC6) && defined(PTW32_CLEANUP_CXX) puts("If this test fails or hangs, rebuild the library with /EHa instead of /EHs."); puts("(This is a known issue with Microsoft VC++6.0.)"); fflush(stdout); diff --git a/tests/once4.c b/tests/once4.c index 0e8fb85e..cc22c0d9 100644 --- a/tests/once4.c +++ b/tests/once4.c @@ -146,7 +146,7 @@ test_once4(void) pthread_t t[NUM_THREADS][NUM_ONCE]; int i, j; -#if defined(PTW32_CONFIG_MSVC6) && defined(__CLEANUP_CXX) +#if defined (PTW32_CONFIG_MSVC6) && defined(PTW32_CLEANUP_CXX) puts("If this test fails or hangs, rebuild the library with /EHa instead of /EHs."); puts("(This is a known issue with Microsoft VC++6.0.)"); fflush(stdout); diff --git a/tests/openmp1.c b/tests/openmp1.c index ffba88f4..628146a6 100755 --- a/tests/openmp1.c +++ b/tests/openmp1.c @@ -100,9 +100,6 @@ test_openmp1(int argc, char *argv[]) memset(&a_thr, 0, sizeof(a_thr)); /* [i_a] fix valid MSVC complaint about unitialized a_thr / b_thr */ memset(&b_thr, 0, sizeof(b_thr)); /* [i_a] fix valid MSVC complaint about unitialized a_thr / b_thr */ - printf("%s:%d - %s - a_thr:%p - b_thr:%p\n", - __FILE__,__LINE__,__FUNCTION__,a_thr.p,b_thr.p); - status = pthread_create(&a_thr, NULL, _thread, (void*) 1 ); if ( status != 0 ) { printf("Failed to create thread 1\n"); @@ -115,6 +112,9 @@ test_openmp1(int argc, char *argv[]) return (-1); } + printf("%s:%d - %s - a_thr:%p - b_thr:%p\n", + __FILE__,__LINE__,__FUNCTION__,a_thr.p,b_thr.p); + status = pthread_join(a_thr, NULL); if ( status != 0 ) { printf("Failed to join thread 1\n"); diff --git a/tests/reinit1.c b/tests/reinit1.c index 97f5141a..0592c0ce 100644 --- a/tests/reinit1.c +++ b/tests/reinit1.c @@ -1,7 +1,7 @@ /* * reinit1.c * - * Same test as rwlock7.c but loop two or times reinitialising the library + * Same test as rwlock7.c but loop two or more times reinitialising the library * each time, to test reinitialisation. We use a rwlock test because rw locks * use CVs, mutexes and semaphores internally. * @@ -56,7 +56,7 @@ static void *thread_routine (void *arg) self->changed = 0; - assert(pthread_getunique_np(self->thread_id) == (self->thread_num + 2)); + assert(pthread_getunique_np(self->thread_id) == (unsigned __int64)(self->thread_num + 2)); for (iteration = 0; iteration < ITERATIONS; iteration++) { @@ -112,8 +112,6 @@ test_reinit1(void) int reinit_count; int seed = 1; - PTW32_STRUCT_TIMEB currSysTime1; - for (reinit_count = 0; reinit_count < LOOPS; reinit_count++) { /* @@ -127,8 +125,6 @@ test_reinit1(void) assert(pthread_rwlock_init (&data[data_count].lock, NULL) == 0); } - PTW32_FTIME(&currSysTime1); - /* * Create THREADS threads to access shared data. */ diff --git a/tests/runorder.mk b/tests/runorder.mk index c7cfb391..c954dae4 100644 --- a/tests/runorder.mk +++ b/tests/runorder.mk @@ -7,7 +7,7 @@ benchtest3.bench: benchtest4.bench: benchtest5.bench: -affinity1.pass: +affinity1.pass: errno0.pass affinity2.pass: affinity1.pass affinity3.pass: affinity2.pass self1.pass create3.pass affinity4.pass: affinity3.pass @@ -56,7 +56,9 @@ create3.pass: create2.pass delay1.pass: self1.pass create3.pass delay2.pass: delay1.pass detach1.pass: join0.pass -equal1.pass: self1.pass create1.pass +equal0.pass: self1.pass +equal1.pass: equal0.pass create1.pass +errno0.pass: sizes.pass errno1.pass: mutex3.pass exception1.pass: cancel4.pass exception2.pass: exception1.pass @@ -111,7 +113,7 @@ once3.pass: once2.pass once4.pass: once3.pass priority1.pass: join1.pass priority2.pass: priority1.pass barrier3.pass -reinit1.pass: rwlock7.pass +reinit1.pass: rwlock6.pass reuse1.pass: create3.pass reuse2.pass: reuse1.pass robust1.pass: mutex8r.pass @@ -125,13 +127,11 @@ rwlock3.pass: rwlock2.pass join2.pass rwlock4.pass: rwlock3.pass rwlock5.pass: rwlock4.pass rwlock6.pass: rwlock5.pass -rwlock7.pass: rwlock6.pass -rwlock8.pass: rwlock7.pass rwlock2_t.pass: rwlock2.pass -rwlock3_t.pass: rwlock2_t.pass -rwlock4_t.pass: rwlock3_t.pass -rwlock5_t.pass: rwlock4_t.pass -rwlock6_t.pass: rwlock5_t.pass +rwlock3_t.pass: rwlock3.pass rwlock2_t.pass +rwlock4_t.pass: rwlock4.pass rwlock3_t.pass +rwlock5_t.pass: rwlock5.pass rwlock4_t.pass +rwlock6_t.pass: rwlock6.pass rwlock5_t.pass rwlock6_t2.pass: rwlock6_t.pass self1.pass: sizes.pass self2.pass: self1.pass equal1.pass create1.pass diff --git a/tests/rwlock2_t.c b/tests/rwlock2_t.c index ba510ccd..61f5e647 100644 --- a/tests/rwlock2_t.c +++ b/tests/rwlock2_t.c @@ -55,16 +55,9 @@ int test_rwlock2_t(void) #endif { - struct timespec abstime = { 0, 0 }; - PTW32_STRUCT_TIMEB currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; + struct timespec abstime, reltime = { 1, 0 }; - PTW32_FTIME(&currSysTime); - - abstime.tv_sec = (long)currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - - abstime.tv_sec += 1; + (void) pthread_win32_getabstime_np(&abstime, &reltime); assert(rwlock == PTHREAD_RWLOCK_INITIALIZER); diff --git a/tests/rwlock3_t.c b/tests/rwlock3_t.c index fae75640..d6b1935d 100644 --- a/tests/rwlock3_t.c +++ b/tests/rwlock3_t.c @@ -68,16 +68,9 @@ test_rwlock3_t(void) #endif { pthread_t t; - struct timespec abstime = { 0, 0 }; - PTW32_STRUCT_TIMEB currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; + struct timespec abstime, reltime = { 1, 0 }; - PTW32_FTIME(&currSysTime); - - abstime.tv_sec = (long)currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - - abstime.tv_sec += 1; + (void) pthread_win32_getabstime_np(&abstime, &reltime); assert(pthread_rwlock_timedwrlock(&rwlock1, &abstime) == 0); diff --git a/tests/rwlock4_t.c b/tests/rwlock4_t.c index b2c458cb..5c928e40 100644 --- a/tests/rwlock4_t.c +++ b/tests/rwlock4_t.c @@ -69,17 +69,9 @@ test_rwlock4_t(void) { pthread_t t; struct timespec abstime = { 0, 0 }; - PTW32_STRUCT_TIMEB currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; + struct timespec reltime = { 1, 0 }; - PTW32_FTIME(&currSysTime); - - abstime.tv_sec = (long)currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - - abstime.tv_sec += 1; - - assert(pthread_rwlock_timedrdlock(&rwlock1, &abstime) == 0); + assert(pthread_rwlock_timedrdlock(&rwlock1, pthread_win32_getabstime_np(&abstime, &reltime)) == 0); assert(pthread_create(&t, NULL, func, NULL) == 0); diff --git a/tests/rwlock5_t.c b/tests/rwlock5_t.c index db3a45f9..35af33b0 100644 --- a/tests/rwlock5_t.c +++ b/tests/rwlock5_t.c @@ -70,16 +70,9 @@ test_rwlock5_t(void) #endif { pthread_t t; - struct timespec abstime = { 0, 0 }; - PTW32_STRUCT_TIMEB currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; + struct timespec abstime, reltime = { 1, 0 }; - PTW32_FTIME(&currSysTime); - - abstime.tv_sec = (long)currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - - abstime.tv_sec += 1; + (void) pthread_win32_getabstime_np(&abstime, &reltime); assert(pthread_rwlock_timedrdlock(&rwlock1, &abstime) == 0); diff --git a/tests/rwlock6_t.c b/tests/rwlock6_t.c index 6e731c62..57aec2e2 100644 --- a/tests/rwlock6_t.c +++ b/tests/rwlock6_t.c @@ -62,15 +62,9 @@ static void * wrfunc(void * arg) static void * rdfunc(void * arg) { int ba = -1; - struct timespec abstime = { 0, 0 }; - PTW32_STRUCT_TIMEB currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; - - PTW32_FTIME(&currSysTime); - - abstime.tv_sec = (long)currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; + struct timespec abstime; + (void) pthread_win32_getabstime_np(&abstime, NULL); if ((int) (size_t)arg == 1) { @@ -149,5 +143,3 @@ test_rwlock6_t(void) return 0; } - - diff --git a/tests/rwlock6_t2.c b/tests/rwlock6_t2.c index 887e4c76..2011cb85 100644 --- a/tests/rwlock6_t2.c +++ b/tests/rwlock6_t2.c @@ -48,7 +48,7 @@ static pthread_rwlock_t rwlock1 = PTHREAD_RWLOCK_INITIALIZER; static int bankAccount = 0; -struct timespec abstime = { 0, 0 }; +struct timespec abstime, reltime = { 1, 0 }; void * wrfunc(void * arg) { @@ -95,15 +95,8 @@ test_rwlock6_t2(void) void* wr1Result = (void*)0; void* wr2Result = (void*)0; void* rdResult = (void*)0; - PTW32_STRUCT_TIMEB currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; - PTW32_FTIME(&currSysTime); - - abstime.tv_sec = (long)currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - - abstime.tv_sec += 1; + (void) pthread_win32_getabstime_np(&abstime, &reltime); bankAccount = 0; diff --git a/tests/self1.c b/tests/self1.c index f8467598..51cc02b3 100644 --- a/tests/self1.c +++ b/tests/self1.c @@ -60,7 +60,7 @@ test_self1(void) */ pthread_t self; -#if defined(PTW32_STATIC_LIB) && !(defined(_MSC_VER) || defined(__MINGW32__)) +#if defined (PTW32_STATIC_LIB) && !(defined(_MSC_VER) || defined(__MINGW32__)) pthread_win32_process_attach_np(); #endif @@ -68,7 +68,7 @@ test_self1(void) assert(self.p != NULL); -#if defined(PTW32_STATIC_LIB) && !(defined(_MSC_VER) || defined(__MINGW32__)) +#if defined (PTW32_STATIC_LIB) && !(defined(_MSC_VER) || defined(__MINGW32__)) pthread_win32_process_detach_np(); #endif return 0; diff --git a/tests/semaphore1.c b/tests/semaphore1.c index 611e6557..d7d5a819 100644 --- a/tests/semaphore1.c +++ b/tests/semaphore1.c @@ -87,7 +87,7 @@ thr(void * arg) if ( result == -1 ) { int err = -#if defined(PTW32_USES_SEPARATE_CRT) +#if defined (PTW32_USES_SEPARATE_CRT) GetLastError(); #else errno; @@ -138,7 +138,7 @@ test_semaphore1(void) if (result2 == -1) { int err = -#if defined(PTW32_USES_SEPARATE_CRT) +#if defined (PTW32_USES_SEPARATE_CRT) GetLastError(); #else errno; diff --git a/tests/semaphore3.c b/tests/semaphore3.c index e2387051..16435cf9 100644 --- a/tests/semaphore3.c +++ b/tests/semaphore3.c @@ -16,17 +16,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/tests/semaphore4t.c b/tests/semaphore4t.c index fda3028f..5627760b 100644 --- a/tests/semaphore4t.c +++ b/tests/semaphore4t.c @@ -77,6 +77,8 @@ #define MAX_COUNT 100 +static const long NANOSEC_PER_SEC = 1000000000L; + static sem_t s; static void * @@ -86,6 +88,100 @@ thr (void * arg) return NULL; } +static int +timeoutwithnanos(sem_t sem, int nanoseconds) +{ + struct timespec ts, rel; + FILETIME ft_before, ft_after; + int rc; + + rel.tv_sec = 0; + rel.tv_nsec = nanoseconds; + + GetSystemTimeAsFileTime(&ft_before); + rc = sem_timedwait(&sem, pthread_win32_getabstime_np(&ts, &rel)); + + /* This should have timed out */ + assert(rc != 0); + assert(errno == ETIMEDOUT); + GetSystemTimeAsFileTime(&ft_after); + // We specified a non-zero wait. Time must advance. + if (ft_before.dwLowDateTime == ft_after.dwLowDateTime && ft_before.dwHighDateTime == ft_after.dwHighDateTime) + { + printf("nanoseconds: %d, rc: %d, errno: %d. before filetime: %d, %d; after filetime: %d, %d\n", + nanoseconds, rc, errno, + (int)ft_before.dwLowDateTime, (int)ft_before.dwHighDateTime, + (int)ft_after.dwLowDateTime, (int)ft_after.dwHighDateTime); + printf("time must advance during sem_timedwait."); + return 1; + } + return 0; +} + +static int +testtimeout() +{ + int rc = 0; + sem_t s2; + int value = 0; + assert(sem_init(&s2, PTHREAD_PROCESS_PRIVATE, 0) == 0); + assert(sem_getvalue(&s2, &value) == 0); + assert(value == 0); + + rc += timeoutwithnanos(s2, 1000); // 1 microsecond + rc += timeoutwithnanos(s2, 10 * 1000); // 10 microseconds + rc += timeoutwithnanos(s2, 100 * 1000); // 100 microseconds + rc += timeoutwithnanos(s2, 1000 * 1000); // 1 millisecond + + return rc; +} + +static int +testmainstuff() +{ + int value = 0; + int i; + pthread_t t[MAX_COUNT+1]; + + assert(sem_init(&s, PTHREAD_PROCESS_PRIVATE, 0) == 0); + assert(sem_getvalue(&s, &value) == 0); + assert(value == 0); + + for (i = 1; i <= MAX_COUNT; i++) + { + assert(pthread_create(&t[i], NULL, thr, NULL) == 0); + do { + sched_yield(); + assert(sem_getvalue(&s, &value) == 0); + } while (value != -i); + assert(-value == i); + } + + assert(sem_getvalue(&s, &value) == 0); + assert(-value == MAX_COUNT); + assert(pthread_cancel(t[50]) == 0); + assert(pthread_join(t[50], NULL) == 0); + assert(sem_getvalue(&s, &value) == 0); + assert(-value == MAX_COUNT - 1); + + for (i = MAX_COUNT - 2; i >= 0; i--) + { + assert(sem_post(&s) == 0); + assert(sem_getvalue(&s, &value) == 0); + assert(-value == i); + } + + for (i = 1; i <= MAX_COUNT; i++) + { + if (i != 50) + { + assert(pthread_join(t[i], NULL) == 0); + } + } + + return 0; +} + #ifndef MONOLITHIC_PTHREAD_TESTS int main() @@ -94,42 +190,11 @@ int test_semaphore4t(void) #endif { - int value = 0; - int i; - pthread_t t[MAX_COUNT+1]; - - assert(sem_init(&s, PTHREAD_PROCESS_PRIVATE, 0) == 0); - assert(sem_getvalue(&s, &value) == 0); - assert(value == 0); - - for (i = 1; i <= MAX_COUNT; i++) - { - assert(pthread_create(&t[i], NULL, thr, NULL) == 0); - do { - sched_yield(); - assert(sem_getvalue(&s, &value) == 0); - } while (value != -i); - assert(-value == i); - } - - assert(sem_getvalue(&s, &value) == 0); - assert(-value == MAX_COUNT); - assert(pthread_cancel(t[50]) == 0); - assert(pthread_join(t[50], NULL) == 0); - assert(sem_getvalue(&s, &value) == 0); - assert(-value == MAX_COUNT - 1); - - for (i = MAX_COUNT - 2; i >= 0; i--) - { - assert(sem_post(&s) == 0); - assert(sem_getvalue(&s, &value) == 0); - assert(-value == i); - } - - for (i = 1; i <= MAX_COUNT; i++) - if (i != 50) - assert(pthread_join(t[i], NULL) == 0); + int rc = 0; - return 0; + rc += testmainstuff(); + rc += testtimeout(); + + return rc; } diff --git a/tests/semaphore5.c b/tests/semaphore5.c index 91373019..5b9aa0d4 100644 --- a/tests/semaphore5.c +++ b/tests/semaphore5.c @@ -100,7 +100,11 @@ test_semaphore5(void) assert(pthread_create(&t, NULL, thr, (void *)&s) == 0); assert(sem_wait(&s) == 0); - assert(sem_destroy(&s) == 0); + /* + * Normally we would retry this next, but we're only + * interested in unexpected results in this test. + */ + assert(sem_destroy(&s) == 0 || errno == EBUSY); assert(pthread_join(t, NULL) == 0); diff --git a/tests/sequence1.c b/tests/sequence1.c index f2017dd0..78cc2994 100755 --- a/tests/sequence1.c +++ b/tests/sequence1.c @@ -36,7 +36,6 @@ * * Test Synopsis: * - that unique thread sequence numbers are generated. - * - Analyse thread struct reuse. * * Test Method (Validation or Falsification): * - @@ -81,7 +80,7 @@ */ enum { - NUMTHREADS = 10000 + NUMTHREADS = PTHREAD_THREADS_MAX }; diff --git a/tests/sizes.c b/tests/sizes.c index 556a84c2..3decc5f0 100644 --- a/tests/sizes.c +++ b/tests/sizes.c @@ -1,6 +1,8 @@ #define _WIN32_WINNT 0x400 #include "test.h" +/* Cheating here - sneaking a peek at library internals */ +#include "../config.h" #include "../implement.h" #ifndef MONOLITHIC_PTHREAD_TESTS diff --git a/tests/spin4.c b/tests/spin4.c index 3c2e5e1e..5f7d57cd 100644 --- a/tests/spin4.c +++ b/tests/spin4.c @@ -53,11 +53,11 @@ static int washere = 0; static void * func(void * arg) { - PTW32_FTIME(&currSysTimeStart); + PTW32_FTIME(&currSysTimeStart); washere = 1; assert(pthread_spin_lock(&lock) == 0); assert(pthread_spin_unlock(&lock) == 0); - PTW32_FTIME(&currSysTimeStop); + PTW32_FTIME(&currSysTimeStop); return (void *)(size_t)GetDurationMilliSecs(currSysTimeStart, currSysTimeStop); } @@ -73,7 +73,7 @@ test_spin4(void) void* result = (void*)0; pthread_t t; int CPUs; - PTW32_STRUCT_TIMEB sysTime; + PTW32_STRUCT_TIMEB sysTime; if ((CPUs = pthread_num_processors_np()) == 1) { @@ -93,7 +93,7 @@ test_spin4(void) do { sched_yield(); - PTW32_FTIME(&sysTime); + PTW32_FTIME(&sysTime); } while (GetDurationMilliSecs(currSysTimeStart, sysTime) <= 1000); diff --git a/tests/stress1.c b/tests/stress1.c index 09e1b8c5..2072f9d4 100644 --- a/tests/stress1.c +++ b/tests/stress1.c @@ -99,46 +99,12 @@ static int signalsTakenCount = 0; static int signalsSent = 0; static int bias = 0; static int timeout = 10; // Must be > 0 +static const long NANOSEC_PER_MILLISEC = 1000000; enum { CTL_STOP = -1 }; -/* - * Returns abstime 'milliseconds' from 'now'. - * - * Works for: -INT_MAX <= millisecs <= INT_MAX - */ -static struct timespec * -millisecondsFromNow (struct timespec * time, int millisecs) -{ - PTW32_STRUCT_TIMEB currSysTime; - int64_t nanosecs, secs; - const int64_t NANOSEC_PER_MILLISEC = 1000000; - const int64_t NANOSEC_PER_SEC = 1000000000; - - /* get current system time and add millisecs */ - PTW32_FTIME(&currSysTime); - - secs = (int64_t)(currSysTime.time) + (millisecs / 1000); - nanosecs = ((int64_t) (millisecs%1000 + currSysTime.millitm)) * NANOSEC_PER_MILLISEC; - if (nanosecs >= NANOSEC_PER_SEC) - { - secs++; - nanosecs -= NANOSEC_PER_SEC; - } - else if (nanosecs < 0) - { - secs--; - nanosecs += NANOSEC_PER_SEC; - } - - time->tv_nsec = (long)nanosecs; - time->tv_sec = (long)secs; - - return time; -} - static void * masterThread (void * arg) { @@ -204,16 +170,20 @@ masterThread (void * arg) static void * slaveThread (void * arg) { - struct timespec time; + struct timespec abstime, reltime; pthread_barrier_wait(&startBarrier); do { assert(pthread_mutex_lock(&control.mx) == 0); + + reltime.tv_sec = (control.value / 1000); + reltime.tv_nsec = (control.value % 1000) * NANOSEC_PER_MILLISEC; + if (pthread_cond_timedwait(&control.cv, &control.mx, - millisecondsFromNow(&time, control.value)) == ETIMEDOUT) + pthread_win32_getabstime_np(&abstime, &reltime)) == ETIMEDOUT) { timeoutCount++; } diff --git a/tests/test.h b/tests/test.h index 874b81ab..62fa8b60 100644 --- a/tests/test.h +++ b/tests/test.h @@ -39,6 +39,13 @@ #ifndef _PTHREAD_TEST_H_ #define _PTHREAD_TEST_H_ +/* + * Some tests sneak a peek at ../implement.h + * This is used inside ../implement.h to control + * what these test apps see and don't see. + */ +#define PTW32_TEST_SNEAK_PEEK + #include "../pthread.h" #include "../sched.h" #include "../semaphore.h" @@ -46,16 +53,22 @@ #include #include #include +/* + * FIXME: May not be available on all platforms. + */ +#include -#define PTW32_THREAD_NULL_ID {NULL,0} +#define PTW32_THREAD_NULL_ID {NULL,0} /* * Some non-thread POSIX API substitutes */ -#define rand_r( _seed ) \ +#if !defined(__MINGW64_VERSION_MAJOR) +# define rand_r( _seed ) \ ( _seed == _seed? rand() : rand() ) +#endif -#if defined(PTW32_CONFIG_MINGW) +#if defined(__MINGW32__) # include #elif defined(__BORLANDC__) # define int64_t ULONGLONG @@ -64,15 +77,15 @@ #endif #if defined(_MSC_VER) && _MSC_VER >= 1400 -# define PTW32_FTIME(x) _ftime64_s(x) -# define PTW32_STRUCT_TIMEB struct __timeb64 +# define PTW32_FTIME(x) _ftime64_s(x) +# define PTW32_STRUCT_TIMEB struct __timeb64 #elif ( defined(_MSC_VER) && _MSC_VER >= 1300 ) || \ - ( defined(PTW32_CONFIG_MINGW) && __MSVCRT_VERSION__ >= 0x0601 ) -# define PTW32_FTIME(x) _ftime64(x) -# define PTW32_STRUCT_TIMEB struct __timeb64 + ( defined(__MINGW32__) && __MSVCRT_VERSION__ >= 0x0601 ) +# define PTW32_FTIME(x) _ftime64(x) +# define PTW32_STRUCT_TIMEB struct __timeb64 #else -# define PTW32_FTIME(x) _ftime(x) -# define PTW32_STRUCT_TIMEB struct _timeb +# define PTW32_FTIME(x) _ftime(x) +# define PTW32_STRUCT_TIMEB struct _timeb #endif @@ -119,9 +132,12 @@ static const char * error_string[] = { "ENOLCK", "ENOSYS", "ENOTEMPTY", +#if PTW32_VERSION_MAJOR > 2 "EILSEQ", - "EOWNERDEAD", +#else + "EILSEQ_or_EOWNERDEAD", "ENOTRECOVERABLE" +#endif }; /* @@ -156,8 +172,12 @@ int assertE; #e, __FILE__, (int) __LINE__), \ fflush(stderr) : \ 0) : \ - (fprintf(stderr, "Assertion failed: (%s %s %s), file %s, line %d, error %s\n", \ - #e,#o,#r, __FILE__, (int) __LINE__, error_string[assertE]), exit(1), 0)) + (assertE <= (int) (sizeof(error_string)/sizeof(error_string[0]))) ? \ + (fprintf(stderr, "Assertion failed: (%s %s %s), file %s, line %d, error %s\n", \ + #e,#o,#r, __FILE__, (int) __LINE__, error_string[assertE]), exit(1), 0) :\ + (fprintf(stderr, \ + "Assertion failed: (%s %s %s), file %s, line %d, error %d\n", \ + #e,#o,#r, __FILE__, (int) __LINE__, assertE), exit(1), 0)) #endif diff --git a/tests/timeouts.c b/tests/timeouts.c index 499a2a53..272e9ce3 100644 --- a/tests/timeouts.c +++ b/tests/timeouts.c @@ -16,17 +16,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., @@ -91,7 +91,7 @@ #define CYG_ONEMILLION 1000000LL #define CYG_ONEKAPPA 1000LL -#if !(_MSC_VER <= 1200) +#if defined(_MSC_VER) && (_MSC_VER > 1200) typedef long long cyg_tim_t; //msvc > 6.0 #else typedef int64_t cyg_tim_t; //msvc 6.0 @@ -183,19 +183,19 @@ static pthread_cond_t cv_; static int Init(void) { - pthread_mutexattr_init(&mattr_); - pthread_mutex_init(&mutex_, &mattr_); - pthread_condattr_init(&cattr_); - pthread_cond_init(&cv_, &cattr_); + assert(0 == pthread_mutexattr_init(&mattr_)); + assert(0 == pthread_mutex_init(&mutex_, &mattr_)); + assert(0 == pthread_condattr_init(&cattr_)); + assert(0 == pthread_cond_init(&cv_, &cattr_)); return 0; } static int Destroy(void) { - pthread_cond_destroy(&cv_); - pthread_mutex_destroy(&mutex_); - pthread_mutexattr_destroy(&mattr_); - pthread_condattr_destroy(&cattr_); + assert(0 == pthread_cond_destroy(&cv_)); + assert(0 == pthread_mutex_destroy(&mutex_)); + assert(0 == pthread_mutexattr_destroy(&mattr_)); + assert(0 == pthread_condattr_destroy(&cattr_)); return 0; } @@ -213,11 +213,13 @@ static int Wait(time_t sec, long nsec) abstime.tv_sec += sc; abstime.tv_nsec %= 1000000000L; } - pthread_mutex_lock(&mutex_); + assert(0 == pthread_mutex_lock(&mutex_)); /* * We don't need to check the CV. */ result = pthread_cond_timedwait(&cv_, &mutex_, &abstime); + assert(result != 0); + assert(errno == ETIMEDOUT); pthread_mutex_unlock(&mutex_); return result; } diff --git a/tests/tsd1.c b/tests/tsd1.c index 25c6f612..43522972 100644 --- a/tests/tsd1.c +++ b/tests/tsd1.c @@ -18,17 +18,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/tests/tsd2.c b/tests/tsd2.c index 345e1050..96fd7c06 100644 --- a/tests/tsd2.c +++ b/tests/tsd2.c @@ -18,17 +18,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/tests/tsd3.c b/tests/tsd3.c index b88e5ca4..f005d66c 100644 --- a/tests/tsd3.c +++ b/tests/tsd3.c @@ -18,17 +18,17 @@ * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., diff --git a/tests/wrapper4tests_1.c b/tests/wrapper4tests_1.c index 9e5f9345..72f37143 100644 --- a/tests/wrapper4tests_1.c +++ b/tests/wrapper4tests_1.c @@ -77,7 +77,9 @@ int test_create3a(int argc, char **argv); int test_delay1(void); int test_delay2(void); int test_detach1(void); +int test_equal0(void); int test_equal1(void); +int test_errno0(void); int test_errno1(void); int test_exception1(void); int test_exception2(int argc, char **argv); @@ -328,7 +330,9 @@ int main(int argc, char **argv) TEST_WRAPPER(test_delay1); TEST_WRAPPER(test_delay2); TEST_WRAPPER(test_detach1); + TEST_WRAPPER(test_equal0); TEST_WRAPPER(test_equal1); + TEST_WRAPPER(test_errno0); TEST_WRAPPER(test_errno1); // TEST_WRAPPER(test_exception1); TEST_WRAPPER_W_ARGV(test_exception2); diff --git a/version.rc b/version.rc index d47d8450..bb8a8c8f 100644 --- a/version.rc +++ b/version.rc @@ -37,15 +37,15 @@ #include "pthread.h" /* - * Note: the correct __CLEANUP_* macro must be defined corresponding to + * Note: the correct PTW32_CLEANUP_* macro must be defined corresponding to * the definition used for the object file builds. This is done in the * relevent makefiles for the command line builds, but users should ensure * that their resource compiler knows what it is too. - * If using the default (no __CLEANUP_* defined), pthread.h will define it - * as __CLEANUP_C. + * If using the default (no PTW32_CLEANUP_* defined), pthread.h will define it + * as PTW32_CLEANUP_C. */ -#if defined(PTW32_RC_MSC) +#if defined (PTW32_RC_MSC) # if defined(PTW32_ARCHx64) # define PTW32_ARCH "x64" # elif defined(PTW32_ARCHx86) @@ -53,60 +53,88 @@ # else # error "PTW32_ARCHx64 / PTW32_ARCHx86 has not been defined" # endif -# if defined(__CLEANUP_C) -# define PTW32_VERSIONINFO_NAME "pthreadVC2.DLL\0" -# define PTW32_VERSIONINFO_DESCRIPTION "MS C " PTW32_ARCH "\0" -# elif defined(__CLEANUP_CXX) -# define PTW32_VERSIONINFO_NAME "pthreadVCE2.DLL\0" -# define PTW32_VERSIONINFO_DESCRIPTION "MS C++ " PTW32_ARCH "\0" -# elif defined(__CLEANUP_SEH) -# define PTW32_VERSIONINFO_NAME "pthreadVSE2.DLL\0" -# define PTW32_VERSIONINFO_DESCRIPTION "MS C SEH " PTW32_ARCH "\0" -# else -# error Resource compiler doesn't know which cleanup style you're using - see version.rc +# if defined(PTW32_CLEANUP_C) +# define PTW32_VERSIONINFO_NAME "pthreadVC2.DLL\0" +# elif defined(PTW32_CLEANUP_CXX) +# define PTW32_VERSIONINFO_NAME "pthreadVCE2.DLL\0" +# elif defined(PTW32_CLEANUP_SEH) +# define PTW32_VERSIONINFO_NAME "pthreadVSE2.DLL\0" +# endif +# if defined (PTW32_ARCHx64) || defined (PTW32_ARCHX64) || defined (PTW32_ARCHAMD64) +# if defined(PTW32_CLEANUP_C) +# define PTW32_VERSIONINFO_DESCRIPTION "MS C x64\0" +# elif defined(PTW32_CLEANUP_CXX) +# define PTW32_VERSIONINFO_DESCRIPTION "MS C++ x64\0" +# elif defined(PTW32_CLEANUP_SEH) +# define PTW32_VERSIONINFO_DESCRIPTION "MS C SEH x64\0" +# endif +# elif defined (PTW32_ARCHx86) || defined (PTW32_ARCHX86) +# if defined(PTW32_CLEANUP_C) +# define PTW32_VERSIONINFO_DESCRIPTION "MS C x86\0" +# elif defined(PTW32_CLEANUP_CXX) +# define PTW32_VERSIONINFO_DESCRIPTION "MS C++ x86\0" +# elif defined(PTW32_CLEANUP_SEH) +# define PTW32_VERSIONINFO_DESCRIPTION "MS C SEH x86\0" +# endif +# elif defined (PTW32_ARCHarm) || defined (PTW32_ARCHARM) || defined (PTW32_AARCH32) +# if defined(PTW32_CLEANUP_C) +# define PTW32_VERSIONINFO_DESCRIPTION "MS C ARM\0" +# elif defined(PTW32_CLEANUP_CXX) +# define PTW32_VERSIONINFO_DESCRIPTION "MS C++ ARM\0" +# elif defined(PTW32_CLEANUP_SEH) +# define PTW32_VERSIONINFO_DESCRIPTION "MS C SEH ARM\0" +# endif +# elif defined (PTW32_ARCHarm64) || defined (PTW32_ARCHARM64) || defined (PTW32_AARCH64) +# if defined(PTW32_CLEANUP_C) +# define PTW32_VERSIONINFO_DESCRIPTION "MS C ARM64\0" +# elif defined(PTW32_CLEANUP_CXX) +# define PTW32_VERSIONINFO_DESCRIPTION "MS C++ ARM64\0" +# elif defined(PTW32_CLEANUP_SEH) +# define PTW32_VERSIONINFO_DESCRIPTION "MS C SEH ARM64\0" +# endif # endif #elif defined(__GNUC__) # if defined(_M_X64) -# define PTW32_ARCH "x64 (mingw64)" +# define PTW32_ARCH "x64 (mingw64)" # else -# define PTW32_ARCH "x86 (mingw32)" +# define PTW32_ARCH "x86 (mingw32)" # endif -# if defined(__CLEANUP_C) -# define PTW32_VERSIONINFO_NAME "pthreadGC2.DLL\0" -# define PTW32_VERSIONINFO_DESCRIPTION "GNU C " PTW32_ARCH "\0" -# elif defined(__CLEANUP_CXX) -# define PTW32_VERSIONINFO_NAME "pthreadGCE2.DLL\0" -# define PTW32_VERSIONINFO_DESCRIPTION "GNU C++ " PTW32_ARCH "\0" +# if defined(PTW32_CLEANUP_C) +# define PTW32_VERSIONINFO_NAME "pthreadGC2.DLL\0" +# define PTW32_VERSIONINFO_DESCRIPTION "GNU C " PTW32_ARCH "\0" +# elif defined(PTW32_CLEANUP_CXX) +# define PTW32_VERSIONINFO_NAME "pthreadGCE2.DLL\0" +# define PTW32_VERSIONINFO_DESCRIPTION "GNU C++ " PTW32_ARCH "\0" # else # error Resource compiler doesn't know which cleanup style you're using - see version.rc # endif #elif defined(__BORLANDC__) # if defined(_M_X64) -# define PTW32_ARCH "x64 (Borland)" +# define PTW32_ARCH "x64 (Borland)" # else -# define PTW32_ARCH "x86 (Borland)" +# define PTW32_ARCH "x86 (Borland)" # endif -# if defined(__CLEANUP_C) -# define PTW32_VERSIONINFO_NAME "pthreadBC2.DLL\0" -# define PTW32_VERSIONINFO_DESCRIPTION "BORLAND C " PTW32_ARCH "\0" -# elif defined(__CLEANUP_CXX) -# define PTW32_VERSIONINFO_NAME "pthreadBCE2.DLL\0" -# define PTW32_VERSIONINFO_DESCRIPTION "BORLAND C++ " PTW32_ARCH "\0" +# if defined(PTW32_CLEANUP_C) +# define PTW32_VERSIONINFO_NAME "pthreadBC2.DLL\0" +# define PTW32_VERSIONINFO_DESCRIPTION "BORLAND C " PTW32_ARCH "\0" +# elif defined(PTW32_CLEANUP_CXX) +# define PTW32_VERSIONINFO_NAME "pthreadBCE2.DLL\0" +# define PTW32_VERSIONINFO_DESCRIPTION "BORLAND C++ " PTW32_ARCH "\0" # else # error Resource compiler doesn't know which cleanup style you're using - see version.rc # endif #elif defined(__WATCOMC__) # if defined(_M_X64) -# define PTW32_ARCH "x64 (Watcom)" +# define PTW32_ARCH "x64 (Watcom)" # else -# define PTW32_ARCH "x86 (Watcom)" +# define PTW32_ARCH "x86 (Watcom)" # endif -# if defined(__CLEANUP_C) -# define PTW32_VERSIONINFO_NAME "pthreadWC2.DLL\0" -# define PTW32_VERSIONINFO_DESCRIPTION "WATCOM C " PTW32_ARCH "\0" -# elif defined(__CLEANUP_CXX) -# define PTW32_VERSIONINFO_NAME "pthreadWCE2.DLL\0" -# define PTW32_VERSIONINFO_DESCRIPTION "WATCOM C++ " PTW32_ARCH "\0" +# if defined(PTW32_CLEANUP_C) +# define PTW32_VERSIONINFO_NAME "pthreadWC2.DLL\0" +# define PTW32_VERSIONINFO_DESCRIPTION "WATCOM C " PTW32_ARCH "\0" +# elif defined(PTW32_CLEANUP_CXX) +# define PTW32_VERSIONINFO_NAME "pthreadWCE2.DLL\0" +# define PTW32_VERSIONINFO_DESCRIPTION "WATCOM C++ " PTW32_ARCH "\0" # else # error Resource compiler doesn't know which cleanup style you're using - see version.rc # endif @@ -127,15 +155,15 @@ BEGIN BEGIN BLOCK "040904b0" BEGIN - VALUE "ProductName", "POSIX Threads for Windows LPGL\0" + VALUE "ProductName", "POSIX Threads for Windows\0" VALUE "ProductVersion", PTW32_VERSION_STRING VALUE "FileVersion", PTW32_VERSION_STRING VALUE "FileDescription", PTW32_VERSIONINFO_DESCRIPTION VALUE "InternalName", PTW32_VERSIONINFO_NAME VALUE "OriginalFilename", PTW32_VERSIONINFO_NAME - VALUE "CompanyName", "Open Source Software community LGPL\0" - VALUE "LegalCopyright", "Copyright (C) Project contributors 2012\0" - VALUE "Comments", "http://sourceware.org/pthreads-win32/\0" + VALUE "CompanyName", "Open Source Software community\0" + VALUE "LegalCopyright(C) 1999-2021 pthreads-win32 / pthreads4w contributors 1999-2021\0" + VALUE "Comments", "https://sourceforge.net/p/pthreads4w/wiki/Contributors/\0" END END BLOCK "VarFileInfo" diff --git a/w32_CancelableWait.c b/w32_CancelableWait.c index 219d87e1..1b7e1e71 100644 --- a/w32_CancelableWait.c +++ b/w32_CancelableWait.c @@ -52,7 +52,7 @@ ptw32_cancelable_wait (HANDLE waitHandle, DWORD timeout) * This provides an extra hook into the pthread_cancel * mechanism that will allow you to wait on a Windows handle and make it a * cancellation point. This function blocks until the given WIN32 handle is - * signaled or pthread_cancel has been called. It is implemented using + * signalled or pthread_cancel has been called. It is implemented using * WaitForMultipleObjects on 'waitHandle' and a manually reset WIN32 * event used to implement pthread_cancel. * @@ -92,7 +92,7 @@ ptw32_cancelable_wait (HANDLE waitHandle, DWORD timeout) handles[1] = NULL; } - status = WaitForMultipleObjects (nHandles, handles, PTW32_FALSE, timeout); + status = WaitForMultipleObjects (nHandles, handles, PTW32_FALSE, timeout); switch (status - WAIT_OBJECT_0) { @@ -110,7 +110,7 @@ ptw32_cancelable_wait (HANDLE waitHandle, DWORD timeout) case 1: /* * Got cancel request. - * In the event that both handles are signaled, the cancel will + * In the event that both handles are signalled, the cancel will * be ignored (see case 0 comment). */ if(handles[1]) ResetEvent (handles[1]); @@ -119,8 +119,8 @@ ptw32_cancelable_wait (HANDLE waitHandle, DWORD timeout) { ptw32_mcs_local_node_t stateLock; /* - * Should handle POSIX and implicit POSIX threads.. - * Make sure we haven't been async-canceled in the meantime. + * Should handle POSIX and implicit POSIX threads. + * Make sure we haven't been async-cancelled in the meantime. */ ptw32_mcs_lock_acquire (&sp->stateLock, &stateLock); if (sp->state < PThreadStateCanceling) @@ -128,7 +128,7 @@ ptw32_cancelable_wait (HANDLE waitHandle, DWORD timeout) sp->state = PThreadStateCanceling; sp->cancelState = PTHREAD_CANCEL_DISABLE; ptw32_mcs_lock_release (&stateLock); - ptw32_throw (PTW32_EPS_CANCEL); + ptw32_throw (PTW32_EPS_CANCEL); /* Never reached */ }