From bff6baacf1e9812ddf855bec5606f003db68a9ff Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Fri, 12 Jan 2024 09:25:54 +0300 Subject: [PATCH 01/29] druntime, DMD: replaces top level version(..) branching by tags More info https://github.com/dlang/dmd/pull/15887 --- druntime/Makefile | 57 ++- .../config/posix_threads/core/sync/event.d | 218 +++++++++++ druntime/config/windows/core/sync/event.d | 166 +++++++++ druntime/mak/COPY | 1 - druntime/mak/SRCS | 2 +- druntime/mak/TAGGED_COPY | 1 + druntime/parse_tagged_hier.sh | 82 ++++ druntime/src/core/internal/event_tests.d | 52 +++ druntime/src/core/sync/event.d | 349 ------------------ 9 files changed, 574 insertions(+), 354 deletions(-) create mode 100644 druntime/config/posix_threads/core/sync/event.d create mode 100644 druntime/config/windows/core/sync/event.d create mode 100644 druntime/mak/TAGGED_COPY create mode 100755 druntime/parse_tagged_hier.sh create mode 100644 druntime/src/core/internal/event_tests.d delete mode 100644 druntime/src/core/sync/event.d diff --git a/druntime/Makefile b/druntime/Makefile index 50e4104d2c6..9d2599d481a 100644 --- a/druntime/Makefile +++ b/druntime/Makefile @@ -135,14 +135,53 @@ DRUNTIMESOLIB=$(DRUNTIMESO)$(DOTLIB) STDDOC= +############### + +TAGGED_COPY_LIST_FILE:=mak/TAGGED_COPY +TAGGED_SRCS_FILE:=$(ROOT)/GEN_SRCS +TAGGED_COPY_FILE:=$(ROOT)/GEN_COPY + +ifeq (64,$(MODEL)) + ARCH_TAG:=x86_64 +else + ARCH_TAG:=x86 +endif + +ifeq (windows,$(OS)) + # Tags order doesn't matter + TAGS:=$(ARCH_TAG),windows +else + TAGS:=$(ARCH_TAG),$(OS),posix_threads +endif + +TGEN_CMD:=./parse_tagged_hier.sh config $(TAGGED_SRCS_FILE) $(TAGGED_COPY_LIST_FILE) $(TAGGED_COPY_FILE) $(TAGS) $(IMPDIR) > /dev/null + +TAGGED_SRCS:=$(shell $(TGEN_CMD) && cat $(TAGGED_SRCS_FILE)) + +# MacOS doesn't support .SHELLSTATUS +ifneq ($(.SHELLSTATUS),) + ifneq ($(.SHELLSTATUS),0) + $(error Tagged sources list generation failed) + endif +endif + +TAGGED_COPY:=$(shell $(TGEN_CMD) && cat $(TAGGED_COPY_FILE)) +ifneq ($(.SHELLSTATUS),) + ifneq ($(.SHELLSTATUS),0) + $(error Tagged copy list generation failed) + endif +endif + +############### + include mak/COPY -COPY:=$(subst \,/,$(COPY)) +COPY:=$(subst \,/,$(COPY)) $(subst \,/,$(TAGGED_COPY)) include mak/DOCS DOCS:=$(subst \,/,$(DOCS)) include mak/SRCS -SRCS:=$(subst \,/,$(SRCS)) +SRCS:=$(subst \,/,$(SRCS)) $(subst \,/,$(TAGGED_SRCS)) # NOTE: trace.d and cover.d are not necessary for a successful build # as both are used for debugging features (profiling and coverage) @@ -353,6 +392,13 @@ import: copy copy: $(COPY) +strip_first_dirs:=cut -d '/' -f4- +IMP_PATH=$(IMPDIR)/$(shell echo $@ | $(strip_first_dirs)) + +$(IMPDIR)/config/%.d : config/%.d + @mkdir -p $(dir $(IMP_PATH)) + @cp $< $(IMP_PATH) + $(IMPDIR)/%.di : src/%.di @mkdir -p $(dir $@) @cp $< $@ @@ -403,6 +449,11 @@ $(ROOT)/valgrind$(DOTOBJ) : src/etc/valgrind/valgrind.c src/etc/valgrind/valgrin @mkdir -p `dirname $@` $(CC) -c $(CFLAGS) $< -o$@ +################################################ + +gen_tagged_srcs_clean: + rm -f $(TAGGED_SRCS_FILE) $(TAGGED_SRCS_FILE).disabled $(TAGGED_COPY_FILE) + ######################## Create a shared library ############################## $(DRUNTIMESO) $(DRUNTIMESOLIB) dll: DFLAGS+=-version=Shared $(SHAREDFLAGS) @@ -562,7 +613,7 @@ install: target cp -r import/* '$(INSTALL_DIR)'/src/druntime/import/ endif -clean: $(addsuffix /.clean,$(ADDITIONAL_TESTS)) +clean: $(addsuffix /.clean,$(ADDITIONAL_TESTS)) gen_tagged_srcs_clean rm -rf $(ROOT_OF_THEM_ALL) $(IMPDIR) $(DOC_OUTPUT_DIR) druntime.zip test/%/.clean: test/%/Makefile diff --git a/druntime/config/posix_threads/core/sync/event.d b/druntime/config/posix_threads/core/sync/event.d new file mode 100644 index 00000000000..f4508d6b834 --- /dev/null +++ b/druntime/config/posix_threads/core/sync/event.d @@ -0,0 +1,218 @@ +/** + * The event module provides a primitive for lightweight signaling of other threads + * (emulating Windows events on Posix) + * + * Copyright: Copyright (c) 2019 D Language Foundation + * License: Distributed under the + * $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0). + * (See accompanying file LICENSE) + * Authors: Rainer Schuetze + * Source: $(DRUNTIMESRC core/sync/event.d) + */ +module core.sync.event; + +import core.sys.posix.pthread; +import core.sys.posix.sys.types; +import core.sys.posix.time; + +import core.time; +import core.internal.abort : abort; + +/** + * represents an event. Clients of an event are suspended while waiting + * for the event to be "signaled". + * + * Implemented using `pthread_mutex` and `pthread_condition` on Posix and + * `CreateEvent` and `SetEvent` on Windows. +--- +import core.sync.event, core.thread, std.file; + +struct ProcessFile +{ + ThreadGroup group; + Event event; + void[] buffer; + + void doProcess() + { + event.wait(); + // process buffer + } + + void process(string filename) + { + event.initialize(true, false); + group = new ThreadGroup; + for (int i = 0; i < 10; ++i) + group.create(&doProcess); + + buffer = std.file.read(filename); + event.setIfInitialized(); + group.joinAll(); + event.terminate(); + } +} +--- + */ +struct Event +{ +nothrow @nogc: + /** + * Creates an event object. + * + * Params: + * manualReset = the state of the event is not reset automatically after resuming waiting clients + * initialState = initial state of the signal + */ + this(bool manualReset, bool initialState) + { + initialize(manualReset, initialState); + } + + /** + * Initializes an event object. Does nothing if the event is already initialized. + * + * Params: + * manualReset = the state of the event is not reset automatically after resuming waiting clients + * initialState = initial state of the signal + */ + void initialize(bool manualReset, bool initialState) + { + if (m_initalized) + return; + pthread_mutex_init(cast(pthread_mutex_t*) &m_mutex, null) == 0 || + abort("Error: pthread_mutex_init failed."); + static if ( is( typeof( pthread_condattr_setclock ) ) ) + { + pthread_condattr_t attr = void; + pthread_condattr_init(&attr) == 0 || + abort("Error: pthread_condattr_init failed."); + pthread_condattr_setclock(&attr, CLOCK_MONOTONIC) == 0 || + abort("Error: pthread_condattr_setclock failed."); + pthread_cond_init(&m_cond, &attr) == 0 || + abort("Error: pthread_cond_init failed."); + pthread_condattr_destroy(&attr) == 0 || + abort("Error: pthread_condattr_destroy failed."); + } + else + { + pthread_cond_init(&m_cond, null) == 0 || + abort("Error: pthread_cond_init failed."); + } + m_state = initialState; + m_manualReset = manualReset; + m_initalized = true; + } + + // copying not allowed, can produce resource leaks + @disable this(this); + @disable void opAssign(Event); + + ~this() + { + terminate(); + } + + /** + * deinitialize event. Does nothing if the event is not initialized. There must not be + * threads currently waiting for the event to be signaled. + */ + void terminate() + { + if (m_initalized) + { + pthread_mutex_destroy(&m_mutex) == 0 || + abort("Error: pthread_mutex_destroy failed."); + pthread_cond_destroy(&m_cond) == 0 || + abort("Error: pthread_cond_destroy failed."); + m_initalized = false; + } + } + + deprecated ("Use setIfInitialized() instead") void set() + { + setIfInitialized(); + } + + /// Set the event to "signaled", so that waiting clients are resumed + void setIfInitialized() + { + if (m_initalized) + { + pthread_mutex_lock(&m_mutex); + m_state = true; + pthread_cond_broadcast(&m_cond); + pthread_mutex_unlock(&m_mutex); + } + } + + /// Reset the event manually + void reset() + { + if (m_initalized) + { + pthread_mutex_lock(&m_mutex); + m_state = false; + pthread_mutex_unlock(&m_mutex); + } + } + + /** + * Wait for the event to be signaled without timeout. + * + * Returns: + * `true` if the event is in signaled state, `false` if the event is uninitialized or another error occured + */ + bool wait() + { + return wait(Duration.max); + } + + /** + * Wait for the event to be signaled with timeout. + * + * Params: + * tmout = the maximum time to wait + * Returns: + * `true` if the event is in signaled state, `false` if the event was nonsignaled for the given time or + * the event is uninitialized or another error occured + */ + bool wait(Duration tmout) + { + if (!m_initalized) + return false; + + pthread_mutex_lock(&m_mutex); + + int result = 0; + if (!m_state) + { + if (tmout == Duration.max) + { + result = pthread_cond_wait(&m_cond, &m_mutex); + } + else + { + import core.sync.config; + + timespec t = void; + mktspec(t, tmout); + + result = pthread_cond_timedwait(&m_cond, &m_mutex, &t); + } + } + if (result == 0 && !m_manualReset) + m_state = false; + + pthread_mutex_unlock(&m_mutex); + + return result == 0; + } + +private: + pthread_mutex_t m_mutex; + pthread_cond_t m_cond; + bool m_initalized; + bool m_state; + bool m_manualReset; +} diff --git a/druntime/config/windows/core/sync/event.d b/druntime/config/windows/core/sync/event.d new file mode 100644 index 00000000000..57fc81a6c0f --- /dev/null +++ b/druntime/config/windows/core/sync/event.d @@ -0,0 +1,166 @@ +/** + * The event module provides a primitive for lightweight signaling of other threads + * (emulating Windows events on Posix) + * + * Copyright: Copyright (c) 2019 D Language Foundation + * License: Distributed under the + * $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0). + * (See accompanying file LICENSE) + * Authors: Rainer Schuetze + * Source: $(DRUNTIMESRC core/sync/event.d) + */ +module core.sync.event; + +import core.sys.windows.basetsd /+: HANDLE +/; +import core.sys.windows.winerror /+: WAIT_TIMEOUT +/; +import core.sys.windows.winbase /+: CreateEvent, CloseHandle, SetEvent, ResetEvent, + WaitForSingleObject, INFINITE, WAIT_OBJECT_0+/; + +import core.time; +import core.internal.abort : abort; + +/** + * represents an event. Clients of an event are suspended while waiting + * for the event to be "signaled". + * + * Implemented using `pthread_mutex` and `pthread_condition` on Posix and + * `CreateEvent` and `SetEvent` on Windows. +--- +import core.sync.event, core.thread, std.file; + +struct ProcessFile +{ + ThreadGroup group; + Event event; + void[] buffer; + + void doProcess() + { + event.wait(); + // process buffer + } + + void process(string filename) + { + event.initialize(true, false); + group = new ThreadGroup; + for (int i = 0; i < 10; ++i) + group.create(&doProcess); + + buffer = std.file.read(filename); + event.setIfInitialized(); + group.joinAll(); + event.terminate(); + } +} +--- + */ +struct Event +{ +nothrow @nogc: + /** + * Creates an event object. + * + * Params: + * manualReset = the state of the event is not reset automatically after resuming waiting clients + * initialState = initial state of the signal + */ + this(bool manualReset, bool initialState) + { + initialize(manualReset, initialState); + } + + /** + * Initializes an event object. Does nothing if the event is already initialized. + * + * Params: + * manualReset = the state of the event is not reset automatically after resuming waiting clients + * initialState = initial state of the signal + */ + void initialize(bool manualReset, bool initialState) + { + if (m_event) + return; + m_event = CreateEvent(null, manualReset, initialState, null); + m_event || abort("Error: CreateEvent failed."); + } + + // copying not allowed, can produce resource leaks + @disable this(this); + @disable void opAssign(Event); + + ~this() + { + terminate(); + } + + /** + * deinitialize event. Does nothing if the event is not initialized. There must not be + * threads currently waiting for the event to be signaled. + */ + void terminate() + { + if (m_event) + CloseHandle(m_event); + m_event = null; + } + + deprecated ("Use setIfInitialized() instead") void set() + { + setIfInitialized(); + } + + /// Set the event to "signaled", so that waiting clients are resumed + void setIfInitialized() + { + if (m_event) + SetEvent(m_event); + } + + /// Reset the event manually + void reset() + { + if (m_event) + ResetEvent(m_event); + } + + /** + * Wait for the event to be signaled without timeout. + * + * Returns: + * `true` if the event is in signaled state, `false` if the event is uninitialized or another error occured + */ + bool wait() + { + return m_event && WaitForSingleObject(m_event, INFINITE) == WAIT_OBJECT_0; + } + + /** + * Wait for the event to be signaled with timeout. + * + * Params: + * tmout = the maximum time to wait + * Returns: + * `true` if the event is in signaled state, `false` if the event was nonsignaled for the given time or + * the event is uninitialized or another error occured + */ + bool wait(Duration tmout) + { + if (!m_event) + return false; + + auto maxWaitMillis = dur!("msecs")(uint.max - 1); + + while (tmout > maxWaitMillis) + { + auto res = WaitForSingleObject(m_event, uint.max - 1); + if (res != WAIT_TIMEOUT) + return res == WAIT_OBJECT_0; + tmout -= maxWaitMillis; + } + auto ms = cast(uint)(tmout.total!"msecs"); + return WaitForSingleObject(m_event, ms) == WAIT_OBJECT_0; + } + + private HANDLE m_event; +} diff --git a/druntime/mak/COPY b/druntime/mak/COPY index 920b4f49710..efcb881a708 100644 --- a/druntime/mak/COPY +++ b/druntime/mak/COPY @@ -129,7 +129,6 @@ COPY=\ $(IMPDIR)\core\sync\barrier.d \ $(IMPDIR)\core\sync\condition.d \ $(IMPDIR)\core\sync\config.d \ - $(IMPDIR)\core\sync\event.d \ $(IMPDIR)\core\sync\exception.d \ $(IMPDIR)\core\sync\mutex.d \ $(IMPDIR)\core\sync\rwmutex.d \ diff --git a/druntime/mak/SRCS b/druntime/mak/SRCS index 1182c69d83b..bc64e2c1b67 100644 --- a/druntime/mak/SRCS +++ b/druntime/mak/SRCS @@ -32,6 +32,7 @@ SRCS=\ src\core\internal\dassert.d \ src\core\internal\destruction.d \ src\core\internal\entrypoint.d \ + src\core\internal\event_tests.d \ src\core\internal\execinfo.d \ src\core\internal\hash.d \ src\core\internal\moving.d \ @@ -128,7 +129,6 @@ SRCS=\ src\core\sync\condition.d \ src\core\sync\config.d \ src\core\sync\exception.d \ - src\core\sync\event.d \ src\core\sync\mutex.d \ src\core\sync\rwmutex.d \ src\core\sync\semaphore.d \ diff --git a/druntime/mak/TAGGED_COPY b/druntime/mak/TAGGED_COPY new file mode 100644 index 00000000000..0581bfa97e1 --- /dev/null +++ b/druntime/mak/TAGGED_COPY @@ -0,0 +1 @@ +core\sync\event.d diff --git a/druntime/parse_tagged_hier.sh b/druntime/parse_tagged_hier.sh new file mode 100755 index 00000000000..a6290842eae --- /dev/null +++ b/druntime/parse_tagged_hier.sh @@ -0,0 +1,82 @@ +#!/usr/bin/env bash + +set -euo pipefail + +SRC_DIR=$1 +DST_FILE=$2 +SRC_COPY_FILE=$3 +DST_COPY_FILE=$4 +TAGS=$5 +IMPDIR=$6 + +if [[ ! -d ${SRC_DIR} ]]; then + echo "Tags dir '${SRC_DIR}' not found" >&2 + exit 1 +fi + +if [[ -f ${DST_FILE} ]]; then + echo "Tagged sources list already generated" + exit 0 +fi + +TAGS_LIST=($(echo "$TAGS" | tr "," "\n")) + +echo -e "\nTags will be applied: $TAGS" + +APPLIED="" + +function applyTaggedFiles { + TAG=$1 + SRC_TAG_DIR=${SRC_DIR}/${TAG} + + if [[ ! -d ${SRC_TAG_DIR} ]]; then + echo "Warning: tag '${TAG}' doesn't corresponds to any subdirectory inside of '${SRC_DIR}', skip" >&2 + else + SRC_FILES_LIST+=($(find ${SRC_TAG_DIR} -type f )) + + pushd ${SRC_TAG_DIR} > /dev/null + MAYBE_COPY_LIST+=($(find * -type f )) + popd > /dev/null + fi + + APPLIED+=" $TAG" + + echo "Currently applied tags:$APPLIED" +} + +for tag in "${TAGS_LIST[@]}" +do + applyTaggedFiles ${tag} +done + +LINES_TO_COPY=$(grep -v '^$' ${SRC_COPY_FILE} | sort | uniq | wc -l) +COPIED=0 + +mkdir -p $(dirname ${DST_FILE}) +mkdir -p $(dirname ${DST_COPY_FILE}) +echo -ne > ${DST_FILE} +echo -ne > ${DST_COPY_FILE} + +for i in "${!SRC_FILES_LIST[@]}" +do + fl=$(echo ${SRC_FILES_LIST[$i]} | tr '/' '\\') + echo ${fl} >> ${DST_FILE} + + maybe_copy=$(echo ${MAYBE_COPY_LIST[$i]} | tr '/' '\\') + + # Adds copy entry if file mentioned in the list + grep -F "$maybe_copy" ${SRC_COPY_FILE} > /dev/null && { + echo ${IMPDIR}'\'${fl} >> ${DST_COPY_FILE} + COPIED=$((COPIED+1)) + } +done + +if [ $COPIED -ne $LINES_TO_COPY ]; then + echo "File '$SRC_COPY_FILE' contains $LINES_TO_COPY meaningful line(s), but to '$DST_COPY_FILE' added $COPIED line(s)" >&2 + + mv ${DST_FILE} "$DST_FILE.disabled" + echo "File '$DST_FILE' to '$DST_FILE.disabled' to avoid considering that tags parsing process was sucessfully done" >&2 + exit 1 +fi + +echo "All tags applied" diff --git a/druntime/src/core/internal/event_tests.d b/druntime/src/core/internal/event_tests.d new file mode 100644 index 00000000000..f504b2a51ab --- /dev/null +++ b/druntime/src/core/internal/event_tests.d @@ -0,0 +1,52 @@ +module core.internal.event_tests; + +import core.sync.event : Event; +import core.time; + +// Test single-thread (non-shared) use. +@nogc nothrow unittest +{ + // auto-reset, initial state false + Event ev1 = Event(false, false); + assert(!ev1.wait(1.dur!"msecs")); + ev1.setIfInitialized(); + assert(ev1.wait()); + assert(!ev1.wait(1.dur!"msecs")); + + // manual-reset, initial state true + Event ev2 = Event(true, true); + assert(ev2.wait()); + assert(ev2.wait()); + ev2.reset(); + assert(!ev2.wait(1.dur!"msecs")); +} + +unittest +{ + import core.thread, core.atomic; + + scope event = new Event(true, false); + int numThreads = 10; + shared int numRunning = 0; + + void testFn() + { + event.wait(8.dur!"seconds"); // timeout below limit for druntime test_runner + numRunning.atomicOp!"+="(1); + } + + auto group = new ThreadGroup; + + for (int i = 0; i < numThreads; ++i) + group.create(&testFn); + + auto start = MonoTime.currTime; + assert(numRunning == 0); + + event.setIfInitialized(); + group.joinAll(); + + assert(numRunning == numThreads); + + assert(MonoTime.currTime - start < 5.dur!"seconds"); +} diff --git a/druntime/src/core/sync/event.d b/druntime/src/core/sync/event.d deleted file mode 100644 index 048607f6ed2..00000000000 --- a/druntime/src/core/sync/event.d +++ /dev/null @@ -1,349 +0,0 @@ -/** - * The event module provides a primitive for lightweight signaling of other threads - * (emulating Windows events on Posix) - * - * Copyright: Copyright (c) 2019 D Language Foundation - * License: Distributed under the - * $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0). - * (See accompanying file LICENSE) - * Authors: Rainer Schuetze - * Source: $(DRUNTIMESRC core/sync/event.d) - */ -module core.sync.event; - -version (Windows) -{ - import core.sys.windows.basetsd /+: HANDLE +/; - import core.sys.windows.winerror /+: WAIT_TIMEOUT +/; - import core.sys.windows.winbase /+: CreateEvent, CloseHandle, SetEvent, ResetEvent, - WaitForSingleObject, INFINITE, WAIT_OBJECT_0+/; -} -else version (Posix) -{ - import core.sys.posix.pthread; - import core.sys.posix.sys.types; - import core.sys.posix.time; -} -else -{ - static assert(false, "Platform not supported"); -} - -import core.time; -import core.internal.abort : abort; - -/** - * represents an event. Clients of an event are suspended while waiting - * for the event to be "signaled". - * - * Implemented using `pthread_mutex` and `pthread_condition` on Posix and - * `CreateEvent` and `SetEvent` on Windows. ---- -import core.sync.event, core.thread, std.file; - -struct ProcessFile -{ - ThreadGroup group; - Event event; - void[] buffer; - - void doProcess() - { - event.wait(); - // process buffer - } - - void process(string filename) - { - event.initialize(true, false); - group = new ThreadGroup; - for (int i = 0; i < 10; ++i) - group.create(&doProcess); - - buffer = std.file.read(filename); - event.setIfInitialized(); - group.joinAll(); - event.terminate(); - } -} ---- - */ -struct Event -{ -nothrow @nogc: - /** - * Creates an event object. - * - * Params: - * manualReset = the state of the event is not reset automatically after resuming waiting clients - * initialState = initial state of the signal - */ - this(bool manualReset, bool initialState) - { - initialize(manualReset, initialState); - } - - /** - * Initializes an event object. Does nothing if the event is already initialized. - * - * Params: - * manualReset = the state of the event is not reset automatically after resuming waiting clients - * initialState = initial state of the signal - */ - void initialize(bool manualReset, bool initialState) - { - version (Windows) - { - if (m_event) - return; - m_event = CreateEvent(null, manualReset, initialState, null); - m_event || abort("Error: CreateEvent failed."); - } - else version (Posix) - { - if (m_initalized) - return; - pthread_mutex_init(cast(pthread_mutex_t*) &m_mutex, null) == 0 || - abort("Error: pthread_mutex_init failed."); - static if ( is( typeof( pthread_condattr_setclock ) ) ) - { - pthread_condattr_t attr = void; - pthread_condattr_init(&attr) == 0 || - abort("Error: pthread_condattr_init failed."); - pthread_condattr_setclock(&attr, CLOCK_MONOTONIC) == 0 || - abort("Error: pthread_condattr_setclock failed."); - pthread_cond_init(&m_cond, &attr) == 0 || - abort("Error: pthread_cond_init failed."); - pthread_condattr_destroy(&attr) == 0 || - abort("Error: pthread_condattr_destroy failed."); - } - else - { - pthread_cond_init(&m_cond, null) == 0 || - abort("Error: pthread_cond_init failed."); - } - m_state = initialState; - m_manualReset = manualReset; - m_initalized = true; - } - } - - // copying not allowed, can produce resource leaks - @disable this(this); - @disable void opAssign(Event); - - ~this() - { - terminate(); - } - - /** - * deinitialize event. Does nothing if the event is not initialized. There must not be - * threads currently waiting for the event to be signaled. - */ - void terminate() - { - version (Windows) - { - if (m_event) - CloseHandle(m_event); - m_event = null; - } - else version (Posix) - { - if (m_initalized) - { - pthread_mutex_destroy(&m_mutex) == 0 || - abort("Error: pthread_mutex_destroy failed."); - pthread_cond_destroy(&m_cond) == 0 || - abort("Error: pthread_cond_destroy failed."); - m_initalized = false; - } - } - } - - deprecated ("Use setIfInitialized() instead") void set() - { - setIfInitialized(); - } - - /// Set the event to "signaled", so that waiting clients are resumed - void setIfInitialized() - { - version (Windows) - { - if (m_event) - SetEvent(m_event); - } - else version (Posix) - { - if (m_initalized) - { - pthread_mutex_lock(&m_mutex); - m_state = true; - pthread_cond_broadcast(&m_cond); - pthread_mutex_unlock(&m_mutex); - } - } - } - - /// Reset the event manually - void reset() - { - version (Windows) - { - if (m_event) - ResetEvent(m_event); - } - else version (Posix) - { - if (m_initalized) - { - pthread_mutex_lock(&m_mutex); - m_state = false; - pthread_mutex_unlock(&m_mutex); - } - } - } - - /** - * Wait for the event to be signaled without timeout. - * - * Returns: - * `true` if the event is in signaled state, `false` if the event is uninitialized or another error occured - */ - bool wait() - { - version (Windows) - { - return m_event && WaitForSingleObject(m_event, INFINITE) == WAIT_OBJECT_0; - } - else version (Posix) - { - return wait(Duration.max); - } - } - - /** - * Wait for the event to be signaled with timeout. - * - * Params: - * tmout = the maximum time to wait - * Returns: - * `true` if the event is in signaled state, `false` if the event was nonsignaled for the given time or - * the event is uninitialized or another error occured - */ - bool wait(Duration tmout) - { - version (Windows) - { - if (!m_event) - return false; - - auto maxWaitMillis = dur!("msecs")(uint.max - 1); - - while (tmout > maxWaitMillis) - { - auto res = WaitForSingleObject(m_event, uint.max - 1); - if (res != WAIT_TIMEOUT) - return res == WAIT_OBJECT_0; - tmout -= maxWaitMillis; - } - auto ms = cast(uint)(tmout.total!"msecs"); - return WaitForSingleObject(m_event, ms) == WAIT_OBJECT_0; - } - else version (Posix) - { - if (!m_initalized) - return false; - - pthread_mutex_lock(&m_mutex); - - int result = 0; - if (!m_state) - { - if (tmout == Duration.max) - { - result = pthread_cond_wait(&m_cond, &m_mutex); - } - else - { - import core.sync.config; - - timespec t = void; - mktspec(t, tmout); - - result = pthread_cond_timedwait(&m_cond, &m_mutex, &t); - } - } - if (result == 0 && !m_manualReset) - m_state = false; - - pthread_mutex_unlock(&m_mutex); - - return result == 0; - } - } - -private: - version (Windows) - { - HANDLE m_event; - } - else version (Posix) - { - pthread_mutex_t m_mutex; - pthread_cond_t m_cond; - bool m_initalized; - bool m_state; - bool m_manualReset; - } -} - -// Test single-thread (non-shared) use. -@nogc nothrow unittest -{ - // auto-reset, initial state false - Event ev1 = Event(false, false); - assert(!ev1.wait(1.dur!"msecs")); - ev1.setIfInitialized(); - assert(ev1.wait()); - assert(!ev1.wait(1.dur!"msecs")); - - // manual-reset, initial state true - Event ev2 = Event(true, true); - assert(ev2.wait()); - assert(ev2.wait()); - ev2.reset(); - assert(!ev2.wait(1.dur!"msecs")); -} - -unittest -{ - import core.thread, core.atomic; - - scope event = new Event(true, false); - int numThreads = 10; - shared int numRunning = 0; - - void testFn() - { - event.wait(8.dur!"seconds"); // timeout below limit for druntime test_runner - numRunning.atomicOp!"+="(1); - } - - auto group = new ThreadGroup; - - for (int i = 0; i < numThreads; ++i) - group.create(&testFn); - - auto start = MonoTime.currTime; - assert(numRunning == 0); - - event.setIfInitialized(); - group.joinAll(); - - assert(numRunning == numThreads); - - assert(MonoTime.currTime - start < 5.dur!"seconds"); -} From 338888b1f9dacebcec065a03a402426de7a58529 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Fri, 12 Jan 2024 14:04:03 +0300 Subject: [PATCH 02/29] CMake: initial tags support, not works --- druntime/parse_tagged_hier.sh | 7 +++--- ldc/runtime/CMakeLists.txt | 43 +++++++++++++++++++++++++++++++---- ldc/runtime/copy_tagged.sh | 18 +++++++++++++++ 3 files changed, 60 insertions(+), 8 deletions(-) create mode 100755 ldc/runtime/copy_tagged.sh diff --git a/druntime/parse_tagged_hier.sh b/druntime/parse_tagged_hier.sh index a6290842eae..1459394664b 100755 --- a/druntime/parse_tagged_hier.sh +++ b/druntime/parse_tagged_hier.sh @@ -59,14 +59,15 @@ echo -ne > ${DST_COPY_FILE} for i in "${!SRC_FILES_LIST[@]}" do - fl=$(echo ${SRC_FILES_LIST[$i]} | tr '/' '\\') - echo ${fl} >> ${DST_FILE} + #~ fl=$(echo ${SRC_FILES_LIST[$i]} | tr '/' '\\') + echo ${SRC_FILES_LIST[$i]} >> ${DST_FILE} maybe_copy=$(echo ${MAYBE_COPY_LIST[$i]} | tr '/' '\\') # Adds copy entry if file mentioned in the list grep -F "$maybe_copy" ${SRC_COPY_FILE} > /dev/null && { - echo ${IMPDIR}'\'${fl} >> ${DST_COPY_FILE} + #~ echo ${IMPDIR}'\'${fl} >> ${DST_COPY_FILE} + echo ${IMPDIR}'/'${SRC_FILES_LIST[$i]} >> ${DST_COPY_FILE} COPIED=$((COPIED+1)) } done diff --git a/ldc/runtime/CMakeLists.txt b/ldc/runtime/CMakeLists.txt index f08427523d8..d225aa18f5d 100644 --- a/ldc/runtime/CMakeLists.txt +++ b/ldc/runtime/CMakeLists.txt @@ -1,6 +1,6 @@ project(runtime C) -cmake_minimum_required(VERSION 3.4.3) +cmake_minimum_required(VERSION 3.18) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}) @@ -141,6 +141,7 @@ message(STATUS "-- - Building LTO libraries (BUILD_LTO_LIBS): ${BUILD_LTO_LIBS} get_directory_property(PROJECT_PARENT_DIR DIRECTORY ${PROJECT_SOURCE_DIR} PARENT_DIRECTORY) set(RUNTIME_DIR ${PROJECT_SOURCE_DIR}/../../druntime CACHE PATH "druntime root directory") +set(RUNTIME_CFG_DIR ${RUNTIME_DIR}/config CACHE PATH "druntime internals config directory") set(PHOBOS2_DIR ${PROJECT_SOURCE_DIR}/../../phobos CACHE PATH "Phobos root directory") set(JITRT_DIR ${PROJECT_SOURCE_DIR}/jit-rt CACHE PATH "jit runtime root directory") @@ -165,6 +166,8 @@ list(REMOVE_ITEM DRUNTIME_D ${RUNTIME_DIR}/src/rt/sections_solaris.d ${RUNTIME_DIR}/src/rt/sections_win32.d ) +# create set of tags +set(TAGS "") # only include core/sys/ modules matching the platform file(GLOB_RECURSE DRUNTIME_D_BIONIC ${RUNTIME_DIR}/src/core/sys/bionic/*.d) file(GLOB_RECURSE DRUNTIME_D_DARWIN ${RUNTIME_DIR}/src/core/sys/darwin/*.d) @@ -183,8 +186,10 @@ list(REMOVE_ITEM DRUNTIME_D ${DRUNTIME_D_WINDOWS} ) if("${TARGET_SYSTEM}" MATCHES "Windows") + list(APPEND TAGS "windows") list(APPEND DRUNTIME_D ${DRUNTIME_D_WINDOWS}) elseif("${TARGET_SYSTEM}" MATCHES "UNIX") + list(APPEND TAGS "posix_threads") list(APPEND DRUNTIME_D ${DRUNTIME_D_POSIX}) if("${TARGET_SYSTEM}" MATCHES "APPLE") list(APPEND DRUNTIME_D ${DRUNTIME_D_DARWIN}) @@ -218,6 +223,37 @@ if("${TARGET_SYSTEM}" MATCHES "UNIX") list(APPEND DRUNTIME_ASM ${RUNTIME_DIR}/src/core/threadasm.S ${RUNTIME_DIR}/src/ldc/eh_asm.S) endif() +# Directory filled with auto-generated import files +set(LDC_BUILD_IMPORT_DIR "${PROJECT_BINARY_DIR}/import") + +# generate additional tags-based lists of files +set(TAGGED_COPY_LIST_FILE "${RUNTIME_DIR}/mak/TAGGED_COPY" CACHE PATH "additional list of files for copying into imports") + +list(JOIN TAGS "," TAGS_STR) +execute_process( + COMMAND "${PROJECT_SOURCE_DIR}/copy_tagged.sh" + "${RUNTIME_DIR}/parse_tagged_hier.sh" + ${RUNTIME_CFG_DIR} + ${TAGGED_COPY_LIST_FILE} + ${TAGS_STR} + ${LDC_BUILD_IMPORT_DIR} + ${PROJECT_BINARY_DIR} + ECHO_OUTPUT_VARIABLE + ECHO_ERROR_VARIABLE + COMMAND_ECHO STDOUT + COMMAND_ERROR_IS_FATAL ANY +) + +file(STRINGS ${PROJECT_BINARY_DIR}/GEN_SRCS TAGGED_SRCS) +file(STRINGS ${PROJECT_BINARY_DIR}/GEN_COPY TAGGED_COPY) + +#~ cmake_path(RELATIVE_PATH TAGGED_SRCS) + +#~ list(APPEND DRUNTIME_D "/home/denizzz/Dev/opend/ldc/runtime/../../druntime/config/posix_threads/core/sync/event.d") +list(APPEND DRUNTIME_D ${TAGGED_SRCS}) +message(${DRUNTIME_D}) +#~ message(FATAL_ERROR ${TAGGED_SRCS}) + if(PHOBOS2_DIR) # Phobos D parts file(GLOB_RECURSE PHOBOS2_D_ETC ${PHOBOS2_DIR}/etc/*.d) @@ -274,9 +310,6 @@ endif() # LLD 8+ requires (new) `--export-dynamic` for WebAssembly (https://github.com/ldc-developers/ldc/issues/3023). set(WASM_DEFAULT_LDC_SWITCHES "${WASM_DEFAULT_LDC_SWITCHES}\n \"-L--export-dynamic\",") -# Directory filled with auto-generated import files -set(LDC_BUILD_IMPORT_DIR "${PROJECT_BINARY_DIR}/import") - # Only generate the config files if this CMake project is embedded in the LDC CMake project. if(LDC_EXE) if(PHOBOS2_DIR) @@ -521,7 +554,7 @@ macro(compile_druntime d_flags lib_suffix path_suffix emit_bc all_at_once single set(single_obj_name "") endif() dc("${DRUNTIME_D}" - "${RUNTIME_DIR}/src" + "${RUNTIME_DIR}" "-conf=;${d_flags};${DRUNTIME_EXTRA_FLAGS};-I${RUNTIME_DIR}/src" "${PROJECT_BINARY_DIR}/objects${target_suffix}" "${emit_bc}" diff --git a/ldc/runtime/copy_tagged.sh b/ldc/runtime/copy_tagged.sh new file mode 100755 index 00000000000..adc85110365 --- /dev/null +++ b/ldc/runtime/copy_tagged.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -euo pipefail + +PARSE_SCRIPT=$1 +DRUNTIME_CFG_DIR=$2 +TAGGED_COPY_LIST_FILE=$3 +TAGS=$4 +IMPDIR=$5 +DST_DIR=$6 + +TAGGED_SRCS_FILE=${DST_DIR}/GEN_SRCS +TAGGED_COPY_FILE=${DST_DIR}/GEN_COPY + +${PARSE_SCRIPT} ${DRUNTIME_CFG_DIR} ${TAGGED_SRCS_FILE} ${TAGGED_COPY_LIST_FILE} ${TAGGED_COPY_FILE} ${TAGS} ${IMPDIR} + +#~ rm -f ${TAGGED_SRCS_FILE} +#~ rm -f ${TAGGED_COPY_FILE} From 48403cff63661e395d1ad1f9f2a859789d43a2de Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Fri, 12 Jan 2024 14:26:43 +0300 Subject: [PATCH 03/29] ldc2, CMake: druntime compilation directory is druntime/ --- ldc/runtime/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ldc/runtime/CMakeLists.txt b/ldc/runtime/CMakeLists.txt index d225aa18f5d..dce90baf4a3 100644 --- a/ldc/runtime/CMakeLists.txt +++ b/ldc/runtime/CMakeLists.txt @@ -766,7 +766,7 @@ macro(build_runtime_variant d_flags c_flags ld_flags lib_suffix path_suffix emit "${lib_suffix}${SHARED_LIB_SUFFIX}" "${path_suffix}" "OFF" "${all_d_files_at_once}" "OFF" druntime_o druntime_bc) - set(rt_dso_o "${PROJECT_BINARY_DIR}/objects${target_suffix}/rt/dso${CMAKE_C_OUTPUT_EXTENSION}") + set(rt_dso_o "${PROJECT_BINARY_DIR}/objects${target_suffix}/src/rt/dso${CMAKE_C_OUTPUT_EXTENSION}") # compile Phobos with public visibility (and preferably to a single object file) if(phobos2_common STREQUAL "") @@ -967,7 +967,7 @@ macro(compile_testrunner d_flags is_shared target_suffix extra_dir_suffix) if("${is_shared}" STREQUAL "ON") # also link-in special rt.dso druntime module - list(APPEND test_runner_o ${PROJECT_BINARY_DIR}/objects-unittest${target_suffix}/rt/dso${CMAKE_C_OUTPUT_EXTENSION}) + list(APPEND test_runner_o ${PROJECT_BINARY_DIR}/objects-unittest${target_suffix}/src/rt/dso${CMAKE_C_OUTPUT_EXTENSION}) endif() endmacro() @@ -1086,7 +1086,7 @@ add_custom_target(all-test-runners DEPENDS ${_GLOBAL_TESTRUNNERS}) macro(file_to_module_name file_name out_module_name) string(REPLACE ${PROJECT_SOURCE_DIR}/ "" stripped ${file_name}) - string(REPLACE "druntime/src/" "" stripped ${stripped}) + string(REPLACE "druntime/" "" stripped ${stripped}) string(REPLACE "phobos/" "" stripped ${stripped}) string(REPLACE ".d" "" stripped ${stripped}) string(REPLACE "/" "." module ${stripped}) From da2703bffdf2541d1ee918cf0ba11274a694f9f8 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Fri, 12 Jan 2024 18:05:17 +0300 Subject: [PATCH 04/29] druntime: tags import/ copying works --- ldc/runtime/CMakeLists.txt | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/ldc/runtime/CMakeLists.txt b/ldc/runtime/CMakeLists.txt index dce90baf4a3..6a2bf46e37b 100644 --- a/ldc/runtime/CMakeLists.txt +++ b/ldc/runtime/CMakeLists.txt @@ -1,6 +1,6 @@ project(runtime C) -cmake_minimum_required(VERSION 3.18) +cmake_minimum_required(VERSION 3.4.3) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}) @@ -142,6 +142,7 @@ message(STATUS "-- - Building LTO libraries (BUILD_LTO_LIBS): ${BUILD_LTO_LIBS} get_directory_property(PROJECT_PARENT_DIR DIRECTORY ${PROJECT_SOURCE_DIR} PARENT_DIRECTORY) set(RUNTIME_DIR ${PROJECT_SOURCE_DIR}/../../druntime CACHE PATH "druntime root directory") set(RUNTIME_CFG_DIR ${RUNTIME_DIR}/config CACHE PATH "druntime internals config directory") +cmake_path(NORMAL_PATH RUNTIME_CFG_DIR) set(PHOBOS2_DIR ${PROJECT_SOURCE_DIR}/../../phobos CACHE PATH "Phobos root directory") set(JITRT_DIR ${PROJECT_SOURCE_DIR}/jit-rt CACHE PATH "jit runtime root directory") @@ -223,9 +224,6 @@ if("${TARGET_SYSTEM}" MATCHES "UNIX") list(APPEND DRUNTIME_ASM ${RUNTIME_DIR}/src/core/threadasm.S ${RUNTIME_DIR}/src/ldc/eh_asm.S) endif() -# Directory filled with auto-generated import files -set(LDC_BUILD_IMPORT_DIR "${PROJECT_BINARY_DIR}/import") - # generate additional tags-based lists of files set(TAGGED_COPY_LIST_FILE "${RUNTIME_DIR}/mak/TAGGED_COPY" CACHE PATH "additional list of files for copying into imports") @@ -236,7 +234,7 @@ execute_process( ${RUNTIME_CFG_DIR} ${TAGGED_COPY_LIST_FILE} ${TAGS_STR} - ${LDC_BUILD_IMPORT_DIR} + "/" ${PROJECT_BINARY_DIR} ECHO_OUTPUT_VARIABLE ECHO_ERROR_VARIABLE @@ -247,12 +245,26 @@ execute_process( file(STRINGS ${PROJECT_BINARY_DIR}/GEN_SRCS TAGGED_SRCS) file(STRINGS ${PROJECT_BINARY_DIR}/GEN_COPY TAGGED_COPY) -#~ cmake_path(RELATIVE_PATH TAGGED_SRCS) - -#~ list(APPEND DRUNTIME_D "/home/denizzz/Dev/opend/ldc/runtime/../../druntime/config/posix_threads/core/sync/event.d") list(APPEND DRUNTIME_D ${TAGGED_SRCS}) -message(${DRUNTIME_D}) -#~ message(FATAL_ERROR ${TAGGED_SRCS}) + +# Directory filled with auto-generated import files +set(LDC_BUILD_IMPORT_DIR "${PROJECT_BINARY_DIR}/import") + +foreach(incl_file ${TAGGED_COPY}) + cmake_path(NORMAL_PATH incl_file) + string(REPLACE ${RUNTIME_CFG_DIR} "" dst_file ${incl_file}) + + # strip first unused dirs from file path + execute_process( + COMMAND "echo" ${dst_file} + COMMAND "cut" -d / -f3- + OUTPUT_VARIABLE pretty_dst_path + COMMAND_ERROR_IS_FATAL ANY + ) + + get_filename_component(path ${pretty_dst_path} PATH) + file(INSTALL ${incl_file} DESTINATION ${LDC_BUILD_IMPORT_DIR}/${path}) +endforeach() if(PHOBOS2_DIR) # Phobos D parts From fd313746aa921633baf91188950d1616704d387d Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Fri, 12 Jan 2024 18:19:28 +0300 Subject: [PATCH 05/29] Unnecessary copy_tagged.sh removed --- ldc/runtime/CMakeLists.txt | 10 ++++++---- ldc/runtime/copy_tagged.sh | 18 ------------------ 2 files changed, 6 insertions(+), 22 deletions(-) delete mode 100755 ldc/runtime/copy_tagged.sh diff --git a/ldc/runtime/CMakeLists.txt b/ldc/runtime/CMakeLists.txt index 6a2bf46e37b..ce9d24f3c09 100644 --- a/ldc/runtime/CMakeLists.txt +++ b/ldc/runtime/CMakeLists.txt @@ -225,17 +225,19 @@ if("${TARGET_SYSTEM}" MATCHES "UNIX") endif() # generate additional tags-based lists of files -set(TAGGED_COPY_LIST_FILE "${RUNTIME_DIR}/mak/TAGGED_COPY" CACHE PATH "additional list of files for copying into imports") +set(TAGGED_COPY_LIST_FILE "${RUNTIME_DIR}/mak/TAGGED_COPY" CACHE FILEPATH "additional list of files for copying into imports") +set(TAGGED_SRCS_FILE "${PROJECT_BINARY_DIR}/GEN_SRCS" CACHE FILEPATH "generated list of sources choised by tags") +set(TAGGED_COPY_FILE "${PROJECT_BINARY_DIR}/GEN_COPY" CACHE FILEPATH "generated list of imports choised by tags") list(JOIN TAGS "," TAGS_STR) execute_process( - COMMAND "${PROJECT_SOURCE_DIR}/copy_tagged.sh" - "${RUNTIME_DIR}/parse_tagged_hier.sh" + COMMAND "${RUNTIME_DIR}/parse_tagged_hier.sh" ${RUNTIME_CFG_DIR} + ${TAGGED_SRCS_FILE} ${TAGGED_COPY_LIST_FILE} + ${TAGGED_COPY_FILE} ${TAGS_STR} "/" - ${PROJECT_BINARY_DIR} ECHO_OUTPUT_VARIABLE ECHO_ERROR_VARIABLE COMMAND_ECHO STDOUT diff --git a/ldc/runtime/copy_tagged.sh b/ldc/runtime/copy_tagged.sh deleted file mode 100755 index adc85110365..00000000000 --- a/ldc/runtime/copy_tagged.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -PARSE_SCRIPT=$1 -DRUNTIME_CFG_DIR=$2 -TAGGED_COPY_LIST_FILE=$3 -TAGS=$4 -IMPDIR=$5 -DST_DIR=$6 - -TAGGED_SRCS_FILE=${DST_DIR}/GEN_SRCS -TAGGED_COPY_FILE=${DST_DIR}/GEN_COPY - -${PARSE_SCRIPT} ${DRUNTIME_CFG_DIR} ${TAGGED_SRCS_FILE} ${TAGGED_COPY_LIST_FILE} ${TAGGED_COPY_FILE} ${TAGS} ${IMPDIR} - -#~ rm -f ${TAGGED_SRCS_FILE} -#~ rm -f ${TAGGED_COPY_FILE} From 26d461b43b71efb879bb881d8571dfb9f0229d0a Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Fri, 12 Jan 2024 18:53:24 +0300 Subject: [PATCH 06/29] commented code removed (Windows slashes is deprecated) --- druntime/parse_tagged_hier.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/druntime/parse_tagged_hier.sh b/druntime/parse_tagged_hier.sh index 1459394664b..c7ec51d886a 100755 --- a/druntime/parse_tagged_hier.sh +++ b/druntime/parse_tagged_hier.sh @@ -59,14 +59,12 @@ echo -ne > ${DST_COPY_FILE} for i in "${!SRC_FILES_LIST[@]}" do - #~ fl=$(echo ${SRC_FILES_LIST[$i]} | tr '/' '\\') echo ${SRC_FILES_LIST[$i]} >> ${DST_FILE} maybe_copy=$(echo ${MAYBE_COPY_LIST[$i]} | tr '/' '\\') # Adds copy entry if file mentioned in the list grep -F "$maybe_copy" ${SRC_COPY_FILE} > /dev/null && { - #~ echo ${IMPDIR}'\'${fl} >> ${DST_COPY_FILE} echo ${IMPDIR}'/'${SRC_FILES_LIST[$i]} >> ${DST_COPY_FILE} COPIED=$((COPIED+1)) } From a3d727f7258f753742b1398344bcd62fdf5d4743 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Fri, 12 Jan 2024 21:05:38 +0300 Subject: [PATCH 07/29] druntime: parse_tagged_hier.sh args rearranged for future use --- druntime/Makefile | 2 +- druntime/parse_tagged_hier.sh | 10 +++++----- ldc/runtime/CMakeLists.txt | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/druntime/Makefile b/druntime/Makefile index 9d2599d481a..b901cec693b 100644 --- a/druntime/Makefile +++ b/druntime/Makefile @@ -154,7 +154,7 @@ else TAGS:=$(ARCH_TAG),$(OS),posix_threads endif -TGEN_CMD:=./parse_tagged_hier.sh config $(TAGGED_SRCS_FILE) $(TAGGED_COPY_LIST_FILE) $(TAGGED_COPY_FILE) $(TAGS) $(IMPDIR) > /dev/null +TGEN_CMD:=./parse_tagged_hier.sh $(TAGGED_SRCS_FILE) $(TAGGED_COPY_LIST_FILE) $(TAGGED_COPY_FILE) $(IMPDIR) $(TAGS) config > /dev/null TAGGED_SRCS:=$(shell $(TGEN_CMD) && cat $(TAGGED_SRCS_FILE)) diff --git a/druntime/parse_tagged_hier.sh b/druntime/parse_tagged_hier.sh index c7ec51d886a..1cdb09a8f2e 100755 --- a/druntime/parse_tagged_hier.sh +++ b/druntime/parse_tagged_hier.sh @@ -2,12 +2,12 @@ set -euo pipefail -SRC_DIR=$1 -DST_FILE=$2 -SRC_COPY_FILE=$3 -DST_COPY_FILE=$4 +DST_FILE=$1 +SRC_COPY_FILE=$2 +DST_COPY_FILE=$3 +IMPDIR=$4 TAGS=$5 -IMPDIR=$6 +SRC_DIR=$6 if [[ ! -d ${SRC_DIR} ]]; then echo "Tags dir '${SRC_DIR}' not found" >&2 diff --git a/ldc/runtime/CMakeLists.txt b/ldc/runtime/CMakeLists.txt index ce9d24f3c09..a26db7de7cc 100644 --- a/ldc/runtime/CMakeLists.txt +++ b/ldc/runtime/CMakeLists.txt @@ -232,12 +232,12 @@ set(TAGGED_COPY_FILE "${PROJECT_BINARY_DIR}/GEN_COPY" CACHE FILEPATH "generated list(JOIN TAGS "," TAGS_STR) execute_process( COMMAND "${RUNTIME_DIR}/parse_tagged_hier.sh" - ${RUNTIME_CFG_DIR} ${TAGGED_SRCS_FILE} ${TAGGED_COPY_LIST_FILE} ${TAGGED_COPY_FILE} - ${TAGS_STR} "/" + ${TAGS_STR} + ${RUNTIME_CFG_DIR} ECHO_OUTPUT_VARIABLE ECHO_ERROR_VARIABLE COMMAND_ECHO STDOUT From 38c0f60524bf5615bf13f25fd25efbdb9548641b Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Fri, 12 Jan 2024 21:09:00 +0300 Subject: [PATCH 08/29] cmake: debug echo output removed, error messages output enabled --- ldc/runtime/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ldc/runtime/CMakeLists.txt b/ldc/runtime/CMakeLists.txt index a26db7de7cc..187801d5da1 100644 --- a/ldc/runtime/CMakeLists.txt +++ b/ldc/runtime/CMakeLists.txt @@ -240,7 +240,6 @@ execute_process( ${RUNTIME_CFG_DIR} ECHO_OUTPUT_VARIABLE ECHO_ERROR_VARIABLE - COMMAND_ECHO STDOUT COMMAND_ERROR_IS_FATAL ANY ) @@ -261,6 +260,7 @@ foreach(incl_file ${TAGGED_COPY}) COMMAND "echo" ${dst_file} COMMAND "cut" -d / -f3- OUTPUT_VARIABLE pretty_dst_path + ECHO_ERROR_VARIABLE COMMAND_ERROR_IS_FATAL ANY ) From 4a54eecbdd890c22fc1c996d303785a1b033ee30 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Sat, 13 Jan 2024 09:29:55 +0300 Subject: [PATCH 09/29] CMake: install tagged imports added --- ldc/runtime/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ldc/runtime/CMakeLists.txt b/ldc/runtime/CMakeLists.txt index 187801d5da1..da3d8387775 100644 --- a/ldc/runtime/CMakeLists.txt +++ b/ldc/runtime/CMakeLists.txt @@ -265,7 +265,7 @@ foreach(incl_file ${TAGGED_COPY}) ) get_filename_component(path ${pretty_dst_path} PATH) - file(INSTALL ${incl_file} DESTINATION ${LDC_BUILD_IMPORT_DIR}/${path}) + file(INSTALL ${incl_file} DESTINATION ${LDC_BUILD_IMPORT_DIR}/tagged_imports/${path}) endforeach() if(PHOBOS2_DIR) @@ -917,6 +917,7 @@ if(PHOBOS2_DIR) install(DIRECTORY ${PHOBOS2_DIR}/etc DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN "*.d") endif() install(FILES ${GCCBUILTINS} DESTINATION ${INCLUDE_INSTALL_DIR}/ldc) +install(DIRECTORY ${LDC_BUILD_IMPORT_DIR}/tagged_imports/ DESTINATION ${INCLUDE_INSTALL_DIR}) # From 87fdcfe1fd06dfa84273c7ca84e15982a55fac33 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Sun, 14 Jan 2024 00:32:49 +0300 Subject: [PATCH 10/29] files paths replaced by variables --- ldc/runtime/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ldc/runtime/CMakeLists.txt b/ldc/runtime/CMakeLists.txt index da3d8387775..c432a2ff293 100644 --- a/ldc/runtime/CMakeLists.txt +++ b/ldc/runtime/CMakeLists.txt @@ -243,8 +243,8 @@ execute_process( COMMAND_ERROR_IS_FATAL ANY ) -file(STRINGS ${PROJECT_BINARY_DIR}/GEN_SRCS TAGGED_SRCS) -file(STRINGS ${PROJECT_BINARY_DIR}/GEN_COPY TAGGED_COPY) +file(STRINGS ${TAGGED_SRCS_FILE} TAGGED_SRCS) +file(STRINGS ${TAGGED_COPY_FILE} TAGGED_COPY) list(APPEND DRUNTIME_D ${TAGGED_SRCS}) From 0fc476887960e057e8232975e7e1356e9a541d27 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Tue, 30 Jan 2024 23:49:13 +0300 Subject: [PATCH 11/29] test module moved: core.internal.event_tests -> core.sync.event_tests --- druntime/mak/SRCS | 2 +- druntime/src/core/{internal => sync}/event_tests.d | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename druntime/src/core/{internal => sync}/event_tests.d (97%) diff --git a/druntime/mak/SRCS b/druntime/mak/SRCS index bc64e2c1b67..cfc3ccade4c 100644 --- a/druntime/mak/SRCS +++ b/druntime/mak/SRCS @@ -32,7 +32,6 @@ SRCS=\ src\core\internal\dassert.d \ src\core\internal\destruction.d \ src\core\internal\entrypoint.d \ - src\core\internal\event_tests.d \ src\core\internal\execinfo.d \ src\core\internal\hash.d \ src\core\internal\moving.d \ @@ -128,6 +127,7 @@ SRCS=\ src\core\sync\barrier.d \ src\core\sync\condition.d \ src\core\sync\config.d \ + src\core\sync\event_tests.d \ src\core\sync\exception.d \ src\core\sync\mutex.d \ src\core\sync\rwmutex.d \ diff --git a/druntime/src/core/internal/event_tests.d b/druntime/src/core/sync/event_tests.d similarity index 97% rename from druntime/src/core/internal/event_tests.d rename to druntime/src/core/sync/event_tests.d index f504b2a51ab..1ac2e90d973 100644 --- a/druntime/src/core/internal/event_tests.d +++ b/druntime/src/core/sync/event_tests.d @@ -1,4 +1,4 @@ -module core.internal.event_tests; +module core.sync.event_tests; import core.sync.event : Event; import core.time; From 9e9a278ede0c42ee382c531a1d668b4c525cd55a Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Thu, 1 Feb 2024 23:53:10 +0300 Subject: [PATCH 12/29] event.d + event_tests.d -> event.d + event_impl.d --- .../config/posix_threads/core/sync/event.d | 218 ------------------ .../posix_threads/core/sync/event_impl.d | 115 +++++++++ .../config/windows/core/sync/event_impl.d | 60 +++++ druntime/mak/COPY | 1 + druntime/mak/SRCS | 2 +- druntime/mak/TAGGED_COPY | 2 +- .../{config/windows => src}/core/sync/event.d | 93 +++++--- druntime/src/core/sync/event_tests.d | 52 ----- 8 files changed, 241 insertions(+), 302 deletions(-) delete mode 100644 druntime/config/posix_threads/core/sync/event.d create mode 100644 druntime/config/posix_threads/core/sync/event_impl.d create mode 100644 druntime/config/windows/core/sync/event_impl.d rename druntime/{config/windows => src}/core/sync/event.d (66%) delete mode 100644 druntime/src/core/sync/event_tests.d diff --git a/druntime/config/posix_threads/core/sync/event.d b/druntime/config/posix_threads/core/sync/event.d deleted file mode 100644 index f4508d6b834..00000000000 --- a/druntime/config/posix_threads/core/sync/event.d +++ /dev/null @@ -1,218 +0,0 @@ -/** - * The event module provides a primitive for lightweight signaling of other threads - * (emulating Windows events on Posix) - * - * Copyright: Copyright (c) 2019 D Language Foundation - * License: Distributed under the - * $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0). - * (See accompanying file LICENSE) - * Authors: Rainer Schuetze - * Source: $(DRUNTIMESRC core/sync/event.d) - */ -module core.sync.event; - -import core.sys.posix.pthread; -import core.sys.posix.sys.types; -import core.sys.posix.time; - -import core.time; -import core.internal.abort : abort; - -/** - * represents an event. Clients of an event are suspended while waiting - * for the event to be "signaled". - * - * Implemented using `pthread_mutex` and `pthread_condition` on Posix and - * `CreateEvent` and `SetEvent` on Windows. ---- -import core.sync.event, core.thread, std.file; - -struct ProcessFile -{ - ThreadGroup group; - Event event; - void[] buffer; - - void doProcess() - { - event.wait(); - // process buffer - } - - void process(string filename) - { - event.initialize(true, false); - group = new ThreadGroup; - for (int i = 0; i < 10; ++i) - group.create(&doProcess); - - buffer = std.file.read(filename); - event.setIfInitialized(); - group.joinAll(); - event.terminate(); - } -} ---- - */ -struct Event -{ -nothrow @nogc: - /** - * Creates an event object. - * - * Params: - * manualReset = the state of the event is not reset automatically after resuming waiting clients - * initialState = initial state of the signal - */ - this(bool manualReset, bool initialState) - { - initialize(manualReset, initialState); - } - - /** - * Initializes an event object. Does nothing if the event is already initialized. - * - * Params: - * manualReset = the state of the event is not reset automatically after resuming waiting clients - * initialState = initial state of the signal - */ - void initialize(bool manualReset, bool initialState) - { - if (m_initalized) - return; - pthread_mutex_init(cast(pthread_mutex_t*) &m_mutex, null) == 0 || - abort("Error: pthread_mutex_init failed."); - static if ( is( typeof( pthread_condattr_setclock ) ) ) - { - pthread_condattr_t attr = void; - pthread_condattr_init(&attr) == 0 || - abort("Error: pthread_condattr_init failed."); - pthread_condattr_setclock(&attr, CLOCK_MONOTONIC) == 0 || - abort("Error: pthread_condattr_setclock failed."); - pthread_cond_init(&m_cond, &attr) == 0 || - abort("Error: pthread_cond_init failed."); - pthread_condattr_destroy(&attr) == 0 || - abort("Error: pthread_condattr_destroy failed."); - } - else - { - pthread_cond_init(&m_cond, null) == 0 || - abort("Error: pthread_cond_init failed."); - } - m_state = initialState; - m_manualReset = manualReset; - m_initalized = true; - } - - // copying not allowed, can produce resource leaks - @disable this(this); - @disable void opAssign(Event); - - ~this() - { - terminate(); - } - - /** - * deinitialize event. Does nothing if the event is not initialized. There must not be - * threads currently waiting for the event to be signaled. - */ - void terminate() - { - if (m_initalized) - { - pthread_mutex_destroy(&m_mutex) == 0 || - abort("Error: pthread_mutex_destroy failed."); - pthread_cond_destroy(&m_cond) == 0 || - abort("Error: pthread_cond_destroy failed."); - m_initalized = false; - } - } - - deprecated ("Use setIfInitialized() instead") void set() - { - setIfInitialized(); - } - - /// Set the event to "signaled", so that waiting clients are resumed - void setIfInitialized() - { - if (m_initalized) - { - pthread_mutex_lock(&m_mutex); - m_state = true; - pthread_cond_broadcast(&m_cond); - pthread_mutex_unlock(&m_mutex); - } - } - - /// Reset the event manually - void reset() - { - if (m_initalized) - { - pthread_mutex_lock(&m_mutex); - m_state = false; - pthread_mutex_unlock(&m_mutex); - } - } - - /** - * Wait for the event to be signaled without timeout. - * - * Returns: - * `true` if the event is in signaled state, `false` if the event is uninitialized or another error occured - */ - bool wait() - { - return wait(Duration.max); - } - - /** - * Wait for the event to be signaled with timeout. - * - * Params: - * tmout = the maximum time to wait - * Returns: - * `true` if the event is in signaled state, `false` if the event was nonsignaled for the given time or - * the event is uninitialized or another error occured - */ - bool wait(Duration tmout) - { - if (!m_initalized) - return false; - - pthread_mutex_lock(&m_mutex); - - int result = 0; - if (!m_state) - { - if (tmout == Duration.max) - { - result = pthread_cond_wait(&m_cond, &m_mutex); - } - else - { - import core.sync.config; - - timespec t = void; - mktspec(t, tmout); - - result = pthread_cond_timedwait(&m_cond, &m_mutex, &t); - } - } - if (result == 0 && !m_manualReset) - m_state = false; - - pthread_mutex_unlock(&m_mutex); - - return result == 0; - } - -private: - pthread_mutex_t m_mutex; - pthread_cond_t m_cond; - bool m_initalized; - bool m_state; - bool m_manualReset; -} diff --git a/druntime/config/posix_threads/core/sync/event_impl.d b/druntime/config/posix_threads/core/sync/event_impl.d new file mode 100644 index 00000000000..ffeaf590416 --- /dev/null +++ b/druntime/config/posix_threads/core/sync/event_impl.d @@ -0,0 +1,115 @@ +module core.sync.event_impl; + +import core.internal.abort : abort; +import core.sys.posix.pthread; +import core.sys.posix.sys.types; +import core.sys.posix.time; +import core.time; + +package: + +nothrow @nogc: + +struct EventHandler +{ + pthread_mutex_t m_mutex; + pthread_cond_t m_cond; + bool initalized; + bool m_state; + bool m_manualReset; +} + +EventHandler create(bool manualReset, bool initialState) +{ + EventHandler h; + + pthread_mutex_init(cast(pthread_mutex_t*) &(h.m_mutex), null) == 0 || + abort("Error: pthread_mutex_init failed."); + + static if ( is( typeof( pthread_condattr_setclock ) ) ) + { + pthread_condattr_t attr = void; + pthread_condattr_init(&attr) == 0 || + abort("Error: pthread_condattr_init failed."); + pthread_condattr_setclock(&attr, CLOCK_MONOTONIC) == 0 || + abort("Error: pthread_condattr_setclock failed."); + pthread_cond_init(&(h.m_cond), &attr) == 0 || + abort("Error: pthread_cond_init failed."); + pthread_condattr_destroy(&attr) == 0 || + abort("Error: pthread_condattr_destroy failed."); + } + else + { + pthread_cond_init(&(h.m_cond), null) == 0 || + abort("Error: pthread_cond_init failed."); + } + + h.m_state = initialState; + h.m_manualReset = manualReset; + h.initalized = true; + + return h; +} + +void destroy(ref EventHandler h) +{ + pthread_mutex_destroy(&(h.m_mutex)) == 0 || + abort("Error: pthread_mutex_destroy failed."); + + pthread_cond_destroy(&(h.m_cond)) == 0 || + abort("Error: pthread_cond_destroy failed."); + + h.initalized = false; +} + +void set(ref EventHandler h) +{ + h.mutexLock; + h.m_state = true; + pthread_cond_broadcast(&(h.m_cond)); + h.mutexUnlock; +} + +void reset(ref EventHandler h) +{ + h.mutexLock; + h.m_state = false; + h.mutexUnlock; +} + +bool wait(ref EventHandler h) +{ + return h.wait(Duration.max); +} + +bool wait(ref EventHandler h, Duration tmout) +{ + h.mutexLock; + + int result = 0; + if (!h.m_state) + { + if (tmout == Duration.max) + { + result = pthread_cond_wait(&(h.m_cond), &(h.m_mutex)); + } + else + { + import core.sync.config; + + timespec t = void; + mktspec(t, tmout); + + result = pthread_cond_timedwait(&(h.m_cond), &(h.m_mutex), &t); + } + } + if (result == 0 && !h.m_manualReset) + h.m_state = false; + + h.mutexUnlock; + + return result == 0; +} + +private void mutexLock(ref EventHandler h) { pthread_mutex_lock(&(h.m_mutex)); } +private void mutexUnlock(ref EventHandler h) { pthread_mutex_unlock(&(h.m_mutex)); } diff --git a/druntime/config/windows/core/sync/event_impl.d b/druntime/config/windows/core/sync/event_impl.d new file mode 100644 index 00000000000..d243d3c6c84 --- /dev/null +++ b/druntime/config/windows/core/sync/event_impl.d @@ -0,0 +1,60 @@ +module core.sync.event_impl; + +import core.internal.abort : abort; +import core.sys.windows.basetsd /+: HANDLE +/; +import core.sys.windows.winerror /+: WAIT_TIMEOUT +/; +import core.sys.windows.winbase /+: CreateEvent, CloseHandle, SetEvent, ResetEvent, + WaitForSingleObject, INFINITE, WAIT_OBJECT_0+/; +import core.time; + +package: + +nothrow @nogc: + +alias EventHandler = HANDLE; + +bool initalized(in EventHandler h) { return h !is null; } + +EventHandler create(bool manualReset, bool initialState) +{ + HANDLE m_event = CreateEvent(null, manualReset, initialState, null); + m_event || abort("Error: CreateEvent failed."); + + return m_event; +} + +void destroy(ref EventHandler m_event) +{ + CloseHandle(m_event); + m_event = null; +} + +void set(EventHandler m_event) +{ + SetEvent(m_event); +} + +void reset(EventHandler m_event) +{ + ResetEvent(m_event); +} + +bool wait(EventHandler m_event) +{ + return m_event && WaitForSingleObject(m_event, INFINITE) == WAIT_OBJECT_0; +} + +bool wait(EventHandler m_event, Duration tmout) +{ + auto maxWaitMillis = dur!("msecs")(uint.max - 1); + + while (tmout > maxWaitMillis) + { + auto res = WaitForSingleObject(m_event, uint.max - 1); + if (res != WAIT_TIMEOUT) + return res == WAIT_OBJECT_0; + tmout -= maxWaitMillis; + } + auto ms = cast(uint)(tmout.total!"msecs"); + return WaitForSingleObject(m_event, ms) == WAIT_OBJECT_0; +} diff --git a/druntime/mak/COPY b/druntime/mak/COPY index efcb881a708..920b4f49710 100644 --- a/druntime/mak/COPY +++ b/druntime/mak/COPY @@ -129,6 +129,7 @@ COPY=\ $(IMPDIR)\core\sync\barrier.d \ $(IMPDIR)\core\sync\condition.d \ $(IMPDIR)\core\sync\config.d \ + $(IMPDIR)\core\sync\event.d \ $(IMPDIR)\core\sync\exception.d \ $(IMPDIR)\core\sync\mutex.d \ $(IMPDIR)\core\sync\rwmutex.d \ diff --git a/druntime/mak/SRCS b/druntime/mak/SRCS index cfc3ccade4c..1182c69d83b 100644 --- a/druntime/mak/SRCS +++ b/druntime/mak/SRCS @@ -127,8 +127,8 @@ SRCS=\ src\core\sync\barrier.d \ src\core\sync\condition.d \ src\core\sync\config.d \ - src\core\sync\event_tests.d \ src\core\sync\exception.d \ + src\core\sync\event.d \ src\core\sync\mutex.d \ src\core\sync\rwmutex.d \ src\core\sync\semaphore.d \ diff --git a/druntime/mak/TAGGED_COPY b/druntime/mak/TAGGED_COPY index 0581bfa97e1..b95581dd2be 100644 --- a/druntime/mak/TAGGED_COPY +++ b/druntime/mak/TAGGED_COPY @@ -1 +1 @@ -core\sync\event.d +core\sync\event_impl.d diff --git a/druntime/config/windows/core/sync/event.d b/druntime/src/core/sync/event.d similarity index 66% rename from druntime/config/windows/core/sync/event.d rename to druntime/src/core/sync/event.d index 57fc81a6c0f..c27962d7982 100644 --- a/druntime/config/windows/core/sync/event.d +++ b/druntime/src/core/sync/event.d @@ -11,13 +11,8 @@ */ module core.sync.event; -import core.sys.windows.basetsd /+: HANDLE +/; -import core.sys.windows.winerror /+: WAIT_TIMEOUT +/; -import core.sys.windows.winbase /+: CreateEvent, CloseHandle, SetEvent, ResetEvent, - WaitForSingleObject, INFINITE, WAIT_OBJECT_0+/; - import core.time; -import core.internal.abort : abort; +import core.sync.event_impl; /** * represents an event. Clients of an event are suspended while waiting @@ -58,6 +53,9 @@ struct ProcessFile struct Event { nothrow @nogc: + + private core.sync.event_impl.EventHandler hdl; + /** * Creates an event object. * @@ -79,10 +77,10 @@ nothrow @nogc: */ void initialize(bool manualReset, bool initialState) { - if (m_event) + if(hdl.initalized) return; - m_event = CreateEvent(null, manualReset, initialState, null); - m_event || abort("Error: CreateEvent failed."); + + hdl = core.sync.event_impl.create(manualReset, initialState); } // copying not allowed, can produce resource leaks @@ -100,9 +98,8 @@ nothrow @nogc: */ void terminate() { - if (m_event) - CloseHandle(m_event); - m_event = null; + if (hdl.initalized) + core.sync.event_impl.destroy(hdl); } deprecated ("Use setIfInitialized() instead") void set() @@ -113,15 +110,15 @@ nothrow @nogc: /// Set the event to "signaled", so that waiting clients are resumed void setIfInitialized() { - if (m_event) - SetEvent(m_event); + if (hdl.initalized) + core.sync.event_impl.set(hdl); } /// Reset the event manually void reset() { - if (m_event) - ResetEvent(m_event); + if (hdl.initalized) + core.sync.event_impl.reset(hdl); } /** @@ -132,7 +129,7 @@ nothrow @nogc: */ bool wait() { - return m_event && WaitForSingleObject(m_event, INFINITE) == WAIT_OBJECT_0; + return core.sync.event_impl.wait(hdl); } /** @@ -146,21 +143,57 @@ nothrow @nogc: */ bool wait(Duration tmout) { - if (!m_event) + if (!hdl.initalized) return false; - auto maxWaitMillis = dur!("msecs")(uint.max - 1); - - while (tmout > maxWaitMillis) - { - auto res = WaitForSingleObject(m_event, uint.max - 1); - if (res != WAIT_TIMEOUT) - return res == WAIT_OBJECT_0; - tmout -= maxWaitMillis; - } - auto ms = cast(uint)(tmout.total!"msecs"); - return WaitForSingleObject(m_event, ms) == WAIT_OBJECT_0; + return core.sync.event_impl.wait(hdl, tmout); } +} + +// Test single-thread (non-shared) use. +@nogc nothrow unittest +{ + // auto-reset, initial state false + Event ev1 = Event(false, false); + assert(!ev1.wait(1.dur!"msecs")); + ev1.setIfInitialized(); + assert(ev1.wait()); + assert(!ev1.wait(1.dur!"msecs")); + + // manual-reset, initial state true + Event ev2 = Event(true, true); + assert(ev2.wait()); + assert(ev2.wait()); + ev2.reset(); + assert(!ev2.wait(1.dur!"msecs")); +} + +unittest +{ + import core.thread, core.atomic; + + scope event = new Event(true, false); + int numThreads = 10; + shared int numRunning = 0; + + void testFn() + { + event.wait(8.dur!"seconds"); // timeout below limit for druntime test_runner + numRunning.atomicOp!"+="(1); + } + + auto group = new ThreadGroup; + + for (int i = 0; i < numThreads; ++i) + group.create(&testFn); + + auto start = MonoTime.currTime; + assert(numRunning == 0); + + event.setIfInitialized(); + group.joinAll(); + + assert(numRunning == numThreads); - private HANDLE m_event; + assert(MonoTime.currTime - start < 5.dur!"seconds"); } diff --git a/druntime/src/core/sync/event_tests.d b/druntime/src/core/sync/event_tests.d deleted file mode 100644 index 1ac2e90d973..00000000000 --- a/druntime/src/core/sync/event_tests.d +++ /dev/null @@ -1,52 +0,0 @@ -module core.sync.event_tests; - -import core.sync.event : Event; -import core.time; - -// Test single-thread (non-shared) use. -@nogc nothrow unittest -{ - // auto-reset, initial state false - Event ev1 = Event(false, false); - assert(!ev1.wait(1.dur!"msecs")); - ev1.setIfInitialized(); - assert(ev1.wait()); - assert(!ev1.wait(1.dur!"msecs")); - - // manual-reset, initial state true - Event ev2 = Event(true, true); - assert(ev2.wait()); - assert(ev2.wait()); - ev2.reset(); - assert(!ev2.wait(1.dur!"msecs")); -} - -unittest -{ - import core.thread, core.atomic; - - scope event = new Event(true, false); - int numThreads = 10; - shared int numRunning = 0; - - void testFn() - { - event.wait(8.dur!"seconds"); // timeout below limit for druntime test_runner - numRunning.atomicOp!"+="(1); - } - - auto group = new ThreadGroup; - - for (int i = 0; i < numThreads; ++i) - group.create(&testFn); - - auto start = MonoTime.currTime; - assert(numRunning == 0); - - event.setIfInitialized(); - group.joinAll(); - - assert(numRunning == numThreads); - - assert(MonoTime.currTime - start < 5.dur!"seconds"); -} From d5b3ef28795479dbf626e9212dcd2aa9847bf63b Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Fri, 2 Feb 2024 00:04:20 +0300 Subject: [PATCH 13/29] Arch tag isn't make sense for official targets --- druntime/Makefile | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/druntime/Makefile b/druntime/Makefile index b901cec693b..9c44d115566 100644 --- a/druntime/Makefile +++ b/druntime/Makefile @@ -141,17 +141,11 @@ TAGGED_COPY_LIST_FILE:=mak/TAGGED_COPY TAGGED_SRCS_FILE:=$(ROOT)/GEN_SRCS TAGGED_COPY_FILE:=$(ROOT)/GEN_COPY -ifeq (64,$(MODEL)) - ARCH_TAG:=x86_64 -else - ARCH_TAG:=x86 -endif - ifeq (windows,$(OS)) # Tags order doesn't matter - TAGS:=$(ARCH_TAG),windows + TAGS:=windows else - TAGS:=$(ARCH_TAG),$(OS),posix_threads + TAGS:=$(OS),posix_threads endif TGEN_CMD:=./parse_tagged_hier.sh $(TAGGED_SRCS_FILE) $(TAGGED_COPY_LIST_FILE) $(TAGGED_COPY_FILE) $(IMPDIR) $(TAGS) config > /dev/null From ac7f2423436e88f5cfb2a564f9f6bd8d5080a641 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Fri, 2 Feb 2024 20:27:55 +0300 Subject: [PATCH 14/29] ldc2.conf: target-specific lines moved out to the separate file --- ldc/common.conf.in | 7 +++++++ ldc/ldc2.conf.in | 8 +------- ldc/ldc2_install.conf.in | 8 +------- ldc/ldc2_phobos.conf.in | 8 +------- ldc/runtime/CMakeLists.txt | 6 ++++++ 5 files changed, 16 insertions(+), 21 deletions(-) create mode 100644 ldc/common.conf.in diff --git a/ldc/common.conf.in b/ldc/common.conf.in new file mode 100644 index 00000000000..a20db569d6e --- /dev/null +++ b/ldc/common.conf.in @@ -0,0 +1,7 @@ +"^wasm(32|64)-": +{ + switches = [ + "-defaultlib=",@WASM_DEFAULT_LDC_SWITCHES@ + ]; + lib-dirs = []; +}; diff --git a/ldc/ldc2.conf.in b/ldc/ldc2.conf.in index 1ec4ce854c4..c5567e603c7 100644 --- a/ldc/ldc2.conf.in +++ b/ldc/ldc2.conf.in @@ -34,10 +34,4 @@ default: rpath = "@SHARED_LIBS_RPATH@"; }; -"^wasm(32|64)-": -{ - switches = [ - "-defaultlib=",@WASM_DEFAULT_LDC_SWITCHES@ - ]; - lib-dirs = []; -}; +@COMMON_CONF_LINES@ diff --git a/ldc/ldc2_install.conf.in b/ldc/ldc2_install.conf.in index 7536f8f0d4f..8e9eb1b8e16 100644 --- a/ldc/ldc2_install.conf.in +++ b/ldc/ldc2_install.conf.in @@ -32,10 +32,4 @@ default: rpath = "@SHARED_LIBS_INSTALL_RPATH@"; }; -"^wasm(32|64)-": -{ - switches = [ - "-defaultlib=",@WASM_DEFAULT_LDC_SWITCHES@ - ]; - lib-dirs = []; -}; +@COMMON_CONF_LINES@ diff --git a/ldc/ldc2_phobos.conf.in b/ldc/ldc2_phobos.conf.in index 9bc5b1aa484..b93a741f394 100644 --- a/ldc/ldc2_phobos.conf.in +++ b/ldc/ldc2_phobos.conf.in @@ -35,10 +35,4 @@ default: rpath = "@SHARED_LIBS_RPATH@"; }; -"^wasm(32|64)-": -{ - switches = [ - "-defaultlib=",@WASM_DEFAULT_LDC_SWITCHES@ - ]; - lib-dirs = []; -}; +@COMMON_CONF_LINES@ diff --git a/ldc/runtime/CMakeLists.txt b/ldc/runtime/CMakeLists.txt index c432a2ff293..166ba6b0958 100644 --- a/ldc/runtime/CMakeLists.txt +++ b/ldc/runtime/CMakeLists.txt @@ -331,6 +331,12 @@ if(LDC_EXE) else() set(CONFIG_NAME ${LDC_EXE}) endif() + + # Adding a duplicating part of config file + set(common_path ${PROJECT_BINARY_DIR}/common.conf) + configure_file(${PROJECT_PARENT_DIR}/common.conf.in ${common_path} @ONLY) + file(READ ${common_path} COMMON_CONF_LINES) + set(conf_path ${PROJECT_BINARY_DIR}/../bin/${LDC_EXE}.conf) set(install_conf_path ${PROJECT_BINARY_DIR}/../bin/${LDC_EXE}_install.conf) configure_file(${PROJECT_PARENT_DIR}/${CONFIG_NAME}.conf.in ${conf_path} @ONLY) From b48118203c6fe68f3b2d876e88c159eb8b805c52 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Fri, 2 Feb 2024 21:19:20 +0300 Subject: [PATCH 15/29] DRUNTIME_TARGET_NAME contains target name for druntime import/ --- ldc/runtime/CMakeLists.txt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/ldc/runtime/CMakeLists.txt b/ldc/runtime/CMakeLists.txt index 166ba6b0958..ee5dd4184d3 100644 --- a/ldc/runtime/CMakeLists.txt +++ b/ldc/runtime/CMakeLists.txt @@ -187,25 +187,33 @@ list(REMOVE_ITEM DRUNTIME_D ${DRUNTIME_D_WINDOWS} ) if("${TARGET_SYSTEM}" MATCHES "Windows") + set(DRUNTIME_TARGET_NAME "windows") list(APPEND TAGS "windows") list(APPEND DRUNTIME_D ${DRUNTIME_D_WINDOWS}) elseif("${TARGET_SYSTEM}" MATCHES "UNIX") list(APPEND TAGS "posix_threads") list(APPEND DRUNTIME_D ${DRUNTIME_D_POSIX}) if("${TARGET_SYSTEM}" MATCHES "APPLE") + set(DRUNTIME_TARGET_NAME "osx") list(APPEND DRUNTIME_D ${DRUNTIME_D_DARWIN}) elseif("${TARGET_SYSTEM}" MATCHES "DragonFly") + set(DRUNTIME_TARGET_NAME "dragonfly") list(APPEND DRUNTIME_D ${DRUNTIME_D_DRAGONFLYBSD}) elseif("${TARGET_SYSTEM}" MATCHES "FreeBSD") + set(DRUNTIME_TARGET_NAME "freebsd") list(APPEND DRUNTIME_D ${DRUNTIME_D_FREEBSD}) elseif("${TARGET_SYSTEM}" MATCHES "Linux") + set(DRUNTIME_TARGET_NAME "linux") list(APPEND DRUNTIME_D ${DRUNTIME_D_LINUX}) list(APPEND DRUNTIME_D ${DRUNTIME_D_BIONIC}) elseif("${TARGET_SYSTEM}" MATCHES "NetBSD") + set(DRUNTIME_TARGET_NAME "netbsd") list(APPEND DRUNTIME_D ${DRUNTIME_D_NETBSD}) elseif("${TARGET_SYSTEM}" MATCHES "OpenBSD") + set(DRUNTIME_TARGET_NAME "openbsd") list(APPEND DRUNTIME_D ${DRUNTIME_D_OPENBSD}) elseif("${TARGET_SYSTEM}" MATCHES "SunOS") + set(DRUNTIME_TARGET_NAME "sunos") list(APPEND DRUNTIME_D ${DRUNTIME_D_SOLARIS}) endif() endif() @@ -923,8 +931,11 @@ if(PHOBOS2_DIR) install(DIRECTORY ${PHOBOS2_DIR}/etc DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN "*.d") endif() install(FILES ${GCCBUILTINS} DESTINATION ${INCLUDE_INSTALL_DIR}/ldc) -install(DIRECTORY ${LDC_BUILD_IMPORT_DIR}/tagged_imports/ DESTINATION ${INCLUDE_INSTALL_DIR}) - +if(DRUNTIME_TARGET_NAME) + install(DIRECTORY ${LDC_BUILD_IMPORT_DIR}/tagged_imports/ DESTINATION ${INCLUDE_INSTALL_DIR}/${DRUNTIME_TARGET_NAME}) +else() + install(DIRECTORY ${LDC_BUILD_IMPORT_DIR}/tagged_imports/ DESTINATION ${INCLUDE_INSTALL_DIR}) +endif() # # Test targets. From 86dbd77813ba0f038f1e9966f82d945bc3434372 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Fri, 2 Feb 2024 21:22:22 +0300 Subject: [PATCH 16/29] DRUNTIME_TARGET_NAME: description added --- ldc/runtime/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ldc/runtime/CMakeLists.txt b/ldc/runtime/CMakeLists.txt index ee5dd4184d3..157e15fac9b 100644 --- a/ldc/runtime/CMakeLists.txt +++ b/ldc/runtime/CMakeLists.txt @@ -186,6 +186,8 @@ list(REMOVE_ITEM DRUNTIME_D ${DRUNTIME_D_OPENBSD} ${DRUNTIME_D_POSIX} ${DRUNTIME_D_SOLARIS} ${DRUNTIME_D_WINDOWS} ) + +# DRUNTIME_TARGET_NAME contains official target name which cross-linking ability is provided by default if("${TARGET_SYSTEM}" MATCHES "Windows") set(DRUNTIME_TARGET_NAME "windows") list(APPEND TAGS "windows") From 61e5e4faaa72083ec138f6c2614edb7c331c1079 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Fri, 2 Feb 2024 22:10:12 +0300 Subject: [PATCH 17/29] platforms dir changed --- ldc/runtime/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ldc/runtime/CMakeLists.txt b/ldc/runtime/CMakeLists.txt index 157e15fac9b..2f3cc823296 100644 --- a/ldc/runtime/CMakeLists.txt +++ b/ldc/runtime/CMakeLists.txt @@ -934,7 +934,7 @@ if(PHOBOS2_DIR) endif() install(FILES ${GCCBUILTINS} DESTINATION ${INCLUDE_INSTALL_DIR}/ldc) if(DRUNTIME_TARGET_NAME) - install(DIRECTORY ${LDC_BUILD_IMPORT_DIR}/tagged_imports/ DESTINATION ${INCLUDE_INSTALL_DIR}/${DRUNTIME_TARGET_NAME}) + install(DIRECTORY ${LDC_BUILD_IMPORT_DIR}/tagged_imports/ DESTINATION ${INCLUDE_INSTALL_DIR}/platforms/${DRUNTIME_TARGET_NAME}) else() install(DIRECTORY ${LDC_BUILD_IMPORT_DIR}/tagged_imports/ DESTINATION ${INCLUDE_INSTALL_DIR}) endif() From 3cf394c650e4a2d3db9ef9089c24ef5a44a69cce Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Fri, 2 Feb 2024 23:17:53 +0300 Subject: [PATCH 18/29] CONF_IMPORTS creation for ldc2.conf and for ldc2_install.conf --- ldc/common.conf.in | 7 +++++++ ldc/ldc2.conf.in | 4 +--- ldc/ldc2_install.conf.in | 4 ++-- ldc/ldc2_phobos.conf.in | 5 +---- ldc/runtime/CMakeLists.txt | 17 +++++++++++++++++ 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/ldc/common.conf.in b/ldc/common.conf.in index a20db569d6e..a9688b40615 100644 --- a/ldc/common.conf.in +++ b/ldc/common.conf.in @@ -5,3 +5,10 @@ ]; lib-dirs = []; }; + +".+-linux-.+": +{ + post-switches = [ + @CONF_IMPORTS@ + ]; +}; \ No newline at end of file diff --git a/ldc/ldc2.conf.in b/ldc/ldc2.conf.in index c5567e603c7..bda5fd7fee0 100644 --- a/ldc/ldc2.conf.in +++ b/ldc/ldc2.conf.in @@ -22,9 +22,7 @@ default: ]; // default switches appended after all explicit command-line switches post-switches = [ - "-I@RUNTIME_DIR@/src", - "-I@LDC_BUILD_IMPORT_DIR@", - "-I@JITRT_DIR@/d", + @CONF_IMPORTS@ ]; // default directories to be searched for libraries when linking lib-dirs = [ diff --git a/ldc/ldc2_install.conf.in b/ldc/ldc2_install.conf.in index 8e9eb1b8e16..78508996591 100644 --- a/ldc/ldc2_install.conf.in +++ b/ldc/ldc2_install.conf.in @@ -22,7 +22,7 @@ default: ]; // default switches appended after all explicit command-line switches post-switches = [ - "-I@INCLUDE_INSTALL_DIR@", + @CONF_IMPORTS@ ]; // default directories to be searched for libraries when linking lib-dirs = [ @@ -32,4 +32,4 @@ default: rpath = "@SHARED_LIBS_INSTALL_RPATH@"; }; -@COMMON_CONF_LINES@ +@COMMON_INSTALL_CONF_LINES@ diff --git a/ldc/ldc2_phobos.conf.in b/ldc/ldc2_phobos.conf.in index b93a741f394..f808c26baba 100644 --- a/ldc/ldc2_phobos.conf.in +++ b/ldc/ldc2_phobos.conf.in @@ -22,10 +22,7 @@ default: ]; // default switches appended after all explicit command-line switches post-switches = [ - "-I@RUNTIME_DIR@/src", - "-I@LDC_BUILD_IMPORT_DIR@", - "-I@JITRT_DIR@/d", - "-I@PHOBOS2_DIR@", + @CONF_IMPORTS@ ]; // default directories to be searched for libraries when linking lib-dirs = [ diff --git a/ldc/runtime/CMakeLists.txt b/ldc/runtime/CMakeLists.txt index 2f3cc823296..b6d5d093233 100644 --- a/ldc/runtime/CMakeLists.txt +++ b/ldc/runtime/CMakeLists.txt @@ -336,12 +336,24 @@ set(WASM_DEFAULT_LDC_SWITCHES "${WASM_DEFAULT_LDC_SWITCHES}\n \"-L--expor # Only generate the config files if this CMake project is embedded in the LDC CMake project. if(LDC_EXE) + # imports for building druntime itself + set(CONF_IMPORTS + -I${RUNTIME_DIR}/src + -I${LDC_BUILD_IMPORT_DIR} + -I${JITRT_DIR}/d + ) + if(PHOBOS2_DIR) set(CONFIG_NAME ${LDC_EXE}_phobos) + list(APPEND CONF_IMPORTS "-I${PHOBOS2_DIR}") else() set(CONFIG_NAME ${LDC_EXE}) endif() + list(TRANSFORM CONF_IMPORTS PREPEND "\"") + list(TRANSFORM CONF_IMPORTS APPEND "\"") + list(JOIN CONF_IMPORTS ", " CONF_IMPORTS) + # Adding a duplicating part of config file set(common_path ${PROJECT_BINARY_DIR}/common.conf) configure_file(${PROJECT_PARENT_DIR}/common.conf.in ${common_path} @ONLY) @@ -350,6 +362,11 @@ if(LDC_EXE) set(conf_path ${PROJECT_BINARY_DIR}/../bin/${LDC_EXE}.conf) set(install_conf_path ${PROJECT_BINARY_DIR}/../bin/${LDC_EXE}_install.conf) configure_file(${PROJECT_PARENT_DIR}/${CONFIG_NAME}.conf.in ${conf_path} @ONLY) + + # import for typical compiler usage + set(CONF_IMPORTS "\"-I${INCLUDE_INSTALL_DIR}\"") + configure_file(${PROJECT_PARENT_DIR}/common.conf.in ${common_path} @ONLY) + file(READ ${common_path} COMMON_INSTALL_CONF_LINES) configure_file(${PROJECT_PARENT_DIR}/${LDC_EXE}_install.conf.in ${install_conf_path} @ONLY) # macOS has fat libraries; otherwise, append a separate config file section for the From da9cad58732fafd23f39f538dd29389ab6b937a9 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Fri, 2 Feb 2024 23:29:32 +0300 Subject: [PATCH 19/29] @CONF_IMPORTS@/platforms/linux added --- ldc/common.conf.in | 2 +- ldc/ldc2.conf.in | 2 +- ldc/ldc2_install.conf.in | 2 +- ldc/ldc2_phobos.conf.in | 2 +- ldc/runtime/CMakeLists.txt | 6 ++---- 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/ldc/common.conf.in b/ldc/common.conf.in index a9688b40615..03e193003c2 100644 --- a/ldc/common.conf.in +++ b/ldc/common.conf.in @@ -9,6 +9,6 @@ ".+-linux-.+": { post-switches = [ - @CONF_IMPORTS@ + "@CONF_IMPORTS@", "@CONF_IMPORTS@/platforms/linux" ]; }; \ No newline at end of file diff --git a/ldc/ldc2.conf.in b/ldc/ldc2.conf.in index bda5fd7fee0..4fe63cb42f3 100644 --- a/ldc/ldc2.conf.in +++ b/ldc/ldc2.conf.in @@ -22,7 +22,7 @@ default: ]; // default switches appended after all explicit command-line switches post-switches = [ - @CONF_IMPORTS@ + "@CONF_IMPORTS@" ]; // default directories to be searched for libraries when linking lib-dirs = [ diff --git a/ldc/ldc2_install.conf.in b/ldc/ldc2_install.conf.in index 78508996591..feb7e59a411 100644 --- a/ldc/ldc2_install.conf.in +++ b/ldc/ldc2_install.conf.in @@ -22,7 +22,7 @@ default: ]; // default switches appended after all explicit command-line switches post-switches = [ - @CONF_IMPORTS@ + "@CONF_IMPORTS@" ]; // default directories to be searched for libraries when linking lib-dirs = [ diff --git a/ldc/ldc2_phobos.conf.in b/ldc/ldc2_phobos.conf.in index f808c26baba..213e3695617 100644 --- a/ldc/ldc2_phobos.conf.in +++ b/ldc/ldc2_phobos.conf.in @@ -22,7 +22,7 @@ default: ]; // default switches appended after all explicit command-line switches post-switches = [ - @CONF_IMPORTS@ + "@CONF_IMPORTS@" ]; // default directories to be searched for libraries when linking lib-dirs = [ diff --git a/ldc/runtime/CMakeLists.txt b/ldc/runtime/CMakeLists.txt index b6d5d093233..79356b2cac7 100644 --- a/ldc/runtime/CMakeLists.txt +++ b/ldc/runtime/CMakeLists.txt @@ -350,9 +350,7 @@ if(LDC_EXE) set(CONFIG_NAME ${LDC_EXE}) endif() - list(TRANSFORM CONF_IMPORTS PREPEND "\"") - list(TRANSFORM CONF_IMPORTS APPEND "\"") - list(JOIN CONF_IMPORTS ", " CONF_IMPORTS) + list(JOIN CONF_IMPORTS "\", \"" CONF_IMPORTS) # Adding a duplicating part of config file set(common_path ${PROJECT_BINARY_DIR}/common.conf) @@ -364,7 +362,7 @@ if(LDC_EXE) configure_file(${PROJECT_PARENT_DIR}/${CONFIG_NAME}.conf.in ${conf_path} @ONLY) # import for typical compiler usage - set(CONF_IMPORTS "\"-I${INCLUDE_INSTALL_DIR}\"") + set(CONF_IMPORTS "-I${INCLUDE_INSTALL_DIR}") configure_file(${PROJECT_PARENT_DIR}/common.conf.in ${common_path} @ONLY) file(READ ${common_path} COMMON_INSTALL_CONF_LINES) configure_file(${PROJECT_PARENT_DIR}/${LDC_EXE}_install.conf.in ${install_conf_path} @ONLY) From ff2c0d5683b45cdeff357ae2942ea10b89ddab94 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Sat, 3 Feb 2024 01:54:01 +0300 Subject: [PATCH 20/29] druntime unittest build fix --- ldc/runtime/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ldc/runtime/CMakeLists.txt b/ldc/runtime/CMakeLists.txt index 79356b2cac7..17c1babc71d 100644 --- a/ldc/runtime/CMakeLists.txt +++ b/ldc/runtime/CMakeLists.txt @@ -600,7 +600,7 @@ macro(compile_druntime d_flags lib_suffix path_suffix emit_bc all_at_once single endif() dc("${DRUNTIME_D}" "${RUNTIME_DIR}" - "-conf=;${d_flags};${DRUNTIME_EXTRA_FLAGS};-I${RUNTIME_DIR}/src" + "-conf=;${d_flags};${DRUNTIME_EXTRA_FLAGS};-I${RUNTIME_DIR}/src;-I${LDC_BUILD_IMPORT_DIR}/tagged_imports" "${PROJECT_BINARY_DIR}/objects${target_suffix}" "${emit_bc}" "${all_at_once}" From f1e6972f4db57097662987ed3886e0cfdde1ca66 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Sat, 3 Feb 2024 02:07:28 +0300 Subject: [PATCH 21/29] All other official platforms added to ldc2.conf --- ldc/common.conf.in | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ldc/common.conf.in b/ldc/common.conf.in index 03e193003c2..13a052c7858 100644 --- a/ldc/common.conf.in +++ b/ldc/common.conf.in @@ -6,9 +6,11 @@ lib-dirs = []; }; -".+-linux-.+": -{ - post-switches = [ - "@CONF_IMPORTS@", "@CONF_IMPORTS@/platforms/linux" - ]; -}; \ No newline at end of file +".+-windows-.+": { post-switches = [ "@CONF_IMPORTS@", "@CONF_IMPORTS@/platforms/windows" ]; }; +".+-osx-.+": { post-switches = [ "@CONF_IMPORTS@", "@CONF_IMPORTS@/platforms/osx" ]; }; +".+-dragonfly-.+": { post-switches = [ "@CONF_IMPORTS@", "@CONF_IMPORTS@/platforms/dragonfly" ]; }; +".+-freebsd-.+": { post-switches = [ "@CONF_IMPORTS@", "@CONF_IMPORTS@/platforms/freebsd" ]; }; +".+-linux-.+": { post-switches = [ "@CONF_IMPORTS@", "@CONF_IMPORTS@/platforms/linux" ]; }; +".+-netbsd-.+": { post-switches = [ "@CONF_IMPORTS@", "@CONF_IMPORTS@/platforms/netbsd" ]; }; +".+-openbsd-.+": { post-switches = [ "@CONF_IMPORTS@", "@CONF_IMPORTS@/platforms/openbsd" ]; }; +".+-sunos-.+": { post-switches = [ "@CONF_IMPORTS@", "@CONF_IMPORTS@/platforms/sunos" ]; }; From 4c32a76a4d74be137efafdb5678bfc146d1c66b6 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Sat, 3 Feb 2024 04:13:23 +0300 Subject: [PATCH 22/29] common.conf.in lines rearranged for better perception --- ldc/common.conf.in | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/ldc/common.conf.in b/ldc/common.conf.in index 13a052c7858..a8b09738589 100644 --- a/ldc/common.conf.in +++ b/ldc/common.conf.in @@ -1,10 +1,4 @@ -"^wasm(32|64)-": -{ - switches = [ - "-defaultlib=",@WASM_DEFAULT_LDC_SWITCHES@ - ]; - lib-dirs = []; -}; +// Imports for officially supplied druntime binaries: ".+-windows-.+": { post-switches = [ "@CONF_IMPORTS@", "@CONF_IMPORTS@/platforms/windows" ]; }; ".+-osx-.+": { post-switches = [ "@CONF_IMPORTS@", "@CONF_IMPORTS@/platforms/osx" ]; }; @@ -14,3 +8,11 @@ ".+-netbsd-.+": { post-switches = [ "@CONF_IMPORTS@", "@CONF_IMPORTS@/platforms/netbsd" ]; }; ".+-openbsd-.+": { post-switches = [ "@CONF_IMPORTS@", "@CONF_IMPORTS@/platforms/openbsd" ]; }; ".+-sunos-.+": { post-switches = [ "@CONF_IMPORTS@", "@CONF_IMPORTS@/platforms/sunos" ]; }; + +"^wasm(32|64)-": +{ + switches = [ + "-defaultlib=",@WASM_DEFAULT_LDC_SWITCHES@ + ]; + lib-dirs = []; +}; \ No newline at end of file From fb0db35cf5daf65c6e8f548f1b7ebe028619f2a9 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Sat, 3 Feb 2024 20:17:26 +0300 Subject: [PATCH 23/29] set TAGS moved --- ldc/runtime/CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ldc/runtime/CMakeLists.txt b/ldc/runtime/CMakeLists.txt index 17c1babc71d..12df149d3f4 100644 --- a/ldc/runtime/CMakeLists.txt +++ b/ldc/runtime/CMakeLists.txt @@ -167,8 +167,6 @@ list(REMOVE_ITEM DRUNTIME_D ${RUNTIME_DIR}/src/rt/sections_solaris.d ${RUNTIME_DIR}/src/rt/sections_win32.d ) -# create set of tags -set(TAGS "") # only include core/sys/ modules matching the platform file(GLOB_RECURSE DRUNTIME_D_BIONIC ${RUNTIME_DIR}/src/core/sys/bionic/*.d) file(GLOB_RECURSE DRUNTIME_D_DARWIN ${RUNTIME_DIR}/src/core/sys/darwin/*.d) @@ -187,6 +185,9 @@ list(REMOVE_ITEM DRUNTIME_D ${DRUNTIME_D_WINDOWS} ) +# create set of tags +set(TAGS "") + # DRUNTIME_TARGET_NAME contains official target name which cross-linking ability is provided by default if("${TARGET_SYSTEM}" MATCHES "Windows") set(DRUNTIME_TARGET_NAME "windows") From dd7fed1e0a79903fe3b5164705fbab561a75702c Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Sat, 3 Feb 2024 21:51:36 +0300 Subject: [PATCH 24/29] Tagged lists generator moved to dedicated function "produce_tagged_hier" --- ldc/runtime/CMakeLists.txt | 76 ++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 32 deletions(-) diff --git a/ldc/runtime/CMakeLists.txt b/ldc/runtime/CMakeLists.txt index 12df149d3f4..3360fdce9cb 100644 --- a/ldc/runtime/CMakeLists.txt +++ b/ldc/runtime/CMakeLists.txt @@ -185,7 +185,7 @@ list(REMOVE_ITEM DRUNTIME_D ${DRUNTIME_D_WINDOWS} ) -# create set of tags +# create set of tags for current target set(TAGS "") # DRUNTIME_TARGET_NAME contains official target name which cross-linking ability is provided by default @@ -240,44 +240,56 @@ set(TAGGED_COPY_LIST_FILE "${RUNTIME_DIR}/mak/TAGGED_COPY" CACHE FILEPATH "addit set(TAGGED_SRCS_FILE "${PROJECT_BINARY_DIR}/GEN_SRCS" CACHE FILEPATH "generated list of sources choised by tags") set(TAGGED_COPY_FILE "${PROJECT_BINARY_DIR}/GEN_COPY" CACHE FILEPATH "generated list of imports choised by tags") -list(JOIN TAGS "," TAGS_STR) -execute_process( - COMMAND "${RUNTIME_DIR}/parse_tagged_hier.sh" - ${TAGGED_SRCS_FILE} - ${TAGGED_COPY_LIST_FILE} - ${TAGGED_COPY_FILE} - "/" - ${TAGS_STR} - ${RUNTIME_CFG_DIR} - ECHO_OUTPUT_VARIABLE - ECHO_ERROR_VARIABLE - COMMAND_ERROR_IS_FATAL ANY -) - -file(STRINGS ${TAGGED_SRCS_FILE} TAGGED_SRCS) -file(STRINGS ${TAGGED_COPY_FILE} TAGGED_COPY) - -list(APPEND DRUNTIME_D ${TAGGED_SRCS}) +function(produce_tagged_hier TAGS import_dst_dir) + file(REMOVE ${TAGGED_SRCS_FILE}) + file(REMOVE ${TAGGED_COPY_FILE}) -# Directory filled with auto-generated import files -set(LDC_BUILD_IMPORT_DIR "${PROJECT_BINARY_DIR}/import") + list(JOIN TAGS "," TAGS_STR) -foreach(incl_file ${TAGGED_COPY}) - cmake_path(NORMAL_PATH incl_file) - string(REPLACE ${RUNTIME_CFG_DIR} "" dst_file ${incl_file}) - - # strip first unused dirs from file path execute_process( - COMMAND "echo" ${dst_file} - COMMAND "cut" -d / -f3- - OUTPUT_VARIABLE pretty_dst_path + COMMAND "${RUNTIME_DIR}/parse_tagged_hier.sh" + ${TAGGED_SRCS_FILE} + ${TAGGED_COPY_LIST_FILE} + ${TAGGED_COPY_FILE} + "/" + ${TAGS_STR} + ${RUNTIME_CFG_DIR} + ECHO_OUTPUT_VARIABLE ECHO_ERROR_VARIABLE COMMAND_ERROR_IS_FATAL ANY ) - get_filename_component(path ${pretty_dst_path} PATH) - file(INSTALL ${incl_file} DESTINATION ${LDC_BUILD_IMPORT_DIR}/tagged_imports/${path}) -endforeach() + file(STRINGS ${TAGGED_SRCS_FILE} TAGGED_SRCS) + file(STRINGS ${TAGGED_COPY_FILE} TAGGED_COPY) + + # returning for further use + set(TAGGED_SRCS ${TAGGED_SRCS} PARENT_SCOPE) + + # copy imports to dedicated tagged imports dir + foreach(incl_file ${TAGGED_COPY}) + cmake_path(NORMAL_PATH incl_file) + string(REPLACE ${RUNTIME_CFG_DIR} "" dst_file ${incl_file}) + + # strip first unused dirs from file path + execute_process( + COMMAND "echo" ${dst_file} + COMMAND "cut" -d / -f3- + OUTPUT_VARIABLE pretty_dst_path + ECHO_ERROR_VARIABLE + COMMAND_ERROR_IS_FATAL ANY + ) + + get_filename_component(path ${pretty_dst_path} PATH) + file(INSTALL ${incl_file} DESTINATION ${import_dst_dir}/${path}) + endforeach() +endfunction() + +# Directory filled with auto-generated import files +set(LDC_BUILD_IMPORT_DIR "${PROJECT_BINARY_DIR}/import") + +cmake_language(CALL produce_tagged_hier ${TAGS} ${LDC_BUILD_IMPORT_DIR}/tagged_imports) + +list(APPEND DRUNTIME_D ${TAGGED_SRCS}) if(PHOBOS2_DIR) # Phobos D parts From 0b4ad802d34d53c8b295f4a95b2f5bc949474b77 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Sat, 3 Feb 2024 22:16:26 +0300 Subject: [PATCH 25/29] Targets matrix added, imports are generated for all of them --- ldc/runtime/CMakeLists.txt | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/ldc/runtime/CMakeLists.txt b/ldc/runtime/CMakeLists.txt index 3360fdce9cb..74c7538507c 100644 --- a/ldc/runtime/CMakeLists.txt +++ b/ldc/runtime/CMakeLists.txt @@ -185,16 +185,11 @@ list(REMOVE_ITEM DRUNTIME_D ${DRUNTIME_D_WINDOWS} ) -# create set of tags for current target -set(TAGS "") - # DRUNTIME_TARGET_NAME contains official target name which cross-linking ability is provided by default if("${TARGET_SYSTEM}" MATCHES "Windows") set(DRUNTIME_TARGET_NAME "windows") - list(APPEND TAGS "windows") list(APPEND DRUNTIME_D ${DRUNTIME_D_WINDOWS}) elseif("${TARGET_SYSTEM}" MATCHES "UNIX") - list(APPEND TAGS "posix_threads") list(APPEND DRUNTIME_D ${DRUNTIME_D_POSIX}) if("${TARGET_SYSTEM}" MATCHES "APPLE") set(DRUNTIME_TARGET_NAME "osx") @@ -284,10 +279,25 @@ function(produce_tagged_hier TAGS import_dst_dir) endforeach() endfunction() +# Official targets +set(OfficialPlatforms "windows" "osx" "linux") + +# Tags matrix for them +set(TAGS_windows "windows") +set(TAGS_osx "posix_threads") +set(TAGS_linux "posix_threads") + # Directory filled with auto-generated import files set(LDC_BUILD_IMPORT_DIR "${PROJECT_BINARY_DIR}/import") -cmake_language(CALL produce_tagged_hier ${TAGS} ${LDC_BUILD_IMPORT_DIR}/tagged_imports) +# Produce imports for all official platforms (including current) +foreach(platform ${OfficialPlatforms}) + cmake_language(CALL produce_tagged_hier ${TAGS_${platform}} ${LDC_BUILD_IMPORT_DIR}/tagged_imports/${platform}) +endforeach() + +# Produce tagged sources and import/ for current target. Overwrites previously generated +# Called only because we need obtain TAGGED_SRCS list for current platform +cmake_language(CALL produce_tagged_hier ${TAGS_${DRUNTIME_TARGET_NAME}} ${LDC_BUILD_IMPORT_DIR}/tagged_imports) list(APPEND DRUNTIME_D ${TAGGED_SRCS}) From bd4dc0497c76486470df19ee5d66a5dfbe54fcb1 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Sat, 3 Feb 2024 22:31:09 +0300 Subject: [PATCH 26/29] Appropriate copying of all official imports --- ldc/runtime/CMakeLists.txt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ldc/runtime/CMakeLists.txt b/ldc/runtime/CMakeLists.txt index 74c7538507c..6b21d15311f 100644 --- a/ldc/runtime/CMakeLists.txt +++ b/ldc/runtime/CMakeLists.txt @@ -296,8 +296,9 @@ foreach(platform ${OfficialPlatforms}) endforeach() # Produce tagged sources and import/ for current target. Overwrites previously generated -# Called only because we need obtain TAGGED_SRCS list for current platform -cmake_language(CALL produce_tagged_hier ${TAGS_${DRUNTIME_TARGET_NAME}} ${LDC_BUILD_IMPORT_DIR}/tagged_imports) +# Called again only because we need obtain TAGGED_SRCS list for the current platform +set(curr_tagged_import_dir ${LDC_BUILD_IMPORT_DIR}/tagged_imports/${DRUNTIME_TARGET_NAME}) +cmake_language(CALL produce_tagged_hier ${TAGS_${DRUNTIME_TARGET_NAME}} ${curr_tagged_import_dir}) list(APPEND DRUNTIME_D ${TAGGED_SRCS}) @@ -623,7 +624,7 @@ macro(compile_druntime d_flags lib_suffix path_suffix emit_bc all_at_once single endif() dc("${DRUNTIME_D}" "${RUNTIME_DIR}" - "-conf=;${d_flags};${DRUNTIME_EXTRA_FLAGS};-I${RUNTIME_DIR}/src;-I${LDC_BUILD_IMPORT_DIR}/tagged_imports" + "-conf=;${d_flags};${DRUNTIME_EXTRA_FLAGS};-I${RUNTIME_DIR}/src;-I${curr_tagged_import_dir}" "${PROJECT_BINARY_DIR}/objects${target_suffix}" "${emit_bc}" "${all_at_once}" @@ -972,9 +973,10 @@ if(PHOBOS2_DIR) endif() install(FILES ${GCCBUILTINS} DESTINATION ${INCLUDE_INSTALL_DIR}/ldc) if(DRUNTIME_TARGET_NAME) - install(DIRECTORY ${LDC_BUILD_IMPORT_DIR}/tagged_imports/ DESTINATION ${INCLUDE_INSTALL_DIR}/platforms/${DRUNTIME_TARGET_NAME}) + # Assumed build for an official platform - copying all imports + install(DIRECTORY ${LDC_BUILD_IMPORT_DIR}/tagged_imports/ DESTINATION ${INCLUDE_INSTALL_DIR}/platforms/) else() - install(DIRECTORY ${LDC_BUILD_IMPORT_DIR}/tagged_imports/ DESTINATION ${INCLUDE_INSTALL_DIR}) + install(DIRECTORY ${curr_tagged_import_dir} DESTINATION ${INCLUDE_INSTALL_DIR}) endif() # From fda4c0c698137a064b4cbef6255b7f90518f09db Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Sat, 3 Feb 2024 22:40:05 +0300 Subject: [PATCH 27/29] Remaining platforms added --- ldc/runtime/CMakeLists.txt | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/ldc/runtime/CMakeLists.txt b/ldc/runtime/CMakeLists.txt index 6b21d15311f..a610393dd16 100644 --- a/ldc/runtime/CMakeLists.txt +++ b/ldc/runtime/CMakeLists.txt @@ -185,7 +185,7 @@ list(REMOVE_ITEM DRUNTIME_D ${DRUNTIME_D_WINDOWS} ) -# DRUNTIME_TARGET_NAME contains official target name which cross-linking ability is provided by default +# DRUNTIME_TARGET_NAME contains official target name which binary is currently produced if("${TARGET_SYSTEM}" MATCHES "Windows") set(DRUNTIME_TARGET_NAME "windows") list(APPEND DRUNTIME_D ${DRUNTIME_D_WINDOWS}) @@ -280,12 +280,20 @@ function(produce_tagged_hier TAGS import_dst_dir) endfunction() # Official targets -set(OfficialPlatforms "windows" "osx" "linux") +set(OfficialPlatforms + "windows" "osx" "dragonfly" "freebsd" + "linux" "netbsd" "openbsd" "sunos" +) # Tags matrix for them -set(TAGS_windows "windows") -set(TAGS_osx "posix_threads") -set(TAGS_linux "posix_threads") +set(TAGS_windows "windows") +set(TAGS_osx "posix_threads") +set(TAGS_dragonfly "posix_threads") +set(TAGS_freebsd "posix_threads") +set(TAGS_linux "posix_threads") +set(TAGS_netbsd "posix_threads") +set(TAGS_openbsd "posix_threads") +set(TAGS_sunos "posix_threads") # Directory filled with auto-generated import files set(LDC_BUILD_IMPORT_DIR "${PROJECT_BINARY_DIR}/import") From 93a49dddb299486be45b9e1a7a712f8cbeee9c95 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Sat, 3 Feb 2024 22:58:55 +0300 Subject: [PATCH 28/29] typo --- ldc/runtime/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ldc/runtime/CMakeLists.txt b/ldc/runtime/CMakeLists.txt index a610393dd16..579ac783f13 100644 --- a/ldc/runtime/CMakeLists.txt +++ b/ldc/runtime/CMakeLists.txt @@ -304,7 +304,7 @@ foreach(platform ${OfficialPlatforms}) endforeach() # Produce tagged sources and import/ for current target. Overwrites previously generated -# Called again only because we need obtain TAGGED_SRCS list for the current platform +# Called again only because we need to obtain TAGGED_SRCS list for the current platform set(curr_tagged_import_dir ${LDC_BUILD_IMPORT_DIR}/tagged_imports/${DRUNTIME_TARGET_NAME}) cmake_language(CALL produce_tagged_hier ${TAGS_${DRUNTIME_TARGET_NAME}} ${curr_tagged_import_dir}) From f50811735ec6e70f64a3be56fe9af6abfe0d9fe5 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Sun, 4 Feb 2024 20:12:58 +0300 Subject: [PATCH 29/29] Skip import/ creation for the current platform --- ldc/runtime/CMakeLists.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ldc/runtime/CMakeLists.txt b/ldc/runtime/CMakeLists.txt index 579ac783f13..16d442265ec 100644 --- a/ldc/runtime/CMakeLists.txt +++ b/ldc/runtime/CMakeLists.txt @@ -298,13 +298,14 @@ set(TAGS_sunos "posix_threads") # Directory filled with auto-generated import files set(LDC_BUILD_IMPORT_DIR "${PROJECT_BINARY_DIR}/import") -# Produce imports for all official platforms (including current) +# Produce imports for all official platforms except current foreach(platform ${OfficialPlatforms}) - cmake_language(CALL produce_tagged_hier ${TAGS_${platform}} ${LDC_BUILD_IMPORT_DIR}/tagged_imports/${platform}) + if(NOT ${platform} EQUAL ${DRUNTIME_TARGET_NAME}) + cmake_language(CALL produce_tagged_hier ${TAGS_${platform}} ${LDC_BUILD_IMPORT_DIR}/tagged_imports/${platform}) + endif() endforeach() -# Produce tagged sources and import/ for current target. Overwrites previously generated -# Called again only because we need to obtain TAGGED_SRCS list for the current platform +# Produce tagged sources and import/ for current target set(curr_tagged_import_dir ${LDC_BUILD_IMPORT_DIR}/tagged_imports/${DRUNTIME_TARGET_NAME}) cmake_language(CALL produce_tagged_hier ${TAGS_${DRUNTIME_TARGET_NAME}} ${curr_tagged_import_dir})